diff options
| author | verdant <im@verdant.ee> | 2026-07-27 09:26:27 +0800 |
|---|---|---|
| committer | verdant <im@verdant.ee> | 2026-07-27 09:26:27 +0800 |
| commit | cb77cf4cd2a501993e50a258c201a639962abc0a (patch) | |
| tree | 7f4adc58c7fe92617466e8411ad4dd2a1d3b3c47 /log.c | |
| parent | 4d899ffbc32b79dc41148e71fd5035993ff6c323 (diff) | |
| download | sf-cb77cf4cd2a501993e50a258c201a639962abc0a.tar.gz sf-cb77cf4cd2a501993e50a258c201a639962abc0a.zip | |
Reformat log.c log.h
Diffstat (limited to 'log.c')
| -rw-r--r-- | log.c | 72 |
1 files changed, 37 insertions, 35 deletions
@@ -9,49 +9,51 @@ #include "err.h" #include "utils.h" -FILE* log_file = NULL; - -void log_init(void) { - if (is_debug()) { - log_file = fopen("./log", "a"); - } else { - log_file = fopen(LOG_FILEPATH, "a"); - } - - if (!log_file) { - die("Faild to open log file"); - } +FILE *log_file = NULL; + +void log_init(void) +{ + log_file = fopen(LOG_FILEPATH, "a"); + + if (!log_file) { + die("Faild to open log file"); + } } -void log_write(log_level level, const char* fmt, ...) { - char* level_str; +void log_write(log_level level, const char *fmt, ...) +{ + char *level_str; - if (level == LOG_INFO) level_str = "INFO"; - if (level == LOG_WARN) level_str = "WARN"; - if (level == LOG_ERR) level_str = "ERR"; + if (level == LOG_INFO) + level_str = "INFO"; + if (level == LOG_WARN) + level_str = "WARN"; + if (level == LOG_ERR) + level_str = "ERR"; - time_t rawtime; - struct tm* timeinfo; - char time_str[32]; + time_t rawtime; + struct tm *timeinfo; + char time_str[32]; - time(&rawtime); - timeinfo = localtime(&rawtime); - strftime(time_str, sizeof(time_str), "%Y-%m-%d %H:%M:%S", timeinfo); + time(&rawtime); + timeinfo = localtime(&rawtime); + strftime(time_str, sizeof(time_str), "%Y-%m-%d %H:%M:%S", timeinfo); - fprintf(log_file, "[%s] [%s] ", time_str, level_str); + fprintf(log_file, "[%s] [%s] ", time_str, level_str); - va_list ap; - va_start(ap, fmt); - vfprintf(log_file, fmt, ap); - va_end(ap); + va_list ap; + va_start(ap, fmt); + vfprintf(log_file, fmt, ap); + va_end(ap); - fprintf(log_file, "\n"); - fflush(log_file); + fprintf(log_file, "\n"); + fflush(log_file); } -void log_end(FILE* log_file) { - if (log_file) { - fclose(log_file); - log_file = NULL; - } +void log_end(FILE *log_file) +{ + if (log_file) { + fclose(log_file); + log_file = NULL; + } } |
