ArmNN
 25.11
Loading...
Searching...
No Matches
Logging.cpp
Go to the documentation of this file.
1//
2// Copyright © 2019,2024 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include <armnn/Logging.hpp>
8#include <armnn/Utils.hpp>
10
11#if defined(_MSC_VER)
12#include <common/include/WindowsWrapper.hpp>
13#endif
14
15#if defined(__ANDROID__)
16#include <android/log.h>
17#endif
18
19#include <iostream>
20
21namespace armnn
22{
23
24template<LogSeverity Level>
26{
27 static SimpleLogger<Level> logger;
28 return logger;
29}
30
31template<>
37
38template<>
44
45template<>
51
52template<>
58
59template<>
65
66template<>
72
105
106class StandardOutputColourSink : public LogSink
107{
108public:
109 StandardOutputColourSink(LogSeverity level = LogSeverity::Info)
110 : m_Level(level)
111 {
112 }
113
114 void Consume(const std::string& s) override
115 {
116 std::cout << GetColour(m_Level) << s << ResetColour() << std::endl;
117 }
118
119private:
120 std::string ResetColour()
121 {
122 return "\033[0m";
123 }
124
125 std::string GetColour(LogSeverity level)
126 {
127 switch(level)
128 {
130 return "\033[35m";
132 return "\033[32m";
134 return "\033[0m";
136 return "\033[33m";
138 return "\033[31m";
140 return "\033[41;30m";
141
142 default:
143 return "\033[0m";
144 }
145 }
146 LogSeverity m_Level;
147};
148
149class DebugOutputSink : public LogSink
150{
151public:
152 void Consume(const std::string& s) override
153 {
154 IgnoreUnused(s);
155#if defined(_MSC_VER)
156 OutputDebugString(s.c_str());
157 OutputDebugString("\n");
158#elif defined(__ANDROID__)
159 __android_log_write(ANDROID_LOG_DEBUG, "armnn", s.c_str());
160#else
161 IgnoreUnused(s);
162#endif
163 }
164};
165
166template<LogSeverity Level>
167inline void SetLoggingSinks(bool standardOut, bool debugOut, bool coloured)
168{
170
171 if (standardOut)
172 {
173 if (coloured)
174 {
176 std::make_shared<StandardOutputColourSink>(Level));
177 } else
178 {
180 std::make_shared<StandardOutputSink>());
181 }
182 }
183
184 if (debugOut)
185 {
187 std::make_shared<DebugOutputSink>());
188 }
189}
190
191void SetAllLoggingSinks(bool standardOut, bool debugOut, bool coloured)
192{
193 SetLoggingSinks<LogSeverity::Trace>(standardOut, debugOut, coloured);
194 SetLoggingSinks<LogSeverity::Debug>(standardOut, debugOut, coloured);
195 SetLoggingSinks<LogSeverity::Info>(standardOut, debugOut, coloured);
196 SetLoggingSinks<LogSeverity::Warning>(standardOut, debugOut, coloured);
197 SetLoggingSinks<LogSeverity::Error>(standardOut, debugOut, coloured);
198 SetLoggingSinks<LogSeverity::Fatal>(standardOut, debugOut, coloured);
199}
200
201} //namespace armnn
#define ARMNN_FALLTHROUGH
Definition Utils.hpp:36
void Enable(bool enable=true)
Definition Logging.hpp:168
static SimpleLogger & Get()
Definition Logging.cpp:25
void AddSink(std::shared_ptr< LogSink > sink)
Definition Logging.hpp:183
Copyright (c) 2021 ARM Limited and Contributors.
void SetLoggingSinks(bool standardOut, bool debugOut, bool coloured)
Definition Logging.cpp:167
void SetAllLoggingSinks(bool standardOut, bool debugOut, bool coloured)
Definition Logging.cpp:191
LogSeverity
Definition Utils.hpp:14
void SetLogFilter(LogSeverity level)
Definition Logging.cpp:73
void IgnoreUnused(Ts &&...)