-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogger.h
125 lines (109 loc) · 3.37 KB
/
Logger.h
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* Copyright (c) 2013, BLK Co., Ltd. All right reserved.
*
* This is unpublished proprietary information of BLK CO., Ltd and is
* protected as an unpublished work under applicable Copyright laws.
* The contents of this file may not be disclosed to third parties,
* copied or duplicated in any form, in whole or in part, without the
* prior written permission of BLK Co., Ltd.
*
* $Id$
*
*/
/**
* @file Definition for logging
*
* @author zhangshengfa
* @date 2013-12-11
*/
#ifndef _LOGGER_H_
#define _LOGGER_H_
#if (defined(_MSC_VER) && _MSC_VER > 1000)
#pragma once
#endif
#include "LoggerDefs.h"
#include <sys/types.h>
namespace hifu { namespace logger {
/** @brief Severity level of log */
enum LOGGER_LIB LogLevel {
DEBUG,
INFO,
WARNING,
ERROR,
FATAL
};
/**
* @brief Type definition for log appending
*
* @param[in] level Log severity level
* @param[in] flag Flag for end of log message, zero(0) is NOT terminated
* @param[in] msg Log message
*
* @return On success, return 0, otherwise return error code
*/
typedef int (*AppendFn)(LogLevel level, int flag, const char *msg);
/**
* @brief Type definition for the funtion that initialized appender
*
* @param[in] argv Argument value
* @param[out] append_func Append function
*
* @retval 0 Initialize appender successfully
* @retval -1 Failed to initialize
*/
typedef int (*InitAppenderFn)(void *argv, AppendFn *append_func);
/**
* @brief Initialize logger
*
* @param[in] level Log severity level to append
* @param[in] init_func Appender initialize function
* @param[in] argv Argument for init_func
*
* @retval 0 Initialized successfully
* @retval -1 Failed to initialize
*/
LOGGER_LIB int initLogger(LogLevel level, InitAppenderFn init_func, void *argv);
/**
* @brief Logging
*
* @param[in] level Log severity level
* @param[in] file File name
* @param[in] func Function name
* @param[in] line Line number
* @param[in] fmt Log format string
*
* @return N/A
*/
LOGGER_LIB void log(LogLevel level, const char *file, const char *func,
int line, const char *fmt, ...);
/**
* @brief Dump buffer in hex
*
* @param[in] level Log severity level
* @param[in] file File name
* @param[in] func Function name
* @param[in] line Line number
* @param[in] buffer Buffer to dump
* @param[in] size Size of buffer
*
* @return N/A
*/
LOGGER_LIB void dump(LogLevel level, const char *file, const char *func,
int line, const char *buffer, size_t size);
} } /* !namespace */
/** @brief Macro for logging shorthand */
#define LOG(level, ...) \
hifu::logger::log(level, __FILE__, __FN__, __LINE__, __VA_ARGS__)
#define DLOG(...) LOG(hifu::logger::DEBUG, __VA_ARGS__)
#define ILOG(...) LOG(hifu::logger::INFO, __VA_ARGS__)
#define WLOG(...) LOG(hifu::logger::WARNING, __VA_ARGS__)
#define ELOG(...) LOG(hifu::logger::ERROR, __VA_ARGS__)
#define FLOG(...) LOG(hifu::logger::FATAL, __VA_ARGS__)
#define DUMP(level, buffer, size) \
hifu::logger::dump(level, __FILE__, __FN__, __LINE__, buffer, size)
#define DDUMP(buffer, size) DUMP(hifu::logger::DEBUG, buffer, size)
#define IDUMP(buffer, size) DUMP(hifu::logger::INFO, buffer, size)
#define WDUMP(buffer, size) DUMP(hifu::logger::WARNING, buffer, size)
#define EDUMP(buffer, size) DUMP(hifu::logger::ERROR, buffer, size)
#define FDUMP(buffer, size) DUMP(hifu::logger::FATAL, buffer, size)
#endif /* !_LOGGER_H_ */