Mercurial > hg > nnchat
comparison main.c @ 554:13901e9be15b
Implement daily logs for room logs.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 12 Nov 2012 19:11:30 +0200 |
parents | b464409fa643 |
children | 66d18a82d6b9 |
comparison
equal
deleted
inserted
replaced
553:b464409fa643 | 554:13901e9be15b |
---|---|
59 char optNickSep; | 59 char optNickSep; |
60 BOOL optDaemon = FALSE, | 60 BOOL optDaemon = FALSE, |
61 setIgnoreMode = FALSE, | 61 setIgnoreMode = FALSE, |
62 optDebug = FALSE, | 62 optDebug = FALSE, |
63 optLogEnable = FALSE, | 63 optLogEnable = FALSE, |
64 optLogDaily = FALSE, | |
64 optOnlyFriendPrv = FALSE; | 65 optOnlyFriendPrv = FALSE; |
65 | 66 |
66 qlist_t *setIgnoreList = NULL, | 67 qlist_t *setIgnoreList = NULL, |
67 *setFriendList = NULL, | 68 *setFriendList = NULL, |
68 *setIdleMessages = NULL; | 69 *setIdleMessages = NULL; |
81 { | 82 { |
82 LOG_FILE = 0x0001, | 83 LOG_FILE = 0x0001, |
83 LOG_WINDOW = 0x0002, | 84 LOG_WINDOW = 0x0002, |
84 LOG_STAMP = 0x0004, | 85 LOG_STAMP = 0x0004, |
85 LOG_FILE2 = 0x0008, | 86 LOG_FILE2 = 0x0008, |
87 LOG_RECURSIVE = 0x0010, | |
86 }; | 88 }; |
87 | 89 |
88 | 90 |
89 /* Arguments | 91 /* Arguments |
90 */ | 92 */ |
244 printFile(win->logFile, msg); | 246 printFile(win->logFile, msg); |
245 fflush(win->logFile); | 247 fflush(win->logFile); |
246 } | 248 } |
247 } | 249 } |
248 | 250 |
251 | |
252 void printMsgF(nn_window_t *win, int flags, const char *fmt, ...); | |
253 BOOL nn_log_reopen(nn_window_t *win); | |
254 | |
255 | |
249 void printMsgV(nn_window_t *win, int flags, const char *fmt, va_list ap) | 256 void printMsgV(nn_window_t *win, int flags, const char *fmt, va_list ap) |
250 { | 257 { |
251 char tmpStr[128], *buf; | 258 char tmpStr[128], *buf; |
259 nn_window_t *tmpwin = (win != NULL) ? win : nnwin_main_window(); | |
260 | |
261 // Only the main window | |
262 if (win == NULL && (flags & LOG_RECURSIVE) == 0) | |
263 { | |
264 time_t currTime = time(NULL); | |
265 struct tm *currTm, *prevTm; | |
266 | |
267 if ((currTm = localtime(&currTime)) != NULL && | |
268 currTm->tm_hour == 0 && | |
269 (prevTm = localtime(&tmpwin->logPrevMsgTime)) != NULL && | |
270 prevTm->tm_hour == 23) | |
271 { | |
272 str_get_timestamp(tmpStr, sizeof(tmpStr), "%d %b %Y"); | |
273 printMsgF(win, LOG_RECURSIVE, "Day changed to %s.\n", tmpStr); | |
274 nn_log_reopen(tmpwin); | |
275 } | |
276 | |
277 tmpwin->logPrevMsgTime = currTime; | |
278 } | |
252 | 279 |
253 if (flags & LOG_STAMP) | 280 if (flags & LOG_STAMP) |
254 { | 281 { |
255 str_get_timestamp(tmpStr, sizeof(tmpStr), "½17½[½11½%H:%M:%S½17½]½0½ "); | 282 str_get_timestamp(tmpStr, sizeof(tmpStr), "½17½[½11½%H:%M:%S½17½]½0½ "); |
256 } | 283 } |
267 printMsgFile(nnwin_main_window(), flags, tmpStr, buf); | 294 printMsgFile(nnwin_main_window(), flags, tmpStr, buf); |
268 } | 295 } |
269 | 296 |
270 if (!optDaemon && (flags & LOG_WINDOW)) | 297 if (!optDaemon && (flags & LOG_WINDOW)) |
271 { | 298 { |
272 nn_window_t *tmp = (win != NULL) ? win : nnwin_main_window(); | 299 if (flags & LOG_STAMP) nnwin_print(tmpwin, tmpStr); |
273 if (flags & LOG_STAMP) nnwin_print(tmp, tmpStr); | 300 nnwin_print(tmpwin, buf); |
274 nnwin_print(tmp, buf); | |
275 } | 301 } |
276 | 302 |
277 th_free(buf); | 303 th_free(buf); |
278 } | 304 } |
279 | 305 |
1520 path = th_strdup(optLogPath); | 1546 path = th_strdup(optLogPath); |
1521 } | 1547 } |
1522 | 1548 |
1523 if (win->id == NULL) | 1549 if (win->id == NULL) |
1524 { | 1550 { |
1525 win->logFilename = th_strdup_printf("%sroom_%d%s", | 1551 // Main window log (aka room log) |
1526 path != NULL ? path : "", optPort, optLogExtension); | 1552 if (optLogDaily) |
1553 { | |
1554 char stamp[64]; | |
1555 str_get_timestamp(stamp, sizeof(stamp), "%Y-%m-%d"); | |
1556 win->logFilename = th_strdup_printf("%sroom_%d-%s%s", | |
1557 path != NULL ? path : "", optPort, | |
1558 stamp, optLogExtension); | |
1559 } | |
1560 else | |
1561 { | |
1562 win->logFilename = th_strdup_printf("%sroom_%d%s", | |
1563 path != NULL ? path : "", optPort, optLogExtension); | |
1564 } | |
1527 } | 1565 } |
1528 else | 1566 else |
1529 { | 1567 { |
1530 // PRV chat log | 1568 // PRV chat log |
1531 size_t pos; | 1569 size_t pos; |
1575 fclose(win->logFile); | 1613 fclose(win->logFile); |
1576 win->logFile = NULL; | 1614 win->logFile = NULL; |
1577 | 1615 |
1578 th_free(win->logFilename); | 1616 th_free(win->logFilename); |
1579 win->logFilename = NULL; | 1617 win->logFilename = NULL; |
1618 } | |
1619 | |
1620 | |
1621 BOOL nn_log_reopen(nn_window_t *win) | |
1622 { | |
1623 nn_log_close(win); | |
1624 return nn_log_open(win); | |
1580 } | 1625 } |
1581 | 1626 |
1582 | 1627 |
1583 BOOL nn_stat_path(const char *path, BOOL *isDirectory, BOOL *isWritable, BOOL *isReadable) | 1628 BOOL nn_stat_path(const char *path, BOOL *isDirectory, BOOL *isWritable, BOOL *isReadable) |
1584 { | 1629 { |
1717 | 1762 |
1718 | 1763 |
1719 tmpcfg = NULL; | 1764 tmpcfg = NULL; |
1720 th_cfg_add_comment(&tmpcfg, "Enable logging"); | 1765 th_cfg_add_comment(&tmpcfg, "Enable logging"); |
1721 th_cfg_add_bool(&tmpcfg, "enable", &optLogEnable, optLogEnable); | 1766 th_cfg_add_bool(&tmpcfg, "enable", &optLogEnable, optLogEnable); |
1767 | |
1768 th_cfg_add_comment(&tmpcfg, "Use daily logfiles for room logs"); | |
1769 th_cfg_add_bool(&tmpcfg, "daily", &optLogDaily, optLogDaily); | |
1770 | |
1722 th_cfg_add_comment(&tmpcfg, "Log files path"); | 1771 th_cfg_add_comment(&tmpcfg, "Log files path"); |
1723 th_cfg_add_string(&tmpcfg, "path", &optLogPath, optLogPath); | 1772 th_cfg_add_string(&tmpcfg, "path", &optLogPath, optLogPath); |
1724 | 1773 |
1725 th_cfg_add_comment(&tmpcfg, "Log filename extension"); | 1774 th_cfg_add_comment(&tmpcfg, "Log filename extension"); |
1726 th_cfg_add_string(&tmpcfg, "extension", &optLogExtension, optLogExtension); | 1775 th_cfg_add_string(&tmpcfg, "extension", &optLogExtension, optLogExtension); |