YARP
Yet Another Robot Platform
LogComponent.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 #include <yarp/os/LogComponent.h>
10 
13 
14 LogComponent::LogComponent(const char* name,
15  LogType minimumPrintLevel,
16  LogType minimumForwardLevel,
17  LogCallback printCallback,
18  LogCallback forwardCallback) :
19  m_name(name),
20  m_tracePrintEnabled(minimumPrintLevel <= yarp::os::Log::TraceType),
21  m_debugPrintEnabled(minimumPrintLevel <= yarp::os::Log::DebugType),
22  m_infoPrintEnabled(minimumPrintLevel <= yarp::os::Log::InfoType),
23  m_warningPrintEnabled(minimumPrintLevel <= yarp::os::Log::WarningType),
24  m_errorPrintEnabled(minimumPrintLevel <= yarp::os::Log::ErrorType),
25  m_fatalPrintEnabled(minimumPrintLevel <= yarp::os::Log::FatalType),
26  m_traceForwardEnabled(minimumForwardLevel <= yarp::os::Log::TraceType),
27  m_debugForwardEnabled(minimumForwardLevel <= yarp::os::Log::DebugType),
28  m_infoForwardEnabled(minimumForwardLevel <= yarp::os::Log::InfoType),
29  m_warningForwardEnabled(minimumForwardLevel <= yarp::os::Log::WarningType),
30  m_errorForwardEnabled(minimumForwardLevel <= yarp::os::Log::ErrorType),
31  m_fatalForwardEnabled(minimumForwardLevel <= yarp::os::Log::FatalType),
32  m_printCallback(printCallback),
33  m_forwardCallback(forwardCallback)
34 {
35  // FIXME Read enviroment variables, config files, etc to configure the component dynamically
36 }
37 
39 {
40  switch (t) {
42  return (m_tracePrintEnabled.load() ? m_printCallback : nullptr);
44  return (m_debugPrintEnabled.load() ? m_printCallback : nullptr);
46  return (m_infoPrintEnabled.load() ? m_printCallback : nullptr);
48  return (m_warningPrintEnabled.load() ? m_printCallback : nullptr);
50  return (m_errorPrintEnabled.load() ? m_printCallback : nullptr);
52  return (m_fatalPrintEnabled.load() ? m_printCallback : nullptr);
53  default:
54  return nullptr;
55  }
56 }
57 
59 {
60  switch (t) {
62  return (m_traceForwardEnabled.load() ? m_forwardCallback : nullptr);
64  return (m_debugForwardEnabled.load() ? m_forwardCallback : nullptr);
66  return (m_infoForwardEnabled.load() ? m_forwardCallback : nullptr);
68  return (m_warningForwardEnabled.load() ? m_forwardCallback : nullptr);
70  return (m_errorForwardEnabled.load() ? m_forwardCallback : nullptr);
72  return (m_fatalForwardEnabled.load() ? m_forwardCallback : nullptr);
73  default:
74  return nullptr;
75  }
76 }
77 
78 #ifndef YARP_NO_DEPRECATED // Since YARP 3.4
79 void LogComponent::setMinimumPrintLevel(LogType minimumPrintLevel)
80 {
81  m_tracePrintEnabled = (minimumPrintLevel <= yarp::os::Log::TraceType);
82  m_debugPrintEnabled = (minimumPrintLevel <= yarp::os::Log::DebugType);
83  m_infoPrintEnabled = (minimumPrintLevel <= yarp::os::Log::InfoType);
84  m_warningPrintEnabled = (minimumPrintLevel <= yarp::os::Log::WarningType);
85  m_errorPrintEnabled = (minimumPrintLevel <= yarp::os::Log::ErrorType);
86  m_fatalPrintEnabled = (minimumPrintLevel <= yarp::os::Log::FatalType);
87 }
88 
89 void LogComponent::setMinimumForwardLevel(LogType minimumForwardLevel)
90 {
91  m_traceForwardEnabled = (minimumForwardLevel <= yarp::os::Log::TraceType);
92  m_debugForwardEnabled = (minimumForwardLevel <= yarp::os::Log::DebugType);
93  m_infoForwardEnabled = (minimumForwardLevel <= yarp::os::Log::InfoType);
94  m_warningForwardEnabled = (minimumForwardLevel <= yarp::os::Log::WarningType);
95  m_errorForwardEnabled = (minimumForwardLevel <= yarp::os::Log::ErrorType);
96  m_fatalForwardEnabled = (minimumForwardLevel <= yarp::os::Log::FatalType);
97 }
98 #endif // YARP_NO_DEPRECATED
yarp::os::Log::InfoType
@ InfoType
Definition: Log.h:79
yarp::os::Log::ErrorType
@ ErrorType
Definition: Log.h:81
LogCallback
yarp::os::Log::LogCallback LogCallback
Definition: LogComponent.cpp:12
t
float t
Definition: FfmpegWriter.cpp:74
yarp::os::Log::TraceType
@ TraceType
Definition: Log.h:77
yarp::os::Log::WarningType
@ WarningType
Definition: Log.h:80
yarp::os::Log::LogType
LogType
Definition: Log.h:75
yarp::os::LogComponent
Definition: LogComponent.h:21
LogComponent.h
yarp::os::LogComponent::LogCallback
yarp::os::Log::LogCallback LogCallback
Definition: LogComponent.h:23
yarp::os::LogComponent::printCallback
LogCallback printCallback(yarp::os::Log::LogType t) const
Definition: LogComponent.cpp:38
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::os::LogComponent::forwardCallback
LogCallback forwardCallback(yarp::os::Log::LogType t) const
Definition: LogComponent.cpp:58
yarp::os::Log
Definition: Log.h:53
yarp::os::Log::FatalType
@ FatalType
Definition: Log.h:82
yarp::os::Log::DebugType
@ DebugType
Definition: Log.h:78
yarp::os::Log::LogCallback
void(*)(yarp::os::Log::LogType type, const char *msg, const char *file, const unsigned int line, const char *func, double systemtime, double networktime, double externaltime, const char *comp_name) LogCallback
Definition: Log.h:108