aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorverdant <im@verdant.ee>2026-07-27 09:26:27 +0800
committerverdant <im@verdant.ee>2026-07-27 09:26:27 +0800
commitcb77cf4cd2a501993e50a258c201a639962abc0a (patch)
tree7f4adc58c7fe92617466e8411ad4dd2a1d3b3c47
parent4d899ffbc32b79dc41148e71fd5035993ff6c323 (diff)
downloadsf-cb77cf4cd2a501993e50a258c201a639962abc0a.tar.gz
sf-cb77cf4cd2a501993e50a258c201a639962abc0a.zip
Reformat log.c log.h
-rw-r--r--log.c72
-rw-r--r--log.h2
2 files changed, 39 insertions, 35 deletions
diff --git a/log.c b/log.c
index 305a666..18e24a7 100644
--- a/log.c
+++ b/log.c
@@ -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;
+ }
}
diff --git a/log.h b/log.h
index f53c18f..9b5dae1 100644
--- a/log.h
+++ b/log.h
@@ -13,4 +13,6 @@ void log_init(void);
void log_write(log_level level, const char *fmt, ...);
+#define LOG_WRITE_INFO(fmt, ...) log_write(LOG_INFO, fmt, ##__VA_ARGS__)
+
#endif /* SS_LOG_H */