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