• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "logger.h"
17 #include <cstdarg>
18 #include "default_logger.h"
19 #ifndef __WITH_NO_HILOG__
20 #include "hi_logger.h"
21 #endif
22 namespace OHOS {
23 namespace HiviewDFX {
Logger()24 Logger::Logger()
25 {
26     m_logger = std::make_unique<DefaultLogger>();
27 #ifndef __WITH_NO_HILOG__
28     SetUserLogger(std::make_unique<HiLogger>());
29 #endif
30 }
31 
GetInstance()32 Logger& Logger::GetInstance()
33 {
34     static Logger instance;
35     return instance;
36 }
37 
SetUserLogger(std::unique_ptr<ILogger> logger)38 bool Logger::SetUserLogger(std::unique_ptr<ILogger> logger)
39 {
40     if (!logger) {
41         return false;
42     }
43     m_logger = std::move(logger);
44     return true;
45 }
46 
47 
Print(uint32_t level,uint32_t domain,const char * tag,const char * format,...)48 void Logger::Print(uint32_t level, uint32_t domain, const char* tag, const char* format, ...)
49 {
50     if (m_logger == nullptr) {
51         return;
52     }
53     va_list args;
54     va_start(args, format);
55     m_logger->Print(level, domain, tag, format, args);
56     va_end(args);
57 }
58 }
59 }