1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
/*
* Logger.h
*
* Copyright (C) ST-Ericsson SA 2011
* Authors: Srimanta Panda <srimanta.panda@stericsson.com>,
* Ola Borgelin <ola.borgelin@stericsson.com>,
* Karin Hedlund <karin.hedlund@stericsson.com>,
* Markus Andersson <markus.m.andersson@stericsson.com> for ST-Ericsson.
* License terms: 3-clause BSD license
*
*/
/*
* @addtogroup Logger
* @{
*/
#pragma once
#include <string>
/**
* @brief Class for storing and displaying logging information.
*
* This class implements simple command line logger that can display logging
* information either to the application console or separate logging console.
*/
class Logger
{
public:
enum LogSeverity {
PROGRESS,
ERR,
WARNING,
INFO
};
/**
* @brief Creates logger with the specified name.
*
* @param[in] name - Name of the logger.
*/
Logger(const std::string& name);
/**
* @brief Destroys the logger.
*/
~Logger();
/**
* @brief printf style log function to print formated message.
*
* It prints the message on separate line adding timestamp and logger name
* if printing in a shared console.
*
* @param[in] severity - the severity of the log message.
* @param[in] format - printf style format of the message.
* @param[in] ... - variable argument list.
*/
#ifdef _WIN32
void log(LogSeverity severity, const char* format, ...) const;
#else
void log(LogSeverity severity, const char* format, ...) const __attribute__((format(printf, 3, 0)));
#endif
/**
* @brief Print hex dump of the buffer.
*
* @param[in] buffer - buffer to be printed to the log.
* @param[in] size - size of the buffer.
*/
void hex(const unsigned char* buffer, size_t size) const;
/**
* @brief Print raw message string to the logging console.
*
* @param[in] message - raw messsage to be printed.
*/
void logRaw(const char* message) const;
static bool verbose_;
private:
FILE* console_;
std::string name_;
};
/* @} */
|