summaryrefslogtreecommitdiff
path: root/include/logger.h
blob: f195759177a2a722bcbf844728c7981b9e9f0f40 (plain)
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
#ifndef H__LOGGER_H
#define H__LOGGER_H

/*
 * does runtime logging.
 * xiang hong
 * 2002-07-29
 */

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <time.h>
#include <unistd.h>


#define RLOG_LV_DEBUG		10
#define RLOG_LV_INFO		20
#define RLOG_LV_FATAL		30

#define LOGMSG_MAX_LEN		1024

#define RUNTIME_LOG(lv, mod, fmt, args...)	\
	runtime_log((lv), (mod), "file %s, line %d, " fmt, \
	__FILE__, __LINE__, ##args)

/*
 * define your own version of RLOG.
 */
#define RLOGF(fmt, args...)	RLOG(RLOG_LV_FATAL, fmt, ##args)
#define RLOGI(fmt, args...)	RLOG(RLOG_LV_INFO, fmt, ##args)
#define RLOGD(fmt, args...)	RLOG(RLOG_LV_DEBUG, fmt, ##args)

#ifdef __cplusplus
extern "C"
{
#endif
/*
 * returns:
 * 0, if succeeded;
 * -1, if file is not absolute path, or failed to create log file;
 */
int runtime_log_init(char * file, int level);
int system_log_init(char * file, int level);

/*
 * name: runtime_log
 * functionality: appends log message to runtime log file.
 * params:
 * 	level: log level, messages with level value smaller the global var
 * 		"runtime_log_level" are ignored;
 * 	module: name of loggin module;
 * 	fmt: format string;
 * returns:
 * 	none;
 */
void runtime_log(int level, char * module, char * fmt, ...);

/*
 * fake function.
 */
void system_log(int level, char * module, char * fmt, ...);

#ifdef __cplusplus
}
#endif
#endif