diff options
author | anozdrin/alik@booka. <> | 2006-11-21 17:47:14 +0300 |
---|---|---|
committer | anozdrin/alik@booka. <> | 2006-11-21 17:47:14 +0300 |
commit | 3e042c6d7b91e3725ff21015f3265b9afe8d93af (patch) | |
tree | 013e928c88c019dc5bfaa9bd7713f68f41037ac5 /server-tools/instance-manager/log.cc | |
parent | ff0325f1625f2802d0080b506f164ca3aa9c1126 (diff) | |
download | mariadb-git-3e042c6d7b91e3725ff21015f3265b9afe8d93af.tar.gz |
Polishing:
- change some return types from int to bool;
- add [ERROR] tag to log_error() output;
- add [INFO] tag to log_info() output;
- change log messages to be more consistent.
Diffstat (limited to 'server-tools/instance-manager/log.cc')
-rw-r--r-- | server-tools/instance-manager/log.cc | 96 |
1 files changed, 57 insertions, 39 deletions
diff --git a/server-tools/instance-manager/log.cc b/server-tools/instance-manager/log.cc index e3880caadd0..7ff45a15432 100644 --- a/server-tools/instance-manager/log.cc +++ b/server-tools/instance-manager/log.cc @@ -37,7 +37,8 @@ log() */ -static inline void log(FILE *file, const char *format, va_list args) +static void log(FILE *file,const char *level_tag, const char *format, + va_list args) { /* log() should be thread-safe; it implies that we either call fprintf() @@ -53,15 +54,16 @@ static inline void log(FILE *file, const char *format, va_list args) localtime_r(&now, &bd_time); char buff_date[128]; - sprintf(buff_date, "[%d/%lu] [%02d/%02d/%02d %02d:%02d:%02d] ", + sprintf(buff_date, "[%d/%lu] [%02d/%02d/%02d %02d:%02d:%02d] [%s] ", (int) getpid(), (unsigned long) pthread_self(), - bd_time.tm_year % 100, - bd_time.tm_mon + 1, - bd_time.tm_mday, - bd_time.tm_hour, - bd_time.tm_min, - bd_time.tm_sec); + (int) bd_time.tm_year % 100, + (int) bd_time.tm_mon + 1, + (int) bd_time.tm_mday, + (int) bd_time.tm_hour, + (int) bd_time.tm_min, + (int) bd_time.tm_sec, + (const char *) level_tag); /* Format the message */ char buff_stack[256]; @@ -109,57 +111,73 @@ static inline void log(FILE *file, const char *format, va_list args) /* don't fflush() the file: buffering strategy is set in log_init() */ } +/************************************************************************** + Logging: implementation of public interface. +**************************************************************************/ -void log_error(const char *format, ...) -{ - va_list args; - va_start(args, format); - log(stderr, format, args); - va_end(args); -} +/* + The function initializes logging sub-system. + SYNOPSIS + log_init() +*/ -void log_info(const char *format, ...) +void log_init() { - va_list args; - va_start(args, format); - log(stdout, format, args); - va_end(args); + /* + stderr is unbuffered by default; there is no good of line buffering, + as all logging is performed linewise - so remove buffering from stdout + also + */ + setbuf(stdout, 0); } -/* TODO: rewrite with buffering print */ -void print_info(const char *format, ...) + +/* + The function is intended to log error messages. It precedes a message + with date, time and [ERROR] tag and print it to the stderr. + + SYNOPSIS + log_error() + format [IN] format string + ... [IN] arguments to format +*/ + +void log_error(const char *format, ...) { va_list args; va_start(args, format); - vfprintf(stdout, format, args); + log(stderr, "ERROR", format, args); va_end(args); } -void print_error(const char *format, ...) + +/* + The function is intended to log information messages. It precedes + a message with date, time and [INFO] tag and print it to the stdout. + + SYNOPSIS + log_error() + format [IN] format string + ... [IN] arguments to format +*/ + +void log_info(const char *format, ...) { va_list args; va_start(args, format); - vfprintf(stderr, format, args); + log(stdout, "INFO", format, args); va_end(args); } /* - log_init() - RETURN VALUE - 0 ok - !0 error -*/ + The function prints information to the error log and eixt(1). -void log_init() -{ - /* - stderr is unbuffered by default; there is no good of line buffering, - as all logging is performed linewise - so remove buffering from stdout - also - */ - setbuf(stdout, 0); -} + SYNOPSIS + die() + format [IN] format string + ... [IN] arguments to format +*/ void die(const char *format, ...) { |