Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / ntp / dist / sntp / log.c
blob2b32ba55a95d8e37df158fe44e63cf8b364c1d30
1 /* $NetBSD$ */
3 #include "log.h"
4 #include "sntp-opts.h"
6 int init = 0;
7 int filelog = 0;
9 FILE *log_file;
12 void log_msg(char *message, char type) {
13 if(init) {
14 time_t cur_time = time(NULL);
15 char *timestamp = ctime(&cur_time);
17 fprintf(log_file, "%s: %s\n", timestamp, message);
18 fflush(log_file);
20 else {
21 switch(type) {
22 case 0:
23 type = LOG_CONS;
24 break;
26 case 1:
27 type = LOG_DEBUG | LOG_CONS;
28 break;
30 case 2:
31 type = LOG_WARNING | LOG_CONS;
32 break;
35 syslog(type, message);
39 void debug_msg(char *message) {
40 if(HAVE_OPT(FILELOG)) {
41 time_t cur_time = time(NULL);
42 char *timestamp = ctime(&cur_time);
44 fprintf(stderr, "%s: %s\n", timestamp, message);
46 else {
47 syslog(LOG_DEBUG
48 #ifdef LOG_PERROR
49 | LOG_PERROR
50 #endif
51 | LOG_CONS, message);
55 void init_log(
56 const char *logfile
59 char error_msg[80];
61 log_file = fopen(logfile, "a");
62 if (log_file == NULL) {
63 filelog = 0;
65 snprintf(error_msg, 80, "init_log(): Cannot open logfile %s", logfile);
66 debug_msg(error_msg);
68 return;
69 } else {
70 filelog = 1;
71 init = 1;
72 atexit(cleanup_log);
76 void cleanup_log(void) {
77 init = 0;
78 fflush(log_file);
79 fclose(log_file);