Switchboard Extension SDK
Toggle main menu visibility
Loading...
Searching...
No Matches
Logger.hpp
1
//
2
// Logger.hpp
3
// SwitchboardSDK
4
//
5
// Created by Balázs Kiss on 2017. 10. 05..
6
// Copyright © 2017. Synervoz Inc. All rights reserved.
7
//
8
9
#pragma once
10
11
#include <sstream>
12
#include <string>
13
#include <switchboard/export.h>
14
#include <switchboard_core/LogDestination.hpp>
15
#include <switchboard_core/LogLevel.hpp>
16
17
namespace
switchboard {
18
23
class
SWITCHBOARDSDK_EXPORT
Logger
{
24
public
:
28
static
void
setLogDestination
(
LogDestination
* destination);
29
35
static
LogDestination
*
getLogDestination
();
36
42
static
void
setLogLevel
(LogLevel level);
43
49
static
LogLevel
getLogLevel
();
50
56
static
void
trace
(
const
std::string& logMessage);
57
63
static
void
debug
(
const
std::string& logMessage);
64
70
static
void
info
(
const
std::string& logMessage);
71
77
static
void
warning
(
const
std::string& logMessage);
78
84
static
void
error
(
const
std::string& logMessage);
85
89
class
LogStream {
90
public
:
91
explicit
LogStream(LogLevel level);
92
LogStream(
const
LogStream&) =
delete
;
93
LogStream& operator=(
const
LogStream&) =
delete
;
94
LogStream(LogStream&& other)
noexcept
;
95
96
LogStream& operator=(LogStream&& other)
noexcept
;
97
98
~LogStream();
99
100
template
<
typename
T>
101
LogStream& operator<<(
const
T& value) {
102
stream << value;
103
return
*
this
;
104
}
105
106
// Handle std::endl and other manipulators
107
LogStream& operator<<(std::ostream& (*manip)(std::ostream&)) {
108
stream << manip;
109
return
*
this
;
110
}
111
112
private
:
113
LogLevel level;
114
std::ostringstream stream;
115
};
116
120
struct
LogStreamFactory {
121
LogLevel level;
122
explicit
LogStreamFactory(
const
LogLevel level) : level(level) {}
123
124
template
<
typename
T>
125
LogStream
operator<<(
const
T& value) {
126
LogStream
stream(level);
127
stream << value;
128
return
stream;
129
}
130
};
131
132
static
LogStreamFactory
traceStream;
133
static
LogStreamFactory
debugStream;
134
static
LogStreamFactory
infoStream;
135
static
LogStreamFactory
warningStream;
136
static
LogStreamFactory
errorStream;
137
138
private
:
139
static
LogLevel logLevel;
140
static
LogDestination
* destination;
141
};
142
143
}
switchboard::LogDestination
Provides an interface to implement platform-specific logging.
Definition
LogDestination.hpp:21
switchboard::Logger::LogStream
Stream-like interface for logging at different levels.
Definition
Logger.hpp:89
switchboard::Logger
Provides logging functionality.
Definition
Logger.hpp:23
switchboard::Logger::getLogDestination
static LogDestination * getLogDestination()
Gets the log destination of the logger.
switchboard::Logger::error
static void error(const std::string &logMessage)
Logs an error level message.
switchboard::Logger::setLogDestination
static void setLogDestination(LogDestination *destination)
Sets the log destination of the logger.
switchboard::Logger::getLogLevel
static LogLevel getLogLevel()
Gets the log level of the logger.
switchboard::Logger::debug
static void debug(const std::string &logMessage)
Logs a debug level message.
switchboard::Logger::info
static void info(const std::string &logMessage)
Logs an info level message.
switchboard::Logger::setLogLevel
static void setLogLevel(LogLevel level)
Sets the log level of the logger.
switchboard::Logger::trace
static void trace(const std::string &logMessage)
Logs a trace level message.
switchboard::Logger::warning
static void warning(const std::string &logMessage)
Logs a warning level message.
switchboard::Logger::LogStreamFactory
Helper factory for creating LogStream instances at different log levels.
Definition
Logger.hpp:120
SwitchboardSDK
include
switchboard_core
Logger.hpp
Generated by
1.18.0