1 #define IMAGER_NO_CONTEXT
12 #define DATABUFF DTBUFF+3+10+1+5+1+1
14 #define LOG_DATE_FORMAT "%Y/%m/%d %H:%M:%S"
17 im_vloog(pIMCTX, int level, const char *fmt, va_list ap);
24 im_init_log(pIMCTX, const char* name,int level) {
27 if (aIMCTX->lg_file) {
29 fclose(aIMCTX->lg_file);
30 aIMCTX->lg_file = NULL;
33 aIMCTX->log_level = level;
35 aIMCTX->lg_file = NULL;
38 aIMCTX->lg_file = stderr;
41 if (NULL == (aIMCTX->lg_file = fopen(name, "w+")) ) {
42 im_push_errorf(aIMCTX, errno, "Cannot open file '%s': (%d)", name, errno);
46 setvbuf(aIMCTX->lg_file, NULL, _IONBF, BUFSIZ);
49 if (aIMCTX->lg_file) {
50 im_log((aIMCTX, 0,"Imager - log started (level = %d)\n", level));
53 return aIMCTX->lg_file != NULL;
57 i_fatal(int exitcode,const char *fmt, ... ) {
61 if (aIMCTX->lg_file != NULL) {
63 im_vloog(aIMCTX, 0, fmt, ap);
70 im_fatal(pIMCTX, int exitcode,const char *fmt, ... ) {
73 if (aIMCTX->lg_file != NULL) {
75 im_vloog(aIMCTX, 0, fmt, ap);
82 =item i_loog(level, format, ...)
85 This is an internal function called by the mm_log() macro.
91 im_vloog(pIMCTX, int level, const char *fmt, va_list ap) {
94 char date_buffer[DTBUFF];
96 if (!aIMCTX->lg_file || level > aIMCTX->log_level)
100 str_tm = localtime(&timi);
101 strftime(date_buffer, DTBUFF, LOG_DATE_FORMAT, str_tm);
102 fprintf(aIMCTX->lg_file, "[%s] %10s:%-5d %3d: ", date_buffer,
103 aIMCTX->filename, aIMCTX->line, level);
104 vfprintf(aIMCTX->lg_file, fmt, ap);
105 fflush(aIMCTX->lg_file);
109 i_loog(int level,const char *fmt, ... ) {
113 if (!aIMCTX->lg_file || level > aIMCTX->log_level)
117 im_vloog(aIMCTX, level, fmt, ap);
122 im_loog(pIMCTX, int level,const char *fmt, ... ) {
125 if (!aIMCTX->lg_file || level > aIMCTX->log_level)
129 im_vloog(aIMCTX, level, fmt, ap);
134 =item i_lhead(file, line)
137 This is an internal function called by the mm_log() macro.
143 im_lhead(pIMCTX, const char *file, int line) {
144 if (aIMCTX->lg_file != NULL) {
145 aIMCTX->filename = file;
150 void i_lhead(const char *file, int line) {
153 im_lhead(aIMCTX, file, line);
159 * Logging is inactive - insert dummy functions
162 int im_init_log(pIMCTX, const char* name,int onoff) {
164 i_push_error(0, "Logging disabled");
168 void i_fatal(int exitcode,const char *fmt, ... ) { exit(exitcode); }
169 void im_fatal(pIMCTX, int exitcode,const char *fmt, ... ) { exit(exitcode); }
172 i_loog(int level,const char *fmt, ... ) {
176 im_loog(pIMCTX, int level,const char *fmt, ... ) {
180 i_lhead(const char *file, int line) { }
183 im_lhead(pIMCTX, const char *file, int line) { }