1 /*
2 * Copyright (c) 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 "process_group_log.h"
17 #include <vector> // for vector
18
19 namespace OHOS {
20 namespace ResourceSchedule {
21 namespace CgroupSetting {
22 LogLevel ProcessGroupLog::level_ = { LOG_DEBUG };
23 const bool RESULT = ProcessGroupLog::InitOnLoaded();
24
JudgeLevel(const LogLevel & level)25 bool ProcessGroupLog::JudgeLevel(const LogLevel &level)
26 {
27 const LogLevel &curLevel = ProcessGroupLog::GetLogLevel();
28 if (level < curLevel) {
29 return false;
30 }
31 return true;
32 }
33
InitOnLoaded()34 bool ProcessGroupLog::InitOnLoaded()
35 {
36 const std::vector<LogLevel> levels = { LOG_DEBUG, LOG_INFO, LOG_WARN, LOG_ERROR, LOG_FATAL };
37 for (const LogLevel& level : levels) {
38 if (HiLogIsLoggable(LOG_TAG_DOMAIN_ID_PGCGS, LOG_TAG_PGCGS, level)) {
39 ProcessGroupLog::SetLogLevel(level);
40 break;
41 }
42 }
43 return true;
44 }
45 } // namespace CgroupSetting
46 } // namespace ResourceSchedule
47 } // namespace OHOS