src/server/daemon/log.c

changeset 60
feb2f1e115c6
parent 45
a24aa388f02f
child 77
f1cff81e425a
equal deleted inserted replaced
59:ab25c0a231d0 60:feb2f1e115c6
57 */ 57 */
58 static UcxMap *access_log_files; // map of AccessLog* 58 static UcxMap *access_log_files; // map of AccessLog*
59 static AccessLog *default_access_log; 59 static AccessLog *default_access_log;
60 60
61 61
62 char *log_date_month[] = { 62 static char *log_date_month[] = {
63 "Jan", 63 "Jan",
64 "Feb", 64 "Feb",
65 "Mar", 65 "Mar",
66 "Apr", 66 "Apr",
67 "May", 67 "May",
72 "Oct", 72 "Oct",
73 "Nov", 73 "Nov",
74 "Dec" 74 "Dec"
75 }; 75 };
76 76
77 char *log_levels[] = { 77 static char *log_levels[] = {
78 "error",
79 "warning", 78 "warning",
80 "info" 79 "config",
80 "security",
81 "failure",
82 "catastrophe",
83 "info",
84 "verbose"
85 };
86
87 static int can_log[] = {
88 1, // warning
89 1, // config
90 1, // security
91 1, // failure
92 1, // catastrophe
93 1, // info
94 0 // verbose
81 }; 95 };
82 96
83 int init_log_file(LogConfig *cfg) { 97 int init_log_file(LogConfig *cfg) {
84 if(is_initialized) { 98 if(is_initialized) {
85 return 0; 99 return 0;
91 if(log_file_fd == -1) { 105 if(log_file_fd == -1) {
92 return -1; 106 return -1;
93 } 107 }
94 108
95 if(!strcmp(cfg->level, "ERROR")) { 109 if(!strcmp(cfg->level, "ERROR")) {
96 log_level = LOG_LEVEL_ERROR; 110 can_log[LOG_WARN] = 0;
111 can_log[LOG_INFORM] = 0;
97 } else if(!strcmp(cfg->level, "WARNING")) { 112 } else if(!strcmp(cfg->level, "WARNING")) {
98 log_level = LOG_LEVEL_WARNING; 113 can_log[LOG_INFORM] = 0;
99 } else if(!strcmp(cfg->level, "INFO")) { 114 } else if(!strcmp(cfg->level, "INFO")) {
100 log_level = LOG_LEVEL_INFO; 115
101 } 116 }
102 117
103 if(cfg->log_stdout) { 118 if(cfg->log_stdout) {
104 // TODO 119 // TODO
105 } 120 }
189 /* 204 /*
190 * log api functions 205 * log api functions
191 */ 206 */
192 207
193 int log_ereport(int degree, const char *format, ...) { 208 int log_ereport(int degree, const char *format, ...) {
194 if(degree > log_level) { 209 if(degree > 6) {
210 return 0;
211 }
212 if(degree > 0 && !can_log[degree]) {
195 return 0; 213 return 0;
196 } 214 }
197 215
198 sstr_t lmsg; 216 sstr_t lmsg;
199 lmsg.ptr = NULL; 217 lmsg.ptr = NULL;

mercurial