log to ncurses console
This commit is contained in:
parent
51e377284c
commit
317ed0abb6
3 changed files with 34 additions and 8 deletions
26
log.cpp
26
log.cpp
|
@ -17,6 +17,7 @@
|
|||
#endif
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "console.h"
|
||||
#include "error.h"
|
||||
#include "log.h"
|
||||
#include "utils.h"
|
||||
|
@ -40,6 +41,7 @@ bool log_trace_enabled = false;
|
|||
#if defined(ESP32)
|
||||
static ntp *ntp_clock = nullptr;
|
||||
#endif
|
||||
static console *log_cnsl = nullptr;
|
||||
|
||||
#if defined(ESP32)
|
||||
int gettid()
|
||||
|
@ -55,6 +57,11 @@ void set_clock_reference(ntp *const ntp_)
|
|||
}
|
||||
#endif
|
||||
|
||||
void set_terminal(console *const cnsl)
|
||||
{
|
||||
log_cnsl = cnsl;
|
||||
}
|
||||
|
||||
void settrace(const bool on)
|
||||
{
|
||||
log_trace_enabled = on;
|
||||
|
@ -198,8 +205,15 @@ void dolog(const log_level_t ll, const char *fmt, ...)
|
|||
fprintf(log_fh, "%s%s\n", ts_str, log_buffer);
|
||||
#endif
|
||||
|
||||
if (ll <= log_level_screen)
|
||||
printf("%s%s\r\n", ts_str, log_buffer);
|
||||
if (ll <= log_level_screen) {
|
||||
if (log_cnsl) {
|
||||
log_cnsl->put_string(ts_str);
|
||||
log_cnsl->put_string_lf(log_buffer);
|
||||
}
|
||||
else {
|
||||
printf("%s%s\r\n", ts_str, log_buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (ll <= log_level_file && is_file == false)
|
||||
|
@ -209,8 +223,12 @@ void dolog(const log_level_t ll, const char *fmt, ...)
|
|||
fprintf(log_fh, "%s\n", log_buffer);
|
||||
#endif
|
||||
|
||||
if (ll <= log_level_screen)
|
||||
printf("%s\r\n", log_buffer);
|
||||
if (ll <= log_level_screen) {
|
||||
if (log_cnsl)
|
||||
log_cnsl->put_string_lf(log_buffer);
|
||||
else
|
||||
printf("%s\r\n", log_buffer);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
3
log.h
3
log.h
|
@ -11,6 +11,8 @@
|
|||
#endif
|
||||
|
||||
|
||||
class console;
|
||||
|
||||
typedef enum { ll_emerg = 0, ll_alert, ll_critical, ll_error, warning, notice, info, debug, none } log_level_t; // TODO ll_ prefix
|
||||
|
||||
log_level_t parse_ll(const std::string & str);
|
||||
|
@ -26,6 +28,7 @@ bool gettrace();
|
|||
#if defined(ESP32)
|
||||
void set_clock_reference(ntp *const ntp_);
|
||||
#endif
|
||||
void set_terminal(console *const cnsl);
|
||||
|
||||
#ifdef TURBO
|
||||
#define DOLOG(ll, always, fmt, ...) do { } while(0)
|
||||
|
|
13
main.cpp
13
main.cpp
|
@ -508,12 +508,17 @@ int main(int argc, char *argv[])
|
|||
|
||||
start_disk_devices(rl02_files, disk_snapshots);
|
||||
|
||||
#if !defined(_WIN32)
|
||||
if (withUI)
|
||||
#if defined(_WIN32)
|
||||
cnsl = new console_posix(&event);
|
||||
#else
|
||||
if (withUI) {
|
||||
cnsl = new console_ncurses(&event);
|
||||
else
|
||||
#endif
|
||||
set_terminal(cnsl);
|
||||
}
|
||||
else {
|
||||
cnsl = new console_posix(&event);
|
||||
}
|
||||
#endif
|
||||
|
||||
bus *b = nullptr;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue