11 #define DATABUFF DTBUFF+3+10+1+5+1+1
14 static int log_level = 0;
15 static FILE *lg_file = NULL;
16 static char date_buffer[DTBUFF];
17 static char data_buffer[DATABUFF];
20 #define LOG_DATE_FORMAT "%Y/%m/%d %H:%M:%S"
23 im_vloog(pIMCTX, int level, const char *fmt, va_list ap);
30 im_init_log(pIMCTX, const char* name,int level) {
32 aIMCTX->log_level = level;
34 aIMCTX->lg_file = NULL;
37 aIMCTX->lg_file = stderr;
39 if (NULL == (aIMCTX->lg_file = fopen(name, "w+")) ) {
40 i_push_errorf(errno, "Cannot open file '%s': (%d)", name, errno);
45 if (aIMCTX->lg_file) {
46 setvbuf(aIMCTX->lg_file, NULL, _IONBF, BUFSIZ);
47 mm_log((0,"Imager - log started (level = %d)\n", level));
50 return aIMCTX->lg_file != NULL;
54 i_fatal(int exitcode,const char *fmt, ... ) {
58 pIMCTX = im_get_context();
60 if (aIMCTX->lg_file != NULL) {
62 im_vloog(aIMCTX, 0, fmt, ap);
69 im_fatal(pIMCTX, int exitcode,const char *fmt, ... ) {
74 if (aIMCTX->lg_file != NULL) {
76 im_vloog(aIMCTX, 0, fmt, ap);
83 =item i_loog(level, format, ...)
86 This is an internal function called by the mm_log() macro.
92 im_vloog(pIMCTX, int level, const char *fmt, va_list ap) {
95 char date_buffer[DTBUFF];
97 if (!aIMCTX->lg_file || level > aIMCTX->log_level)
101 str_tm = localtime(&timi);
102 strftime(date_buffer, DTBUFF, LOG_DATE_FORMAT, str_tm);
103 fprintf(aIMCTX->lg_file, "[%s] %10s:%-5d %3d: ", date_buffer,
104 aIMCTX->filename, aIMCTX->line, level);
105 vfprintf(aIMCTX->lg_file, fmt, ap);
106 fflush(aIMCTX->lg_file);
110 i_loog(int level,const char *fmt, ... ) {
111 pIMCTX = im_get_context();
114 if (!aIMCTX->lg_file || level > aIMCTX->log_level)
118 im_vloog(aIMCTX, level, fmt, ap);
123 im_loog(pIMCTX, int level,const char *fmt, ... ) {
126 if (!aIMCTX->lg_file || level > aIMCTX->log_level)
130 im_vloog(aIMCTX, level, fmt, ap);
135 =item i_lhead(file, line)
138 This is an internal function called by the mm_log() macro.
144 im_lhead(pIMCTX, const char *file, int line) {
145 if (aIMCTX->lg_file != NULL) {
146 aIMCTX->filename = file;
151 void i_lhead(const char *file, int line) {
152 pIMCTX = im_get_context();
154 im_lhead(aIMCTX, file, line);
160 * Logging is inactive - insert dummy functions
163 int i_init_log(const char* name,int onoff) {
165 i_push_error(0, "Logging disabled");
169 void i_fatal(int exitcode,const char *fmt, ... ) { exit(exitcode); }
170 void im_fatal(pIMCTX, int exitcode,const char *fmt, ... ) { exit(exitcode); }
173 i_loog(int level,const char *fmt, ... ) {
177 i_lhead(const char *file, int line) { }