Skip to content

Commit

Permalink
Arduino compliancy (#9)
Browse files Browse the repository at this point in the history
* Cleanup merge mess, renamed files

* Renamed files

* Update keywords

* Update arduino-lint.yml to work only on PRs
  • Loading branch information
jibrilsharafi authored May 12, 2024
1 parent c04139a commit ea7fbaa
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 190 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/arduino-lint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
on: [push, pull_request]
on: pull_request
jobs:
lint:
runs-on: ubuntu-latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This file provides a simple example to show how to use the AdvancedLogger library.
*
* Author: Jibril Sharafi, @jibrilsharafi
* Date: 12/05/2024
* Date: 07/04/2024
* GitHub repository: https://github.com/jibrilsharafi/AdvancedLogger
*
* This library is licensed under the MIT License. See the LICENSE file for more information.
Expand Down Expand Up @@ -32,15 +32,11 @@
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>

#include "advancedLogger.h"
#include "AdvancedLogger.h"

String customLogPath = "/customPath/log.txt";
String customConfigPath = "/customPath/config.txt";

AdvancedLogger logger(customLogPath.c_str(), customConfigPath.c_str()); // Leave empty for default paths
String customLogPath = "/customPath/log.txt";
String customConfigPath = "/customPath/config.txt";

AdvancedLogger logger(customLogPath.c_str(), customConfigPath.c_str()); // Leave empty for default paths

AsyncWebServer server(80);
Expand All @@ -54,15 +50,7 @@ const long intervalLogDump = 10000;
long lastMillisLogClear = 0;
const long intervalLogClear = 30000;

int maxLogLines = 10; // Low value for testing purposes

long lastMillisLogDump = 0;
const long intervalLogDump = 10000;

long lastMillisLogClear = 0;
const long intervalLogClear = 30000;

int maxLogLines = 10; // Low value for testing purposes
int maxLogLines = 100; // Low value for testing purposes

// **** CHANGE THESE TO YOUR SSID AND PASSWORD ****
const char *ssid = "YOUR_SSID";
Expand Down Expand Up @@ -90,9 +78,6 @@ void setup()
// Set the maximum number of log lines before the log is cleared
// If you don't set this, the default is used
logger.setMaxLogLines(maxLogLines);
// Set the maximum number of log lines before the log is cleared
// If you don't set this, the default is used
logger.setMaxLogLines(maxLogLines);
logger.log("AdvancedLogger setup done!", "basicServer::setup", ADVANCEDLOGGER_INFO);

// Connect to WiFi
Expand All @@ -111,15 +96,11 @@ void setup()
{ request->send(200, "text/html", "<button onclick=\"window.location.href='/log'\">Explore the logs</button><br><br><button onclick=\"window.location.href='/config'\">Explore the configuration</button>"); });
server.serveStatic("/log", SPIFFS, customLogPath.c_str());
server.serveStatic("/config", SPIFFS, customConfigPath.c_str());
server.serveStatic("/log", SPIFFS, customLogPath.c_str());
server.serveStatic("/config", SPIFFS, customConfigPath.c_str());
server.onNotFound([](AsyncWebServerRequest *request)
{ request->send(404, "text/plain", "Not found"); });
server.begin();
logger.log("Server started!", "basicServer::setup", ADVANCEDLOGGER_INFO);

lastMillisLogDump = millis();
lastMillisLogClear = millis();
lastMillisLogDump = millis();
lastMillisLogClear = millis();
logger.log("Setup done!", "basicServer::setup", ADVANCEDLOGGER_INFO);
Expand All @@ -139,7 +120,6 @@ void loop()
delay(500);
logger.logOnly("This is an info message (logOnly)!!", "basicServer::loop", ADVANCEDLOGGER_INFO);
delay(1000);
delay(1000);

printLevel = logger.getPrintLevel();
saveLevel = logger.getSaveLevel();
Expand All @@ -152,20 +132,7 @@ void loop()
}

if (millis() - lastMillisLogClear > intervalLogClear)
if (millis() - lastMillisLogDump > intervalLogDump)
{
logger.dumpToSerial();

lastMillisLogDump = millis();
}

if (millis() - lastMillisLogClear > intervalLogClear)
{
logger.log(
("Current number of log lines: " + String(logger.getLogLines())).c_str(),
"basicServer::loop",
ADVANCEDLOGGER_INFO
);
logger.log(
("Current number of log lines: " + String(logger.getLogLines())).c_str(),
"basicServer::loop",
Expand All @@ -176,7 +143,5 @@ void loop()
logger.log("Log cleared!", "basicServer::loop", ADVANCEDLOGGER_WARNING);

lastMillisLogClear = millis();

lastMillisLogClear = millis();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <Arduino.h>
#include <SPIFFS.h>

#include "advancedLogger.h"
#include "AdvancedLogger.h"

String customLogPath = "/customPath/log.txt";
String customConfigPath = "/customPath/config.txt";
Expand Down
13 changes: 11 additions & 2 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ setSaveLevel KEYWORD2
getPrintLevel KEYWORD2
getSaveLevel KEYWORD2
setDefaultLogLevels KEYWORD2
setLogLevelsFromSpiffs KEYWORD2
setMaxLogLines KEYWORD2
getLogLines KEYWORD2
clearLog KEYWORD2
dumpToSerial KEYWORD2

####################################################################################################
# AdvancedLogger constants
Expand All @@ -28,4 +30,11 @@ ADVANCEDLOGGER_DEBUG LITERAL1
ADVANCEDLOGGER_INFO LITERAL1
ADVANCEDLOGGER_WARNING LITERAL1
ADVANCEDLOGGER_ERROR LITERAL1
ADVANCEDLOGGER_FATAL LITERAL1
ADVANCEDLOGGER_FATAL LITERAL1
ADVANCEDLOGGER_DEFAULT_PRINT_LEVEL LITERAL1
ADVANCEDLOGGER_DEFAULT_SAVE_LEVEL LITERAL1
ADVANCEDLOGGER_DEFAULT_MAX_LOG_LINES LITERAL1
ADVANCEDLOGGER_TIMESTAMP_FORMAT LITERAL1
ADVANCEDLOGGER_FORMAT LITERAL1
ADVANCEDLOGGER_LOG_PATH LITERAL1
ADVANCEDLOGGER_CONFIG_PATH LITERAL1
Loading

0 comments on commit ea7fbaa

Please sign in to comment.