Skip to content

Commit

Permalink
Enhanced logging: Show Loglevel
Browse files Browse the repository at this point in the history
  • Loading branch information
tueddy committed Oct 21, 2023
1 parent efd1ea6 commit 16176e8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## DEV-branch

* 21.10.2023: Enhanced logging: Show Loglevel
* 14.10.2023: New define NO_SDCARD, enable to start without any SD card, e.g. for a webplayer only.
* 05.10.2023: Enable "Arduino as component" by default
* 02.10.2023: Optimize Arduino as component (Disable BLE, BT-HFP & SPI ethernet)
Expand Down
2 changes: 2 additions & 0 deletions html/management.html
Original file line number Diff line number Diff line change
Expand Up @@ -2050,11 +2050,13 @@ <h5 class="modal-title" data-i18n="tools.nvserase.title"></h5>
hslastwaitforstate: info.hallsensor.lastWaitState, hswaited: info.hallsensor.lastWaitMS}) + "\n";
}
$('#modalInfoContent').text(content);
$("#modalInfoContent").css("font-family","inherit");
}

async function fetchLog() {
let logtext = await (await fetch("/log")).text();
$('#modalInfoContent').text(logtext);
$("#modalInfoContent").css("font-family","monospace");
}

$(document).ready(function () {
Expand Down
30 changes: 21 additions & 9 deletions src/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ void Log_Init(void){
Log_RingBuffer = new LogRingBuffer();
}

String getLoglevel(const uint8_t logLevel) {
switch (logLevel) {
case LOGLEVEL_ERROR:
return "E";
case LOGLEVEL_NOTICE:
return "N";
case LOGLEVEL_INFO:
return "I";
case LOGLEVEL_DEBUG:
return "D";
default:
return " ";
}
}

/* Wrapper-function for serial-logging (with newline)
_logBuffer: char* to log
_minLogLevel: loglevel configured for this message.
Expand All @@ -19,11 +34,10 @@ void Log_Init(void){
void Log_Println(const char *_logBuffer, const uint8_t _minLogLevel) {
if (SERIAL_LOGLEVEL >= _minLogLevel) {
uint32_t ctime = millis();
Serial.printf("[ %u ] ", ctime);
static String sLogLevel = getLoglevel(_minLogLevel);
Serial.printf("%s [%u] ", sLogLevel.c_str(), ctime);
Serial.println(_logBuffer);
Log_RingBuffer->print("[ ");
Log_RingBuffer->print(ctime);
Log_RingBuffer->print(" ] ");
Log_RingBuffer->printf("%s [%u] ", sLogLevel.c_str(), ctime);
Log_RingBuffer->println(_logBuffer);
}
}
Expand All @@ -33,14 +47,12 @@ void Log_Print(const char *_logBuffer, const uint8_t _minLogLevel, bool printTim
if (SERIAL_LOGLEVEL >= _minLogLevel) {
if (printTimestamp) {
uint32_t ctime = millis();
Serial.printf("[ %u ] ", ctime);
static String sLogLevel = getLoglevel(_minLogLevel);
Serial.printf("%s [%u] ", sLogLevel.c_str(), ctime);
Serial.print(_logBuffer);
Log_RingBuffer->print("[ ");
Log_RingBuffer->print(ctime);
Log_RingBuffer->print(" ] ");
Log_RingBuffer->printf("%s [%u] ", sLogLevel.c_str(), ctime);
} else {
Serial.print(_logBuffer);

}
Log_RingBuffer->print(_logBuffer);
}
Expand Down
2 changes: 1 addition & 1 deletion src/revision.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once

#include "gitrevision.h"
constexpr const char softwareRevision[] = "Software-revision: 20231021-1";
constexpr const char softwareRevision[] = "Software-revision: 20231021-2";

0 comments on commit 16176e8

Please sign in to comment.