mirror of
https://github.com/Laxilef/OTGateway.git
synced 2025-12-10 18:24:27 +05:00
feat: added log level setting
This commit is contained in:
@@ -37,7 +37,7 @@ build_flags =
|
||||
-D BUILD_ENV='"$PIOENV"'
|
||||
-D USE_SERIAL=${secrets.use_serial}
|
||||
-D USE_TELNET=${secrets.use_telnet}
|
||||
-D DEBUG_BY_DEFAULT=${secrets.debug}
|
||||
-D DEFAULT_LOG_LEVEL=${secrets.log_level}
|
||||
-D DEFAULT_HOSTNAME='"${secrets.hostname}"'
|
||||
-D DEFAULT_AP_SSID='"${secrets.ap_ssid}"'
|
||||
-D DEFAULT_AP_PASSWORD='"${secrets.ap_password}"'
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[secrets]
|
||||
use_serial = true
|
||||
use_telnet = true
|
||||
debug = true
|
||||
log_level = 5
|
||||
hostname = opentherm
|
||||
|
||||
ap_ssid = OpenTherm Gateway
|
||||
|
||||
@@ -99,11 +99,10 @@ protected:
|
||||
tMqtt->disable();
|
||||
}
|
||||
|
||||
if ( Log.getLevel() != TinyLogger::Level::INFO && !settings.system.debug ) {
|
||||
Log.setLevel(TinyLogger::Level::INFO);
|
||||
|
||||
} else if ( Log.getLevel() != TinyLogger::Level::VERBOSE && settings.system.debug ) {
|
||||
Log.setLevel(TinyLogger::Level::VERBOSE);
|
||||
if (settings.system.logLevel >= TinyLogger::Level::SILENT && settings.system.logLevel <= TinyLogger::Level::VERBOSE) {
|
||||
if (Log.getLevel() != settings.system.logLevel) {
|
||||
Log.setLevel(static_cast<TinyLogger::Level>(settings.system.logLevel));
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -160,7 +159,7 @@ protected:
|
||||
this->restartSignalTime = millis();
|
||||
}
|
||||
|
||||
if (!settings.system.debug) {
|
||||
if (settings.system.logLevel < TinyLogger::Level::VERBOSE) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -270,7 +270,7 @@ protected:
|
||||
return;
|
||||
}
|
||||
|
||||
if (settings.system.debug) {
|
||||
if (settings.system.logLevel >= TinyLogger::Level::TRACE) {
|
||||
Log.strace(FPSTR(L_MQTT_MSG), F("Topic: %s\r\n> "), topic);
|
||||
if (Log.lock()) {
|
||||
for (size_t i = 0; i < length; i++) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#define PORTAL_CACHE_TIME "max-age=86400"
|
||||
#define PORTAL_CACHE settings.system.debug ? nullptr : PORTAL_CACHE_TIME
|
||||
#define PORTAL_CACHE (settings.system.logLevel >= TinyLogger::Level::TRACE ? nullptr : PORTAL_CACHE_TIME)
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <Updater.h>
|
||||
|
||||
@@ -24,7 +24,7 @@ struct NetworkSettings {
|
||||
|
||||
struct Settings {
|
||||
struct {
|
||||
bool debug = DEBUG_BY_DEFAULT;
|
||||
uint8_t logLevel = DEFAULT_LOG_LEVEL;
|
||||
|
||||
struct {
|
||||
bool enable = USE_SERIAL;
|
||||
|
||||
@@ -62,8 +62,8 @@
|
||||
#define DEFAULT_STA_PASSWORD ""
|
||||
#endif
|
||||
|
||||
#ifndef DEBUG_BY_DEFAULT
|
||||
#define DEBUG_BY_DEFAULT false
|
||||
#ifndef DEFAULT_LOG_LEVEL
|
||||
#define DEFAULT_LOG_LEVEL TinyLogger::Level::VERBOSE
|
||||
#endif
|
||||
|
||||
#ifndef DEFAULT_STATUS_LED_GPIO
|
||||
|
||||
@@ -129,7 +129,9 @@ void setup() {
|
||||
Log.addStream(telnetStream);
|
||||
}
|
||||
|
||||
Log.setLevel(settings.system.debug ? TinyLogger::Level::VERBOSE : TinyLogger::Level::INFO);
|
||||
if (settings.system.logLevel >= TinyLogger::Level::SILENT && settings.system.logLevel <= TinyLogger::Level::VERBOSE) {
|
||||
Log.setLevel(static_cast<TinyLogger::Level>(settings.system.logLevel));
|
||||
}
|
||||
|
||||
// network
|
||||
network = (new NetworkMgr)
|
||||
|
||||
10
src/utils.h
10
src/utils.h
@@ -326,7 +326,7 @@ bool jsonToNetworkSettings(const JsonVariantConst src, NetworkSettings& dst) {
|
||||
|
||||
void settingsToJson(const Settings& src, JsonVariant dst, bool safe = false) {
|
||||
if (!safe) {
|
||||
dst["system"]["debug"] = src.system.debug;
|
||||
dst["system"]["logLevel"] = static_cast<uint8_t>(src.system.logLevel);
|
||||
dst["system"]["serial"]["enable"] = src.system.serial.enable;
|
||||
dst["system"]["serial"]["baudrate"] = src.system.serial.baudrate;
|
||||
dst["system"]["telnet"]["enable"] = src.system.telnet.enable;
|
||||
@@ -459,11 +459,11 @@ bool jsonToSettings(const JsonVariantConst src, Settings& dst, bool safe = false
|
||||
|
||||
if (!safe) {
|
||||
// system
|
||||
if (src["system"]["debug"].is<bool>()) {
|
||||
bool value = src["system"]["debug"].as<bool>();
|
||||
if (!src["system"]["logLevel"].isNull()) {
|
||||
uint8_t value = src["system"]["logLevel"].as<uint8_t>();
|
||||
|
||||
if (value != dst.system.debug) {
|
||||
dst.system.debug = value;
|
||||
if (value != dst.system.logLevel && value >= TinyLogger::Level::SILENT && value <= TinyLogger::Level::VERBOSE) {
|
||||
dst.system.logLevel = value;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,13 +198,10 @@
|
||||
"metric": "Metric <small>(celsius, liters, bar)</small>",
|
||||
"imperial": "Imperial <small>(fahrenheit, gallons, psi)</small>",
|
||||
"statusLedGpio": "Status LED GPIO",
|
||||
"debug": "Debug mode",
|
||||
"logLevel": "Log level",
|
||||
"serial": {
|
||||
"enable": "Enable Serial port",
|
||||
"baud": {
|
||||
"title": "Serial port baud rate",
|
||||
"note": "Available: 9600, 19200, 38400, 57600, 74880, 115200"
|
||||
}
|
||||
"baud": "Serial port baud rate"
|
||||
},
|
||||
"telnet": {
|
||||
"enable": "Enable Telnet",
|
||||
|
||||
@@ -198,13 +198,10 @@
|
||||
"metric": "Метрическая <small>(цильсии, литры, бары)</small>",
|
||||
"imperial": "Imperial <small>(фаренгейты, галлоны, psi)</small>",
|
||||
"statusLedGpio": "Статус LED GPIO",
|
||||
"debug": "Отладка",
|
||||
"logLevel": "Уровень логирования",
|
||||
"serial": {
|
||||
"enable": "Вкл. Serial порт",
|
||||
"baud": {
|
||||
"title": "Скорость Serial порта",
|
||||
"note": "Доступно: 9600, 19200, 38400, 57600, 74880, 115200"
|
||||
}
|
||||
"baud": "Скорость Serial порта"
|
||||
},
|
||||
"telnet": {
|
||||
"enable": "Вкл. Telnet",
|
||||
|
||||
@@ -94,11 +94,6 @@
|
||||
<fieldset>
|
||||
<legend data-i18n>settings.section.diag</legend>
|
||||
|
||||
<label for="system-debug">
|
||||
<input type="checkbox" id="system-debug" name="system[debug]" value="true">
|
||||
<span data-i18n>settings.system.debug</span>
|
||||
</label>
|
||||
|
||||
<label for="system-serial-enable">
|
||||
<input type="checkbox" id="system-serial-enable" name="system[serial][enable]" value="true">
|
||||
<span data-i18n>settings.system.serial.enable</span>
|
||||
@@ -109,11 +104,31 @@
|
||||
<span data-i18n>settings.system.telnet.enable</span>
|
||||
</label>
|
||||
|
||||
<label for="system-log-level">
|
||||
<span data-i18n>settings.system.logLevel</span>
|
||||
<select id="system-log-level" name="system[logLevel]">
|
||||
<option value="0">SILENT</option>
|
||||
<option value="1">FATAL</option>
|
||||
<option value="2">ERROR</option>
|
||||
<option value="3">WARNING</option>
|
||||
<option value="4">INFO</option>
|
||||
<option value="5">NOTICE</option>
|
||||
<option value="6">TRACE</option>
|
||||
<option value="7">VERBOSE</option>
|
||||
</select>
|
||||
</label>
|
||||
|
||||
<div class="grid">
|
||||
<label for="system-serial-baudrate">
|
||||
<span data-i18n>settings.system.serial.baud.title</span>
|
||||
<input type="number" inputmode="numeric" id="system-serial-baudrate" name="system[serial][baudrate]" min="9600" max="115200" step="1" required>
|
||||
<small data-i18n>settings.system.serial.baud.note</small>
|
||||
<span data-i18n>settings.system.serial.baud</span>
|
||||
<select id="system-serial-baudrate" name="system[serial][baudrate]" required>
|
||||
<option value="9600">9600</option>
|
||||
<option value="19200">19200</option>
|
||||
<option value="38400">38400</option>
|
||||
<option value="57600">57600</option>
|
||||
<option value="74880">74880</option>
|
||||
<option value="115200">115200</option>
|
||||
</select>
|
||||
</label>
|
||||
|
||||
<label for="system-telnet-port">
|
||||
@@ -757,9 +772,9 @@
|
||||
|
||||
const fillData = (data) => {
|
||||
// System
|
||||
setCheckboxValue('#system-debug', data.system.debug);
|
||||
setSelectValue('#system-log-level', data.system.logLevel);
|
||||
setCheckboxValue('#system-serial-enable', data.system.serial.enable);
|
||||
setInputValue('#system-serial-baudrate', data.system.serial.baudrate);
|
||||
setSelectValue('#system-serial-baudrate', data.system.serial.baudrate);
|
||||
setCheckboxValue('#system-telnet-enable', data.system.telnet.enable);
|
||||
setInputValue('#system-telnet-port', data.system.telnet.port);
|
||||
setRadioValue('.system-unit-system', data.system.unitSystem);
|
||||
|
||||
@@ -539,6 +539,17 @@ function setInputValue(selector, value, attrs = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
function setSelectValue(selector, value) {
|
||||
let item = document.querySelector(selector);
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (let option of item.options) {
|
||||
option.selected = option.value == value;
|
||||
}
|
||||
}
|
||||
|
||||
function show(selector) {
|
||||
let items = document.querySelectorAll(selector);
|
||||
if (!items.length) {
|
||||
|
||||
Reference in New Issue
Block a user