diff options
Diffstat (limited to 'src/log.cpp')
| -rw-r--r-- | src/log.cpp | 110 |
1 files changed, 0 insertions, 110 deletions
diff --git a/src/log.cpp b/src/log.cpp deleted file mode 100644 index 094bcab..0000000 --- a/src/log.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* -* Copyright (c) 2025 Aldrik Ramaekers <aldrik.ramaekers@gmail.com> -* -* Permission to use, copy, modify, and/or distribute this software for any -* purpose with or without fee is hereby granted, provided that the above -* copyright notice and this permission notice appear in all copies. -* -* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -#include <stdio.h> -#include <stdarg.h> -#include <time.h> -#include "timer.h" -#include "log.hpp" - -program_log g_log = {0}; - -program_log* get_log() -{ - return &g_log; -} - -void log_clear() -{ - g_log.write_cursor = 0; - g_log.history_length = 0; -} - -static void log_message(const char* fmt, ImVec4 color, va_list args) -{ - vsnprintf(g_log.history[g_log.write_cursor], MAX_LEN_LOG_TXT, fmt, args); - g_log.colors[g_log.write_cursor] = color; - - tick_t ms_since_epoch = timer_system(); - char time_buf[50]; - time_t seconds = (time_t)(ms_since_epoch / 1000); - int milliseconds = (int)(ms_since_epoch % 1000); - - // Convert to local time - struct tm tm_time; - #if defined(_WIN32) - localtime_s(&tm_time, &seconds); - #else - localtime_r(&seconds, &tm_time); - #endif - - snprintf(time_buf, 50, "%02d:%02d %02d.%03d", - tm_time.tm_hour, - tm_time.tm_min, - tm_time.tm_sec, - milliseconds); - - char tmp[MAX_LEN_LOG_TXT]; - snprintf(tmp, MAX_LEN_LOG_TXT, "[%s] %s", time_buf, g_log.history[g_log.write_cursor]); - tmp[MAX_LEN_LOG_TXT-1] = 0; - memcpy(g_log.history[g_log.write_cursor], tmp, MAX_LEN_LOG_TXT); - - g_log.write_cursor++; - if (g_log.write_cursor >= MAX_LEN_LOG_HISTORY) g_log.write_cursor = 0; - - g_log.history_length++; - if (g_log.history_length > MAX_LEN_LOG_HISTORY) g_log.history_length = MAX_LEN_LOG_HISTORY; -} - -void log_aerr(a_err errors) -{ - if (errors & A_ERR_GENERIC) log_error(" ERROR: Generic error"); - if (errors & A_ERR_NOT_FOUND) log_error(" ERROR: Not found"); - if (errors & A_ERR_MISSING_DESCRIPTION) log_error(" ERROR: Missing description"); - if (errors & A_ERR_CODE_EXISTS) log_error(" ERROR: Code already exists"); - if (errors & A_ERR_MISSING_BILLING_ITEMS) log_error(" ERROR: Missing billing items"); - if (errors & A_ERR_INVALID_ADDRESSEE) log_error(" ERROR: Invalid addressee"); - if (errors & A_ERR_INVALID_CUSTOMER) log_error(" ERROR: Invalid customer"); - if (errors & A_ERR_INVALID_SUPPLIER) log_error(" ERROR: Invalid supplier"); - if (errors & A_ERR_MISSING_NAME) log_error(" ERROR: Missing name"); - if (errors & A_ERR_MISSING_CITY) log_error(" ERROR: Missing city"); - if (errors & A_ERR_MISSING_POSTAL) log_error(" ERROR: Missing postal code"); - if (errors & A_ERR_MISSING_ADDRESS1) log_error(" ERROR: Missing address line 1"); - if (errors & A_ERR_MISSING_COUNTRYCODE) log_error(" ERROR: Missing country code"); - if (errors & A_ERR_MISSING_TAXID) log_error(" ERROR: Missing tax ID"); - if (errors & A_ERR_MISSING_BUSINESSID) log_error(" ERROR: Missing business ID"); - if (errors & A_ERR_MAX_ITEMS_REACHED) log_error(" ERROR: Maximum items reached"); - if (errors & A_ERR_MISSING_CODE) log_error(" ERROR: Missing code"); - if (errors & A_ERR_MISSING_EMAIL) log_error(" ERROR: Missing email"); - if (errors & A_ERR_MISSING_TAX_RATE) log_error(" ERROR: Missing tax rate"); - if (errors & A_ERR_INVALID_BILLING_ITEM) log_error(" ERROR: Invalid billing item"); -} - -void log_error(const char* fmt, ...) -{ - va_list args; - va_start(args, fmt); - log_message(fmt, ImVec4(1,0,0,1), args); - va_end(args); -} - -void log_info(const char* fmt, ...) -{ - va_list args; - va_start(args, fmt); - log_message(fmt, ImVec4(1,1,1,1), args); - va_end(args); -} |
