Changeset a5893e9 in code
- Timestamp:
- Mar 5, 2014, 4:56:11 PM (11 years ago)
- Branches:
- master
- Children:
- 4e66b3a
- Parents:
- 45bd56a
- git-author:
- Florian Obser <florian@…> (03/05/14 16:30:11)
- git-committer:
- Mike Belopuhov <mike@…> (03/05/14 16:56:11)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
logger.c
r45bd56a ra5893e9 19 19 #include <sys/socket.h> 20 20 #include <sys/time.h> 21 #include <sys/types.h> 21 22 #include <sys/uio.h> 22 23 #include <errno.h> … … 27 28 #include <syslog.h> 28 29 #include <sysexits.h> 30 #include <time.h> 29 31 #include <login_cap.h> 30 32 #include <event.h> … … 35 37 36 38 void logger_dispatch(int, short, void *); 39 void logger_tick(int, short, void *); 40 void logger_set_ts(void); 37 41 38 42 int logger_pipe; … … 43 47 size_t length; 44 48 }; 49 50 char line_ts[sizeof("[12:34 ]")]; 51 52 struct event ev_tick; 53 struct timeval tick; 45 54 46 55 int … … 100 109 } 101 110 111 /* event for the tick */ 112 tick.tv_sec = 60; 113 tick.tv_usec = 0; 114 evtimer_set(&ev_tick, logger_tick, NULL); 115 if (evtimer_add(&ev_tick, &tick) < 0) { 116 syslog(LOG_ERR, "evtimer_add: %m"); 117 exit (EX_UNAVAILABLE); 118 } 119 logger_set_ts(); 102 120 return event_dispatch(); 103 121 } … … 133 151 /* TODO: check time of the day and open the next file */ 134 152 135 fprintf(stderr, "%s @%s: %s\n", e.nick, e.group, buf);153 fprintf(stderr, "%s%s@%s: %s\n", line_ts, e.nick, e.group, buf); 136 154 } 137 155 … … 155 173 syslog(LOG_ERR, "logger write: %m"); 156 174 } 175 176 void 177 logger_tick(int fd __attribute__((unused)), short event __attribute__((unused)), 178 void *arg __attribute__((unused))) 179 { 180 logger_set_ts(); 181 if (evtimer_add(&ev_tick, &tick) < 0) { 182 syslog(LOG_ERR, "evtimer_add: %m"); 183 exit (EX_UNAVAILABLE); 184 } 185 } 186 void 187 logger_set_ts(void) 188 { 189 struct tm *tm; 190 time_t t; 191 192 t = time(NULL); 193 tm = gmtime(&t); 194 snprintf(line_ts, sizeof(line_ts), "[%02d:%02d] ", tm->tm_hour, 195 tm->tm_min); 196 }
Note:
See TracChangeset
for help on using the changeset viewer.