1 /* 2 * Copyright (c) 2023 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 <string> 17 #include <atomic> 18 #include "ffrt_log_api.h" 19 #include "internal_inc/osal.h" 20 21 static int g_ffrtLogLevel = FFRT_LOG_ERROR; 22 static std::atomic<unsigned int> g_ffrtLogId(0); 23 GetLogId(void)24unsigned int GetLogId(void) 25 { 26 return ++g_ffrtLogId; 27 } 28 GetLogLevel(void)29int GetLogLevel(void) 30 { 31 return g_ffrtLogLevel; 32 } 33 SetLogLevel(void)34static void SetLogLevel(void) 35 { 36 std::string envLogStr = GetEnv("FFRT_LOG_LEVEL"); 37 if (envLogStr.size() != 0) { 38 int level = std::stoi(envLogStr); 39 if (level < FFRT_LOG_LEVEL_MAX && level >= FFRT_LOG_ERROR) { 40 g_ffrtLogLevel = level; 41 return; 42 } 43 } 44 } 45 LogInit(void)46static __attribute__((constructor)) void LogInit(void) 47 { 48 SetLogLevel(); 49 }