Logging utility should have different log levels so that we may take decision on log levels while making logs. It may include, printing file name, function name and line number just for the case of error messages, Setting a global log level and only logging messages which are less than the global log levels, in this way, application in production can get rid of debugging log messages. We may initialize system with different log levels or changing log level at run time.
Basicly there should be at least 3 log levels (Error, Warn, Info or Debug) as follows:
enum LogLevel {LogLevelError=00,
LogLevelWarn=10,
LogLevelInfo=20,
LogLevelMaxLevel=9999 };
CLog class contains an static variable GlobalLogLevel of type LogLevel, which can be set during initialization or at runtime, as follows:
class CLog
{
...
public:
static LogLevel GlobalLogLevel;
...
};
Before logging message, it is tested that the message going to be logged should have less log level than the global log level, as follows:
void CLog::LogMessageToFD(FILE *fd, char *msg, int logLevel, char *fileName,
char *funcName, int lineNum,) {
.........................
if(logLevel <= CLog::GlobalLogLevel) {
// Print Log Message with time stamp
}
.........................
}
Basicly there should be at least 3 log levels (Error, Warn, Info or Debug) as follows:
enum LogLevel {LogLevelError=00,
LogLevelWarn=10,
LogLevelInfo=20,
LogLevelMaxLevel=9999 };
CLog class contains an static variable GlobalLogLevel of type LogLevel, which can be set during initialization or at runtime, as follows:
class CLog
{
...
public:
static LogLevel GlobalLogLevel;
...
};
Before logging message, it is tested that the message going to be logged should have less log level than the global log level, as follows:
void CLog::LogMessageToFD(FILE *fd, char *msg, int logLevel, char *fileName,
char *funcName, int lineNum,) {
.........................
if(logLevel <= CLog::GlobalLogLevel) {
// Print Log Message with time stamp
}
.........................
}
No comments:
Post a Comment