Configurable log levels

This commit is contained in:
folkert van heusden 2022-06-11 12:46:09 +02:00
parent d8e8111d8a
commit 99c7398a57
3 changed files with 41 additions and 7 deletions

21
log.cpp
View file

@ -100,3 +100,24 @@ void dolog(const log_level_t ll, const char *fmt, ...)
free(ts_str); 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;
}

8
log.h
View file

@ -1,5 +1,9 @@
typedef enum { debug, info, warning, ll_error } log_level_t; // TODO ll_ prefix #include <string>
//
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 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 setloguid(const int uid, const int gid);
void closelog(); void closelog();

View file

@ -47,12 +47,12 @@ void help()
printf("-T t.bin load file as a binary tape file (like simh \"load\" command)\n"); 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("-R d.rk load file as a RK05 disk device\n");
printf("-p 123 set CPU start pointer to decimal(!) value\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("-b x enable bootloader (build-in), parameter must be \"rk05\" or \"rl02\"\n");
printf("-n ncurses UI\n"); printf("-n ncurses UI\n");
printf("-d enable debugger\n"); printf("-d enable debugger\n");
printf("-t enable tracing (disassemble to stderr, requires -d as well)\n"); printf("-t enable tracing (disassemble to stderr, requires -d as well)\n");
printf("-l x log to file x\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[]) int main(int argc, char *argv[])
@ -78,6 +78,8 @@ int main(int argc, char *argv[])
bootloader_t bootloader = BL_NONE; 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; int opt = -1;
while((opt = getopt(argc, argv, "hm:T:r:R:p:ndtL:b:l:")) != -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)); c->setRegister(7, atoi(optarg));
break; break;
case 'L': case 'L': {
loadbin(b, c->getRegister(7), optarg); 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; break;
case 'l': case 'l':
@ -150,7 +159,7 @@ int main(int argc, char *argv[])
console *cnsl = nullptr; 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 }; std::atomic_bool interrupt_emulation { false };