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