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"
27 im_init_log(pIMCTX, const char* name,int level) {
29 aIMCTX->log_level = level;
31 aIMCTX->lg_file = NULL;
34 aIMCTX->lg_file = stderr;
36 if (NULL == (aIMCTX->lg_file = fopen(name, "w+")) ) {
37 i_push_errorf(errno, "Cannot open file '%s': (%d)", name, errno);
42 if (aIMCTX->lg_file) {
43 setvbuf(aIMCTX->lg_file, NULL, _IONBF, BUFSIZ);
44 mm_log((0,"Imager - log started (level = %d)\n", level));
47 return aIMCTX->lg_file != NULL;
52 i_fatal(int exitcode,const char *fmt, ... ) {
57 if (lg_file != NULL) {
59 str_tm = localtime(&timi);
60 if ( strftime(date_buffer, DTBUFF, date_format, str_tm) )
61 fprintf(lg_file,"[%s] ",date_buffer);
63 vfprintf(lg_file,fmt,ap);
72 =item i_loog(level, format, ...)
75 This is an internal function called by the mm_log() macro.
81 im_vloog(pIMCTX, int level, const char *fmt, va_list ap) {
84 char date_buffer[DTBUFF];
86 if (!aIMCTX->lg_file || level > aIMCTX->log_level)
90 str_tm = localtime(&timi);
91 strftime(date_buffer, DTBUFF, LOG_DATE_FORMAT, str_tm);
92 fprintf(aIMCTX->lg_file, "[%s] %10s:%-5d %3d: ", date_buffer,
93 aIMCTX->filename, aIMCTX->line, level);
94 vfprintf(aIMCTX->lg_file, fmt, ap);
95 fflush(aIMCTX->lg_file);
99 i_loog(int level,const char *fmt, ... ) {
100 pIMCTX = im_get_context();
103 if (!aIMCTX->lg_file || level > aIMCTX->log_level)
107 im_vloog(aIMCTX, level, fmt, ap);
112 im_loog(pIMCTX, int level,const char *fmt, ... ) {
115 if (!aIMCTX->lg_file || level > aIMCTX->log_level)
119 im_vloog(aIMCTX, level, fmt, ap);
124 =item i_lhead(file, line)
127 This is an internal function called by the mm_log() macro.
133 im_lhead(pIMCTX, const char *file, int line) {
134 if (aIMCTX->lg_file != NULL) {
135 aIMCTX->filename = file;
140 void i_lhead(const char *file, int line) {
141 pIMCTX = im_get_context();
143 im_lhead(aIMCTX, file, line);
149 * Logging is inactive - insert dummy functions
152 int i_init_log(const char* name,int onoff) {
154 i_push_error(0, "Logging disabled");
158 void i_fatal(int exitcode,const char *fmt, ... ) { exit(exitcode); }
161 i_loog(int level,const char *fmt, ... ) {
165 i_lhead(const char *file, int line) { }