Repo for OpenPTS version 0.2.X
修订版 | a0496f4d32b4ec6d3ea4598e559b9fdfeb8ddc31 (tree) |
---|---|
时间 | 2012-01-05 09:05:41 |
作者 | Seiji Munetoh <munetoh@jp.i...> |
Commiter | Seiji Munetoh |
set initial value (-1) to catd to avoid segmentation fault by catgets called before catopen
@@ -26,43 +26,31 @@ | ||
26 | 26 | * \brief logging functions |
27 | 27 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
28 | 28 | * @date 2010-05-07 |
29 | - * cleanup 2011-01-22 SM | |
30 | - * cleanup 2011-12-28 SM | |
29 | + * cleanup 2012-01-04 SM | |
31 | 30 | * |
32 | - * Verbose OUTPUT VERBOSE LOGGING | |
33 | - * Level (stdout) (stderr) (console/syslog/file) | |
31 | + * Console output | |
32 | + * | |
33 | + * Verbose OUTPUT ERROR/VERBOSE | |
34 | + * Level (stdout) (stderr) | |
34 | 35 | * -------------------------------------------------- |
35 | - * 0 ON ERROR msg. ERROR/INFO | |
36 | - * 1 ON +verbose msg. ERROR/INFO | |
37 | - * 2 ON ERROR/INFO+DEBUG | |
36 | + * 0 ON ERROR msg. | |
37 | + * 1 ON +verbose(1) msg | |
38 | + * 2 ON +verbose(2) msg | |
38 | 39 | * -------------------------------------------------- |
39 | 40 | * |
40 | - * LOG | |
41 | - * off | |
42 | - * error | |
43 | - * on/debug | |
44 | - * | |
45 | - * Config | |
46 | - * verbose=0 | |
47 | - * logging.location=console|syslog|file | |
48 | - * logging.file=./ptsc.log | |
49 | - * debug.mode=0x01 | |
41 | + * Logging (syslog/console/file) | |
50 | 42 | * |
51 | - * Priority | |
52 | - * 1. Commandline option (location/file must be given by conf) | |
53 | - * 2. ENV | |
54 | - * 3. Conf file | |
43 | + * Default logging scheme is hard coded by each command | |
55 | 44 | * |
56 | - * LOG("msg",format) | |
45 | + * ptsc -m syslog -> conf | |
46 | + * ptsc else env -> conf | |
47 | + * openpts default(file ~/.openpts/openpts.log) -> conf | |
57 | 48 | * |
58 | - * OUTPUT console/stderr | |
59 | - * VERBOSE console/stderr | |
60 | - * ASSERT console/stderr | |
49 | + * Controlled by config file | |
50 | + * debug.mode=0x01 | |
51 | + * logging.location=console|syslog|file | |
52 | + * logging.file=./ptsc.log | |
61 | 53 | * |
62 | - * ERROR console|file|syslog | |
63 | - * INFO console|file|syslog | |
64 | - * TODO console|file|syslog | |
65 | - * DEBUG console|file|syslog | |
66 | 54 | * |
67 | 55 | */ |
68 | 56 |
@@ -107,7 +95,7 @@ | ||
107 | 95 | #include <locale.h> |
108 | 96 | #ifdef HAVE_CATGETS |
109 | 97 | #include <nl_types.h> |
110 | -nl_catd catd; | |
98 | +nl_catd catd = (nl_catd) -1; /* set error until open */ | |
111 | 99 | #endif |
112 | 100 | #endif |
113 | 101 |
@@ -206,7 +194,7 @@ void determineLogLocationByEnv(void) { | ||
206 | 194 | |
207 | 195 | /* debug mode => debugBits */ |
208 | 196 | if ((tempDebugMode = getenv("OPENPTS_DEBUG_MODE")) != NULL) { |
209 | - debugBits = (int) strtol(tempDebugMode,NULL,16); | |
197 | + debugBits = (int) strtol(tempDebugMode, NULL, 16); | |
210 | 198 | DEBUG("DEBUG FLAG(0x%x) set by ENV\n", debugBits); |
211 | 199 | } |
212 | 200 | } |
@@ -222,7 +210,7 @@ void setLogLocation(int ll, char *filename) { | ||
222 | 210 | char * oldlog; |
223 | 211 | /* already open */ |
224 | 212 | LOG(LOG_INFO, "Logfile changed from %s to %s\n", logFileName, filename); |
225 | - oldlog=strdup(logFileName); | |
213 | + oldlog = strdup(logFileName); | |
226 | 214 | if (oldlog == NULL) { |
227 | 215 | LOG(LOG_ERR, "no memory"); |
228 | 216 | return; |
@@ -389,42 +377,11 @@ void writeLog(int priority, const char *format, ...) { | ||
389 | 377 | fprintf(stderr, "%s", logEntry); |
390 | 378 | break; |
391 | 379 | } |
392 | - // TODO default? | |
380 | + default: | |
381 | + LOG(LOG_ERR, "Unknown logLocation, %d", logLocation); | |
382 | + break; | |
393 | 383 | } |
394 | 384 | |
395 | - | |
396 | -#if 0 | |
397 | - va_start(list, format); | |
398 | - | |
399 | - // if (getenv("PTSCD_DAEMON") != NULL) { | |
400 | - if (getenv("OPENPTS_SYSLOG") != NULL) { | |
401 | - /* daemon -> syslog */ | |
402 | - openlog("ptsc", LOG_NDELAY|LOG_PID, LOG_LOCAL5); | |
403 | - | |
404 | - // 2011-04-11 SM shows verbose messages | |
405 | - if (priority == LOG_DEBUG) priority = LOG_INFO; | |
406 | - | |
407 | - // vsyslog is not supported by some unix | |
408 | - vsnprintf(buf, SYSLOG_BUF_SIZE, format, list); | |
409 | - syslog(priority, "%s", buf); | |
410 | - | |
411 | - closelog(); | |
412 | - } else { | |
413 | - /* foregrond -> stdout */ | |
414 | - if (priority == LOG_INFO) { | |
415 | - fprintf(stdout, "INFO:"); | |
416 | - } else if (priority == LOG_ERR) { | |
417 | - fprintf(stdout, "ERROR:"); | |
418 | - } else { | |
419 | - fprintf(stdout, "%d:", priority); | |
420 | - } | |
421 | - vfprintf(stdout, format, list); | |
422 | - fprintf(stdout, "\n"); | |
423 | - } | |
424 | - va_end(list); | |
425 | -#endif | |
426 | - | |
427 | - | |
428 | 385 | if (format2 != NULL) free(format2); |
429 | 386 | } |
430 | 387 |
@@ -435,7 +392,7 @@ static int openLogFile(void) { | ||
435 | 392 | return logFileFd; |
436 | 393 | } |
437 | 394 | |
438 | - //logFileFd = open(logFileName, O_RDWR|O_CREAT|O_TRUNC, DEFAULT_LOG_FILE_PERM); | |
395 | + /* append to the existing file */ | |
439 | 396 | logFileFd = open(logFileName, O_WRONLY|O_CREAT|O_APPEND, DEFAULT_LOG_FILE_PERM); |
440 | 397 | return logFileFd; |
441 | 398 | } |