MtnLog  2.7.2
Moltony's Logging Library
mtnlog.h
Go to the documentation of this file.
1 
13 #ifndef MTNLOG_H_
14 #define MTNLOG_H_ 1
15 
19 #ifdef MTNLOG_NO_STDBOOL
20  #define MTNLOG_BOOL int
21 #else
22  #include <stdbool.h>
23  #define MTNLOG_BOOL bool
24 #endif
25 
26 #include <stdarg.h>
27 
31 typedef enum
32 {
36 } MtnLogLevel;
37 
47 typedef void (*MtnLogCallback)(MtnLogLevel, const char *, const char *);
48 
54 #ifdef __FILE_NAME__
55  #ifdef __func__
56  #define mtnlogMessageC(level, ...) mtnlogMessageCInternal(__LINE__, __FILE_NAME__, __func__, (level), __VA_ARGS__)
57  #else
58  #define mtnlogMessageC(level, ...) mtnlogMessageCInternal(__LINE__, __FILE_NAME__, "", (level), __VA_ARGS__)
59  #endif
60 #else
61  #ifdef __func__
62  #define mtnlogMessageC(level, ...) mtnlogMessageCInternal(__LINE__, __FILE__, __func__, (level), __VA_ARGS__)
63  #else
64  #define mtnlogMessageC(level, ...) mtnlogMessageCInternal(__LINE__, __FILE__, "", (level), __VA_ARGS__)
65  #endif
66 #endif
67 
74 #ifdef __FILE_NAME__
75  #ifdef __func__
76  #define mtnlogMessageTagC(level, tag, ...) mtnlogMessageTagCInternal(__LINE__, __FILE_NAME__, __func__, (level), (tag), __VA_ARGS__)
77  #else
78  #define mtnlogMessageTagC(level, tag, ...) mtnlogMessageTagCInternal(__LINE__, __FILE_NAME__, "", (level), (tag), __VA_ARGS__)
79  #endif
80 #else
81  #ifdef __func__
82  #define mtnlogMessageTagC(level, tag, ...) mtnlogMessageTagCInternal(__LINE__, __FILE__, __func__, (level), (tag), __VA_ARGS__)
83  #else
84  #define mtnlogMessageTagC(level, tag, ...) mtnlogMessageTagCInternal(__LINE__, __FILE__, "", (level), (tag), __VA_ARGS__)
85  #endif
86 #endif
87 
88 #ifdef __cplusplus
89 extern "C" {
90 #endif
91 
97 void mtnlogInit(const MtnLogLevel level, const char *logFileName);
98 
105 void mtnlogColor(const MTNLOG_BOOL enable);
106 
115 
120 void mtnlogConsoleOutput(const MTNLOG_BOOL enable);
121 
128 void mtnlogFileOutput(const MTNLOG_BOOL enable);
129 
134 void mtnlogSetLevel(const MtnLogLevel level);
135 
141 
146 void mtnlogTimestamps(const MTNLOG_BOOL enable);
147 
153 
161 void mtnlogMessage(const MtnLogLevel level, const char *format, ...);
162 
170 void mtnlogVMessage(const MtnLogLevel level, const char *format, va_list l);
171 
179 void mtnlogMessageTag(const MtnLogLevel level, const char *tag, const char *format, ...);
180 
189 void mtnlogVMessageTag(const MtnLogLevel level, const char *tag, const char *format, va_list l);
190 
196 void mtnlogMessageCInternal(const int line, const char *file, const char *function, const MtnLogLevel level, const char *message, ...);
197 
203 void mtnlogMessageTagCInternal(const int line, const char *file, const char *function, const MtnLogLevel level, const char *tag, const char *message, ...);
204 
205 #ifdef __cplusplus
206 }
207 #endif
208 
209 #endif
210 
#define MTNLOG_BOOL
MtnLog boolean type.
Definition: mtnlog.h:23
void mtnlogMessageCInternal(const int line, const char *file, const char *function, const MtnLogLevel level, const char *message,...)
Internal function for mtnlogMessageC.
void(* MtnLogCallback)(MtnLogLevel, const char *, const char *)
Log callback function.
Definition: mtnlog.h:47
void mtnlogMessage(const MtnLogLevel level, const char *format,...)
Print a message to the log.
MTNLOG_BOOL mtnlogCheckColor(void)
Check if color is supported.
void mtnlogMessageTag(const MtnLogLevel level, const char *tag, const char *format,...)
Print a message to the log with a tag.
void mtnlogMessageTagCInternal(const int line, const char *file, const char *function, const MtnLogLevel level, const char *tag, const char *message,...)
Internal function for mtnlogMessageTagC.
void mtnlogSetCallback(const MtnLogCallback cb)
Set log callback.
void mtnlogVMessageTag(const MtnLogLevel level, const char *tag, const char *format, va_list l)
Print a message to the log with a tag (VA list version)
void mtnlogTimestamps(const MTNLOG_BOOL enable)
Enable or disable log timestamps.
void mtnlogConsoleOutput(const MTNLOG_BOOL enable)
Enable or disable outputting log messages into console (stdout)
void mtnlogFileOutput(const MTNLOG_BOOL enable)
Enable or disable outputting log messages into the log file.
void mtnlogColor(const MTNLOG_BOOL enable)
Enable or disable color for messages.
void mtnlogInit(const MtnLogLevel level, const char *logFileName)
Initialize logging.
void mtnlogVMessage(const MtnLogLevel level, const char *format, va_list l)
Print a message to the log (VA list version)
MtnLogLevel
Enum representing logging level.
Definition: mtnlog.h:32
@ MTNLOG_ERROR
Definition: mtnlog.h:35
@ MTNLOG_INFO
Definition: mtnlog.h:33
@ MTNLOG_WARNING
Definition: mtnlog.h:34
void mtnlogConsoleTimestamps(const MTNLOG_BOOL enable)
Enable or disable putting timestamps in console.
void mtnlogSetLevel(const MtnLogLevel level)
Set logging level.