3 @brief Flog logging library
4 @author Nabeel Sowan (nabeel.sowan@vibes.se)
6 Useful as the main logger of a program
13 #define FLOG_NOTHING 0x00
14 #define FLOG_NONE FLOG_NOTHING
17 #define FLOG_CRITICAL 0x01
18 #define FLOG_CRIT FLOG_CRITICAL
21 #define FLOG_ERROR 0x02
22 #define FLOG_ERR FLOG_ERROR
25 #define FLOG_WARNING 0x04
26 #define FLOG_WARN FLOG_WARNING
27 #define FLOG_ALERT FLOG_WARNING
30 #define FLOG_NOTE 0x08
31 #define FLOG_NOTIFY FLOG_NOTE
32 #define FLOG_IMP FLOG_NOTE
33 #define FLOG_IMPORTANT FLOG_NOTE
36 #define FLOG_INFO 0x10
37 #define FLOG_INFORMATION FLOG_INFO
38 #define FLOG_MSG FLOG_INFO
39 #define FLOG_MESSAGE FLOG_INFO
41 //! Info in verbose mode
42 #define FLOG_VERBOSE 0x20
43 #define FLOG_VINFO FLOG_VERBOSE
46 #define FLOG_DEBUG 0x40
48 //! Debug info for flog itself
49 #define FLOG_FLOG_DEBUG 0x80
51 //! Bitmask to show only errors
52 #define FLOG_SHOW_ONLY_ERRORS FLOG_CRIT | FLOG_ERR
53 #define FLOG_SHOW_ERRORS_AND_WARNINGS FLOG_CRIT | FLOG_ERR | FLOG_WARN
54 #define FLOG_SHOW_IMPORTANT_NOTES FLOG_CRIT | FLOG_ERR | FLOG_WARN | FLOG_NOTE
55 #define FLOG_SHOW_INFO FLOG_CRIT | FLOG_ERR | FLOG_WARN | FLOG_NOTE | FLOG_INFO
56 #define FLOG_SHOW_VERBOSE_INFO FLOG_CRIT | FLOG_ERR | FLOG_WARN | FLOG_NOTE | FLOG_INFO | FLOG_VINFO
57 #define FLOG_SHOW_ALL FLOG_CRIT | FLOG_ERR | FLOG_WARN | FLOG_NOTE | FLOG_INFO | FLOG_VINFO | FLOG_DEBUG
58 #define FLOG_SHOW_FLOG_DEBUG FLOG_CRIT | FLOG_ERR | FLOG_WARN | FLOG_NOTE | FLOG_INFO | FLOG_VINFO | FLOG_DEBUG | FLOG_FLOG_DEBUG
60 //! Macros to allow removal of messages from release builds
62 #define flog_dprint(p, type, subsystem, text) flog_print (p, type, subsystem, text)
63 #define flog_dprintf(p, type, subsystem, ...) flog_printf (p, type, subsystem, __VA_ARGS__)
65 #define flog_dprint(p, type, subsystem, text) 0
66 #define flog_dprintf(p, type, subsystem, ...) 0
69 typedef int FLOG_MSG_TYPE_T
;
71 typedef int FLOG_TIMESTAMP_T
;
76 FLOG_TIMESTAMP_T time
; //!< timestamp
78 FLOG_MSG_TYPE_T type
; //!< type of message
79 char *subsystem
; //!< subsystem which is outputting the msg
80 char *text
; //!< message contents
84 char *name
; //!< name of log
85 FLOG_MSG_TYPE_T accepted_msg_type
; //!< bitmask of which messages to accept
86 int (*output_func
)(const FLOG_MSG_T
*,void *); //!< function to output messages to
87 int output_error
; //!< errors occurred on output
88 int output_stop_on_error
; //!< stop outputting messages on error
89 struct flog_t
*error_log
; //!< error log for flog errors
90 FLOG_MSG_T
**msg
; //!< array of messages
91 int msg_amount
; //!< amount of messages in array
92 int msg_max
; //!< maximum amount of buffered messages
93 struct flog_t
**sublog
; //!< array of sublogs
94 int sublog_amount
; //!< amount of sublogs in array
97 typedef struct flog_t FLOG_T
;
99 void init_flog_msg_t(FLOG_MSG_T
*p
);
100 FLOG_MSG_T
* create_flog_msg_t(FLOG_MSG_TYPE_T msg_type
,const char *subsystem
,const char *text
);
101 void destroy_flog_msg_t(FLOG_MSG_T
*p
);
103 void init_flog_t(FLOG_T
*p
);
104 FLOG_T
* create_flog_t(const char *name
, FLOG_MSG_TYPE_T accepted_msg_type
);
105 void destroy_flog_t(FLOG_T
*p
);
107 int flog_add_msg(FLOG_T
*p
,FLOG_MSG_T
*msg
);
108 void flog_clear_msg_buffer(FLOG_T
*p
);
109 int flog_append_sublog(FLOG_T
*p
,FLOG_T
*sublog
);
111 int flog_print(FLOG_T
*p
,FLOG_MSG_TYPE_T type
,const char *subsystem
,const char *text
);
112 int flog_printf(FLOG_T
*p
,FLOG_MSG_TYPE_T type
,const char *subsystem
,const char *textf
, ...);
114 char * flog_msg_t_to_str(const FLOG_MSG_T
*p
);
115 char * flog_get_msg_type_str(FLOG_MSG_TYPE_T type
);
116 void flog_test(FLOG_T
*p
);
118 #ifdef FLOG_TIMESTAMP
119 const char * get_timestamp(void);