1 /*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "option_debug.h"
17 namespace OHOS {
18 namespace Developtools {
19 namespace HiPerf {
OnVerboseLevel(const std::vector<std::string> & debugLevel)20 static bool OnVerboseLevel(const std::vector<std::string> &debugLevel)
21 {
22 if (debugLevel.size() <= 0) {
23 return false;
24 }
25 DebugLogger::GetInstance()->SetLogLevel(LEVEL_VERBOSE);
26 DebugLogger::GetInstance()->Disable(false);
27 return true;
28 }
29
OnMuchLevel(const std::vector<std::string> & debugLevel)30 static bool OnMuchLevel(const std::vector<std::string> &debugLevel)
31 {
32 if (debugLevel.size() <= 0) {
33 return false;
34 }
35 DebugLogger::GetInstance()->SetLogLevel(LEVEL_MUCH);
36 DebugLogger::GetInstance()->Disable(false);
37 return true;
38 }
39
OnDebugLevel(const std::vector<std::string> & debugLevel)40 static bool OnDebugLevel(const std::vector<std::string> &debugLevel)
41 {
42 if (debugLevel.size() <= 0) {
43 return false;
44 }
45 DebugLogger::GetInstance()->SetLogLevel(LEVEL_DEBUG);
46 DebugLogger::GetInstance()->Disable(false);
47 return true;
48 }
49
OnNoDebug(const std::vector<std::string> & debugLevel)50 static bool OnNoDebug(const std::vector<std::string> &debugLevel)
51 {
52 if (debugLevel.size() <= 0) {
53 return false;
54 }
55 DebugLogger::GetInstance()->Disable();
56 return true;
57 }
58
OnMixLogOutput(const std::vector<std::string> & debugLevel)59 static bool OnMixLogOutput(const std::vector<std::string> &debugLevel)
60 {
61 if (debugLevel.size() <= 0) {
62 return false;
63 }
64 DebugLogger::GetInstance()->SetMixLogOutput(true);
65 return true;
66 }
67
OnLogPath(std::vector<std::string> & args)68 static bool OnLogPath(std::vector<std::string> &args)
69 {
70 if (args.size() > 0) {
71 DebugLogger::GetInstance()->SetLogPath(args[0]);
72 args.erase(args.begin());
73 } else {
74 return false;
75 }
76 return true;
77 }
78
OnLogTag(std::vector<std::string> & args)79 static bool OnLogTag(std::vector<std::string> &args)
80 {
81 if (args.size() > 0) {
82 DebugLogger::GetInstance()->SetLogTags(args[0]);
83 args.erase(args.begin());
84 } else {
85 return false;
86 }
87 return true;
88 }
89 #if is_ohos && !is_double_framework
OnHiLog(const std::vector<std::string> & args)90 static bool OnHiLog(const std::vector<std::string> &args)
91 {
92 DebugLogger::GetInstance()->EnableHiLog();
93 return true;
94 }
95 #endif
RegisterMainCommandDebug()96 void RegisterMainCommandDebug()
97 {
98 Option::RegisterMainOption("--nodebug", "disable debug log, usage format: --nodebug [command] [args]",
99 OnNoDebug);
100 Option::RegisterMainOption("--debug", "show debug log, usage format: --debug [command] [args]",
101 OnDebugLevel);
102 Option::RegisterMainOption("--verbose", "show debug log, usage format: --verbose [command] [args]",
103 OnVerboseLevel);
104 Option::RegisterMainOption("--much", "show extremely much debug log, usage format: --much [command] [args]",
105 OnMuchLevel);
106 Option::RegisterMainOption("--mixlog", "mix the log in output, usage format: --much [command] [args]",
107 OnMixLogOutput);
108 Option::RegisterMainOption("--logpath",
109 "log file name full path, usage format: --logpath [filepath] [command] [args]",
110 OnLogPath);
111 std::string tagUsage = StringPrintf("%s\t%-20s\t%s\t%-20s\t%s",
112 "enable log level for HILOG_TAG, usage format: --logtag <tag>[:level][,<tag>[:level]] [command] [args]\n", " ",
113 "tag: Dump, Report, Record, Stat... level: D, V, M...\n", " ",
114 "example: hiperf --verbose --logtag Record:D [command] [args]");
115 Option::RegisterMainOption("--logtag", tagUsage.c_str(), OnLogTag);
116 #if is_ohos && !is_double_framework
117 Option::RegisterMainOption("--hilog", "use hilog not file to record log", OnHiLog);
118 #endif
119 }
120 } // namespace HiPerf
121 } // namespace Developtools
122 } // namespace OHOS
123