• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <platform/api/logging.h>
18 
19 #include <android-base/logging.h>
20 
21 #include "adb_trace.h"
22 
23 namespace openscreen {
24 
IsLoggingOn(LogLevel level,const char * file)25 bool IsLoggingOn(LogLevel level, const char* file) {
26     return true;
27 }
28 
OpenScreenLogLevelToAndroid(LogLevel level)29 static android::base::LogSeverity OpenScreenLogLevelToAndroid(LogLevel level) {
30     switch (level) {
31         case LogLevel::kVerbose:
32             return android::base::VERBOSE;
33         case LogLevel::kInfo:
34             return android::base::INFO;
35         case LogLevel::kWarning:
36             return android::base::WARNING;
37         case LogLevel::kError:
38             return android::base::ERROR;
39         case LogLevel::kFatal:
40             return android::base::FATAL;
41     }
42 }
43 
LogWithLevel(LogLevel level,const char * file,int line,std::stringstream desc)44 void LogWithLevel(LogLevel level, const char* file, int line, std::stringstream desc) {
45     auto severity = OpenScreenLogLevelToAndroid(level);
46     std::string msg = std::string("(") + file + ":" + std::to_string(line) + ") " + desc.str();
47 
48     // We never ignore a warning or worse (error and fatals).
49     if (severity >= android::base::WARNING) {
50         LOG(severity) << msg;
51     } else {
52         VLOG(MDNS_STACK) << msg;
53     }
54 }
55 
Break()56 [[noreturn]] void Break() {
57     LOG(FATAL) << "openscreen Break() called";
58     abort(); // LOG(FATAL) isn't [[noreturn]].
59 }
60 
61 }  // namespace openscreen
62