summaryrefslogtreecommitdiff
path: root/ted.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-09-24 10:32:07 -0400
committerpommicket <pommicket@gmail.com>2023-09-24 10:32:07 -0400
commit114c05577dc3306b7c416fb0cf02a431e48de952 (patch)
treeb2c6057bf2c0cca7f4525c99e0ae447599c724f7 /ted.c
parentcdf94949a4a12b0f99d855dcfb113905ac8a90f4 (diff)
nicer logging (always show pid, timestamp)
Diffstat (limited to 'ted.c')
-rw-r--r--ted.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/ted.c b/ted.c
index 3c09f01..d1db1fb 100644
--- a/ted.c
+++ b/ted.c
@@ -39,11 +39,19 @@ static void ted_vset_message(Ted *ted, MessageType type, const char *fmt, va_lis
vsnprintf(message, sizeof message - 1, fmt, args);
// output error to log file
- char tstr[256];
- time_t t = time(NULL);
- struct tm *tm = localtime(&t);
- strftime(tstr, sizeof tstr, "%Y-%m-%d %H:%M:%S", tm);
- ted_log(ted, "[ERROR %s] %s\n", tstr, message);
+ const char *type_str = "";
+ switch (type) {
+ case MESSAGE_ERROR:
+ type_str = "ERROR";
+ break;
+ case MESSAGE_WARNING:
+ type_str = "WARNING";
+ break;
+ case MESSAGE_INFO:
+ type_str = "INFO";
+ break;
+ }
+ ted_log(ted, "%s: %s\n", type_str, message);
if (type >= ted->message_type) {
ted->message_type = type;
@@ -51,6 +59,13 @@ static void ted_vset_message(Ted *ted, MessageType type, const char *fmt, va_lis
}
}
+void ted_update_time(Ted *ted) {
+ time_t t = time(NULL);
+ struct tm *tm = localtime(&t);
+ strftime(ted->frame_time_string, sizeof ted->frame_time_string, "%Y-%m-%d %H:%M:%S", tm);
+ ted->frame_time = time_get_seconds();
+}
+
TextBuffer *ted_active_buffer(Ted *ted) {
return ted->active_buffer;
}
@@ -146,8 +161,10 @@ void ted_log(Ted *ted, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
+ fprintf(ted->log, "[pid %d, %s] ", ted->pid, ted->frame_time_string);
vfprintf(ted->log, fmt, args);
va_end(args);
+ fflush(ted->log);
}
@@ -796,7 +813,6 @@ static void mark_node_reachable(Ted *ted, Node *node, bool *reachable) {
if (i < 0) return;
if (reachable[i]) {
ted_error(ted, "Node %d reachable in 2 different ways\nThis should never happen.", i);
- ted_log(ted, "Node %d reachable in 2 different ways\n", i);
node_close(ted, node);
return;
}
@@ -814,7 +830,6 @@ void ted_check_for_node_problems(Ted *ted) {
for (u32 i = 0; i < arr_len(ted->nodes); ++i) {
if (!reachable[i]) {
ted_error(ted, "ORPHANED NODE %u\nThis should never happen.", i);
- ted_log(ted, "ORPHANED NODE %u\n", i);
node_close(ted, ted->nodes[i]);
--i;
}