Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 137 lines (110 sloc) 2.576 kb
e11d297 - Makefile.PL now builds imconfig.h with #defines for libraries
Tony Cook authored
1 #include "imconfig.h"
02d1d62 Initial revision
Arnar Mar Hrafnkelsson authored
2 #include "log.h"
3589189 - fix a few compiler warnings
Tony Cook authored
3 #include <stdlib.h>
10ea52a @tonycoz re-work document and test Imager's logging facility
authored
4 #include <errno.h>
8d14daa @tonycoz switch to using size_t and i_img_dim strictly
authored
5 #include "imerror.h"
10ea52a @tonycoz re-work document and test Imager's logging facility
authored
6
7 #ifdef IMAGER_LOG
02d1d62 Initial revision
Arnar Mar Hrafnkelsson authored
8
9 #define DTBUFF 50
10 #define DATABUFF DTBUFF+3+10+1+5+1+1
11
12 static int log_level = 0;
13 static FILE *lg_file = NULL;
d03fd5a @tonycoz revert threading changes, they aren't ready for the mainline yet
authored
14 static char *date_format = "%Y/%m/%d %H:%M:%S";
02d1d62 Initial revision
Arnar Mar Hrafnkelsson authored
15 static char date_buffer[DTBUFF];
16 static char data_buffer[DATABUFF];
17
a482206 @tonycoz WIP, it compiles
authored
18
02d1d62 Initial revision
Arnar Mar Hrafnkelsson authored
19 /*
20 * Logging is active
21 */
22
10ea52a @tonycoz re-work document and test Imager's logging facility
authored
23 int
d03fd5a @tonycoz revert threading changes, they aren't ready for the mainline yet
authored
24 i_init_log(const char* name,int level) {
10ea52a @tonycoz re-work document and test Imager's logging facility
authored
25 i_clear_error();
d03fd5a @tonycoz revert threading changes, they aren't ready for the mainline yet
authored
26 log_level = level;
02d1d62 Initial revision
Arnar Mar Hrafnkelsson authored
27 if (level < 0) {
d03fd5a @tonycoz revert threading changes, they aren't ready for the mainline yet
authored
28 lg_file = NULL;
02d1d62 Initial revision
Arnar Mar Hrafnkelsson authored
29 } else {
30 if (name == NULL) {
d03fd5a @tonycoz revert threading changes, they aren't ready for the mainline yet
authored
31 lg_file = stderr;
02d1d62 Initial revision
Arnar Mar Hrafnkelsson authored
32 } else {
d03fd5a @tonycoz revert threading changes, they aren't ready for the mainline yet
authored
33 if (NULL == (lg_file = fopen(name, "w+")) ) {
34 i_push_errorf(errno, "Cannot open file '%s': (%d)", name, errno);
10ea52a @tonycoz re-work document and test Imager's logging facility
authored
35 return 0;
02d1d62 Initial revision
Arnar Mar Hrafnkelsson authored
36 }
37 }
38 }
d03fd5a @tonycoz revert threading changes, they aren't ready for the mainline yet
authored
39 if (lg_file) {
40 setvbuf(lg_file, NULL, _IONBF, BUFSIZ);
41 mm_log((0,"Imager - log started (level = %d)\n", level));
10ea52a @tonycoz re-work document and test Imager's logging facility
authored
42 }
43
d03fd5a @tonycoz revert threading changes, they aren't ready for the mainline yet
authored
44 return lg_file != NULL;
02d1d62 Initial revision
Arnar Mar Hrafnkelsson authored
45 }
46
47 void
b1e9695 long delayed renaming of m_fatal() to i_fatal() to match Imager's
Tony Cook authored
48 i_fatal(int exitcode,const char *fmt, ... ) {
02d1d62 Initial revision
Arnar Mar Hrafnkelsson authored
49 va_list ap;
d03fd5a @tonycoz revert threading changes, they aren't ready for the mainline yet
authored
50 time_t timi;
51 struct tm *str_tm;
a482206 @tonycoz WIP, it compiles
authored
52
d03fd5a @tonycoz revert threading changes, they aren't ready for the mainline yet
authored
53 if (lg_file != NULL) {
54 timi = time(NULL);
55 str_tm = localtime(&timi);
56 if ( strftime(date_buffer, DTBUFF, date_format, str_tm) )
57 fprintf(lg_file,"[%s] ",date_buffer);
a482206 @tonycoz WIP, it compiles
authored
58 va_start(ap,fmt);
d03fd5a @tonycoz revert threading changes, they aren't ready for the mainline yet
authored
59 vfprintf(lg_file,fmt,ap);
a482206 @tonycoz WIP, it compiles
authored
60 va_end(ap);
61 }
62 exit(exitcode);
63 }
02d1d62 Initial revision
Arnar Mar Hrafnkelsson authored
64
d03fd5a @tonycoz revert threading changes, they aren't ready for the mainline yet
authored
65
bd8052a merge in tiff re-work branch
Tony Cook authored
66 /*
67 =item i_loog(level, format, ...)
68 =category Logging
69
70 This is an internal function called by the mm_log() macro.
71
72 =cut
73 */
02d1d62 Initial revision
Arnar Mar Hrafnkelsson authored
74
75 void
bf1573f rename some private functions to private names
Tony Cook authored
76 i_loog(int level,const char *fmt, ... ) {
02d1d62 Initial revision
Arnar Mar Hrafnkelsson authored
77 va_list ap;
d03fd5a @tonycoz revert threading changes, they aren't ready for the mainline yet
authored
78 if (level > log_level) return;
79 if (lg_file != NULL) {
80 fputs(data_buffer, lg_file);
81 fprintf(lg_file, "%3d: ",level);
82 va_start(ap,fmt);
83 vfprintf(lg_file, fmt, ap);
84 fflush(lg_file);
85 va_end(ap);
86 }
02d1d62 Initial revision
Arnar Mar Hrafnkelsson authored
87 }
88
6cfee9d API documentation (mostly)
Tony Cook authored
89 /*
90 =item i_lhead(file, line)
91 =category Logging
92
93 This is an internal function called by the mm_log() macro.
94
95 =cut
96 */
02d1d62 Initial revision
Arnar Mar Hrafnkelsson authored
97
98 void
d03fd5a @tonycoz revert threading changes, they aren't ready for the mainline yet
authored
99 i_lhead(const char *file, int line) {
100 time_t timi;
101 struct tm *str_tm;
102
103 if (lg_file != NULL) {
104 timi = time(NULL);
105 str_tm = localtime(&timi);
106 strftime(date_buffer, DTBUFF, date_format, str_tm);
107 #ifdef IMAGER_SNPRINTF
108 snprintf(data_buffer, sizeof(data_buffer), "[%s] %10s:%-5d ", date_buffer, file, line);
109 #else
110 sprintf(data_buffer, "[%s] %10s:%-5d ", date_buffer, file, line);
111 #endif
02d1d62 Initial revision
Arnar Mar Hrafnkelsson authored
112 }
113 }
10ea52a @tonycoz re-work document and test Imager's logging facility
authored
114
115 #else
116
117 /*
118 * Logging is inactive - insert dummy functions
119 */
120
121 int i_init_log(const char* name,int onoff) {
122 i_clear_error();
123 i_push_error(0, "Logging disabled");
124 return 0;
125 }
126
127 void i_fatal(int exitcode,const char *fmt, ... ) { exit(exitcode); }
128
129 void
130 i_loog(int level,const char *fmt, ... ) {
131 }
132
133 void
134 i_lhead(const char *file, int line) { }
135
136 #endif
Something went wrong with that request. Please try again.