1 #define IMAGER_NO_CONTEXT
12 #define DATABUFF DTBUFF+3+10+1+5+1+1
15 static int log_level = 0;
16 static FILE *lg_file = NULL;
17 static char date_buffer[DTBUFF];
18 static char data_buffer[DATABUFF];
21 #define LOG_DATE_FORMAT "%Y/%m/%d %H:%M:%S"
24 im_vloog(pIMCTX, int level, const char *fmt, va_list ap);
31 im_init_log(pIMCTX, const char* name,int level) {
33 aIMCTX->log_level = level;
35 aIMCTX->lg_file = NULL;
38 aIMCTX->lg_file = stderr;
40 if (NULL == (aIMCTX->lg_file = fopen(name, "w+")) ) {
41 im_push_errorf(aIMCTX, errno, "Cannot open file '%s': (%d)", name, errno);
46 if (aIMCTX->lg_file) {
47 setvbuf(aIMCTX->lg_file, NULL, _IONBF, BUFSIZ);
48 im_log((aIMCTX, 0,"Imager - log started (level = %d)\n", level));
51 return aIMCTX->lg_file != NULL;
55 i_fatal(int exitcode,const char *fmt, ... ) {
59 if (aIMCTX->lg_file != NULL) {
61 im_vloog(aIMCTX, 0, fmt, ap);
68 im_fatal(pIMCTX, int exitcode,const char *fmt, ... ) {
71 if (aIMCTX->lg_file != NULL) {
73 im_vloog(aIMCTX, 0, fmt, ap);
80 =item i_loog(level, format, ...)
83 This is an internal function called by the mm_log() macro.
89 im_vloog(pIMCTX, int level, const char *fmt, va_list ap) {
92 char date_buffer[DTBUFF];
94 if (!aIMCTX->lg_file || level > aIMCTX->log_level)
98 str_tm = localtime(&timi);
99 strftime(date_buffer, DTBUFF, LOG_DATE_FORMAT, str_tm);
100 fprintf(aIMCTX->lg_file, "[%s] %10s:%-5d %3d: ", date_buffer,
101 aIMCTX->filename, aIMCTX->line, level);
102 vfprintf(aIMCTX->lg_file, fmt, ap);
103 fflush(aIMCTX->lg_file);
107 i_loog(int level,const char *fmt, ... ) {
111 if (!aIMCTX->lg_file || level > aIMCTX->log_level)
115 im_vloog(aIMCTX, level, fmt, ap);
120 im_loog(pIMCTX, int level,const char *fmt, ... ) {
123 if (!aIMCTX->lg_file || level > aIMCTX->log_level)
127 im_vloog(aIMCTX, level, fmt, ap);
132 =item i_lhead(file, line)
135 This is an internal function called by the mm_log() macro.
141 im_lhead(pIMCTX, const char *file, int line) {
142 if (aIMCTX->lg_file != NULL) {
143 aIMCTX->filename = file;
148 void i_lhead(const char *file, int line) {
151 im_lhead(aIMCTX, file, line);
157 * Logging is inactive - insert dummy functions
160 int im_init_log(pIMCTX, const char* name,int onoff) {
162 i_push_error(0, "Logging disabled");
166 void i_fatal(int exitcode,const char *fmt, ... ) { exit(exitcode); }
167 void im_fatal(pIMCTX, int exitcode,const char *fmt, ... ) { exit(exitcode); }
170 i_loog(int level,const char *fmt, ... ) {
174 im_loog(pIMCTX, int level,const char *fmt, ... ) {
178 i_lhead(const char *file, int line) { }
181 im_lhead(pIMCTX, const char *file, int line) { }