mirror of
https://github.com/Tha14/toxic.git
synced 2025-02-17 06:17:24 +01:00
easier way to format timestamps
This commit is contained in:
parent
5e377639c8
commit
ce76896eb3
14
src/log.c
14
src/log.c
@ -51,10 +51,9 @@ void init_logging_session(uint8_t *name, uint8_t *key, struct chatlog *log)
|
|||||||
sprintf(&ident[2], "%02X", key[2] & 0xff);
|
sprintf(&ident[2], "%02X", key[2] & 0xff);
|
||||||
ident[KEY_IDENT_DIGITS*2+1] = '\0';
|
ident[KEY_IDENT_DIGITS*2+1] = '\0';
|
||||||
} else {
|
} else {
|
||||||
struct tm *tminfo = get_time();
|
uint8_t s[MAX_STR_SIZE];
|
||||||
snprintf(ident, sizeof(ident),
|
strftime(s, MAX_STR_SIZE, "%Y-%m-%d[%H:%M:%S]", get_time());
|
||||||
"%04d-%02d-%02d[%d:%02d:%02d]", tminfo->tm_year+1900,tminfo->tm_mon+1, tminfo->tm_mday,
|
snprintf(ident, sizeof(ident), "%s", s);
|
||||||
tminfo->tm_hour, tminfo->tm_min, tminfo->tm_sec);
|
|
||||||
path_len += strlen(ident) + 1;
|
path_len += strlen(ident) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,10 +95,9 @@ void write_to_log(uint8_t *msg, uint8_t *name, struct chatlog *log, bool event)
|
|||||||
else
|
else
|
||||||
snprintf(name_frmt, sizeof(name_frmt), "%s:", name);
|
snprintf(name_frmt, sizeof(name_frmt), "%s:", name);
|
||||||
|
|
||||||
struct tm *tminfo = get_time();
|
uint8_t s[MAX_STR_SIZE];
|
||||||
fprintf(log->file,"%04d/%02d/%02d [%d:%02d:%02d] %s %s\n", tminfo->tm_year+1900,
|
strftime(s, MAX_STR_SIZE, "%Y/%m/%d [%H:%M:%S]", get_time());
|
||||||
tminfo->tm_mon+1, tminfo->tm_mday, tminfo->tm_hour, tminfo->tm_min,
|
fprintf(log->file,"%s %s %s\n", s, name_frmt, msg);
|
||||||
tminfo->tm_sec, name_frmt, msg);
|
|
||||||
|
|
||||||
uint64_t curtime = (uint64_t) time(NULL);
|
uint64_t curtime = (uint64_t) time(NULL);
|
||||||
|
|
||||||
|
@ -67,10 +67,11 @@ struct tm *get_time(void)
|
|||||||
/* Prints the time to given window */
|
/* Prints the time to given window */
|
||||||
void print_time(WINDOW *window)
|
void print_time(WINDOW *window)
|
||||||
{
|
{
|
||||||
struct tm *timeinfo = get_time();
|
uint8_t s[MAX_STR_SIZE];
|
||||||
|
strftime(s, MAX_STR_SIZE, "[%H:%M] ", get_time());
|
||||||
|
|
||||||
wattron(window, COLOR_PAIR(BLUE));
|
wattron(window, COLOR_PAIR(BLUE));
|
||||||
wprintw(window, "[%d:%02d:%02d] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
|
wprintw(window, "%s", s);
|
||||||
wattroff(window,COLOR_PAIR(BLUE));
|
wattroff(window,COLOR_PAIR(BLUE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user