From 99c7398a5798a19595d053467e7428fa04911184 Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Sat, 11 Jun 2022 12:46:09 +0200 Subject: [PATCH] Configurable log levels --- log.cpp | 21 +++++++++++++++++++++ log.h | 8 ++++++-- main.cpp | 19 ++++++++++++++----- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/log.cpp b/log.cpp index 977b286..386049a 100644 --- a/log.cpp +++ b/log.cpp @@ -100,3 +100,24 @@ void dolog(const log_level_t ll, const char *fmt, ...) free(ts_str); } +log_level_t parse_ll(const std::string & str) +{ + if (str == "debug") + return debug; + + if (str == "info") + return info; + + if (str == "warning") + return warning; + + if (str == "error") + return ll_error; + + if (str == "none") + return none; + + error_exit(false, "Log level \"%s\" not understood", str.c_str()); + + return debug; +} diff --git a/log.h b/log.h index d531b06..dd2cd97 100644 --- a/log.h +++ b/log.h @@ -1,5 +1,9 @@ -typedef enum { debug, info, warning, ll_error } log_level_t; // TODO ll_ prefix - // +#include + + +typedef enum { debug, info, warning, ll_error, none } log_level_t; // TODO ll_ prefix + +log_level_t parse_ll(const std::string & str); void setlog(const char *lf, const log_level_t ll_file, const log_level_t ll_screen); void setloguid(const int uid, const int gid); void closelog(); diff --git a/main.cpp b/main.cpp index d473655..35bbdcd 100644 --- a/main.cpp +++ b/main.cpp @@ -47,12 +47,12 @@ void help() printf("-T t.bin load file as a binary tape file (like simh \"load\" command)\n"); printf("-R d.rk load file as a RK05 disk device\n"); printf("-p 123 set CPU start pointer to decimal(!) value\n"); - printf("-L f.bin load file into memory at address given by -p (and run it)\n"); printf("-b x enable bootloader (build-in), parameter must be \"rk05\" or \"rl02\"\n"); printf("-n ncurses UI\n"); printf("-d enable debugger\n"); printf("-t enable tracing (disassemble to stderr, requires -d as well)\n"); printf("-l x log to file x\n"); + printf("-L x,y set log level for screen (x) and file (y)\n"); } int main(int argc, char *argv[]) @@ -77,7 +77,9 @@ int main(int argc, char *argv[]) bootloader_t bootloader = BL_NONE; - const char *logfile = nullptr; + const char *logfile = nullptr; + log_level_t ll_screen = none; + log_level_t ll_file = none; int opt = -1; while((opt = getopt(argc, argv, "hm:T:r:R:p:ndtL:b:l:")) != -1) @@ -134,8 +136,15 @@ int main(int argc, char *argv[]) c->setRegister(7, atoi(optarg)); break; - case 'L': - loadbin(b, c->getRegister(7), optarg); + case 'L': { + auto parts = split(optarg, ","); + + if (parts.size() != 2) + error_exit(false, "Argument missing for -L"); + + ll_screen = parse_ll(parts[0]); + ll_file = parse_ll(parts[1]); + } break; case 'l': @@ -150,7 +159,7 @@ int main(int argc, char *argv[]) console *cnsl = nullptr; - setlog(logfile, logfile ? ((tracing || run_debugger) ? debug : info) : ll_error, ll_error); + setlog(logfile, ll_file, ll_screen); std::atomic_bool interrupt_emulation { false };