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