polymech - fw latest | web ui

This commit is contained in:
2026-04-18 10:31:24 +02:00
parent a105c5ee85
commit ab2ff368a6
2972 changed files with 441416 additions and 372 deletions
+266
View File
@@ -0,0 +1,266 @@
/*
_ ___ ___ _ _ ___ _ _ ___ _ ___ ___
/_\ | _ \ \| | | |_ _| \| |/ _ \| | / _ \ / __|
/ _ \| / |) | |_| || || .` | (_) | |_| (_) | (_ |
/_/ \_\_|_\___/ \___/|___|_|\_|\___/|____\___/ \___|
Log library for Arduino
version 1.1.1
https://github.com/thijse/Arduino-Log
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "ArduinoLog.h"
void Logging::begin(int level, Print* logOutput, bool showLevel)
{
#ifndef DISABLE_LOGGING
setLevel(level);
setShowLevel(showLevel);
_logOutput = logOutput;
#endif
}
void Logging::setLevel(int level)
{
#ifndef DISABLE_LOGGING
_level = constrain(level, LOG_LEVEL_SILENT, LOG_LEVEL_VERBOSE);
#endif
}
int Logging::getLevel() const
{
#ifndef DISABLE_LOGGING
return _level;
#else
return 0;
#endif
}
void Logging::setShowLevel(bool showLevel)
{
#ifndef DISABLE_LOGGING
_showLevel = showLevel;
#endif
}
bool Logging::getShowLevel() const
{
#ifndef DISABLE_LOGGING
return _showLevel;
#else
return false;
#endif
}
void Logging::setPrefix(printfunction f)
{
#ifndef DISABLE_LOGGING
_prefix = f;
#endif
}
void Logging::clearPrefix()
{
#ifndef DISABLE_LOGGING
_prefix = nullptr;
#endif
}
void Logging::setSuffix(printfunction f)
{
#ifndef DISABLE_LOGGING
_suffix = f;
#endif
}
void Logging::clearSuffix()
{
#ifndef DISABLE_LOGGING
_prefix = nullptr;
#endif
}
void Logging::print(const __FlashStringHelper *format, va_list args)
{
#ifndef DISABLE_LOGGING
PGM_P p = reinterpret_cast<PGM_P>(format);
// This copy is only necessary on some architectures (x86) to change a passed
// array in to a va_list.
#ifdef __x86_64__
va_list args_copy;
va_copy(args_copy, args);
#endif
char c = pgm_read_byte(p++);
for(;c != 0; c = pgm_read_byte(p++))
{
if (c == '%')
{
c = pgm_read_byte(p++);
#ifdef __x86_64__
printFormat(c, &args_copy);
#else
printFormat(c, &args);
#endif
}
else
{
_logOutput->print(c);
}
}
#ifdef __x86_64__
va_end(args_copy);
#endif
#endif
}
void Logging::print(const char *format, va_list args) {
#ifndef DISABLE_LOGGING
// This copy is only necessary on some architectures (x86) to change a passed
// array in to a va_list.
#ifdef __x86_64__
va_list args_copy;
va_copy(args_copy, args);
#endif
for (; *format != 0; ++format)
{
if (*format == '%')
{
++format;
#ifdef __x86_64__
printFormat(*format, &args_copy);
#else
printFormat(*format, &args);
#endif
}
else
{
_logOutput->print(*format);
}
}
#ifdef __x86_64__
va_end(args_copy);
#endif
#endif
}
void Logging::printFormat(const char format, va_list *args) {
#ifndef DISABLE_LOGGING
if (format == '\0') return;
if (format == '%')
{
_logOutput->print(format);
}
else if (format == 's')
{
register char *s = (char *)va_arg(*args, int);
_logOutput->print(s);
}
else if (format == 'S')
{
register __FlashStringHelper *s = (__FlashStringHelper *)va_arg(*args, int);
_logOutput->print(s);
}
else if (format == 'd' || format == 'i')
{
_logOutput->print(va_arg(*args, int), DEC);
}
else if (format == 'D' || format == 'F')
{
_logOutput->print(va_arg(*args, double));
}
else if (format == 'x')
{
_logOutput->print(va_arg(*args, int), HEX);
}
else if (format == 'X')
{
_logOutput->print("0x");
//_logOutput->print(va_arg(*args, int), HEX);
register uint16_t h = (uint16_t) va_arg( *args, int );
if (h<0xFFF) _logOutput->print('0');
if (h<0xFF ) _logOutput->print('0');
if (h<0xF ) _logOutput->print('0');
_logOutput->print(h,HEX);
}
else if (format == 'p')
{
register Printable *obj = (Printable *) va_arg(*args, int);
_logOutput->print(*obj);
}
else if (format == 'b')
{
_logOutput->print(va_arg(*args, int), BIN);
}
else if (format == 'B')
{
_logOutput->print("0b");
_logOutput->print(va_arg(*args, int), BIN);
}
else if (format == 'l')
{
_logOutput->print(va_arg(*args, long), DEC);
}
else if (format == 'u')
{
_logOutput->print(va_arg(*args, unsigned long), DEC);
}
else if (format == 'c')
{
_logOutput->print((char) va_arg(*args, int));
}
else if( format == 'C' ) {
register char c = (char) va_arg( *args, int );
if (c>=0x20 && c<0x7F) {
_logOutput->print(c);
} else {
_logOutput->print("0x");
if (c<0xF) _logOutput->print('0');
_logOutput->print(c, HEX);
}
}
else if(format == 't')
{
if (va_arg(*args, int) == 1)
{
_logOutput->print("T");
}
else
{
_logOutput->print("F");
}
}
else if (format == 'T')
{
if (va_arg(*args, int) == 1)
{
_logOutput->print(F("true"));
}
else
{
_logOutput->print(F("false"));
}
}
#endif
}
Logging Log = Logging();
+385
View File
@@ -0,0 +1,385 @@
/*
_ ___ ___ _ _ ___ _ _ ___ _ ___ ___
/_\ | _ \ \| | | |_ _| \| |/ _ \| | / _ \ / __|
/ _ \| / |) | |_| || || .` | (_) | |_| (_) | (_ |
/_/ \_\_|_\___/ \___/|___|_|\_|\___/|____\___/ \___|
Log library for Arduino
version 1.1.1
https://github.com/thijse/Arduino-Log
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
*/
#pragma once
#include <inttypes.h>
#include <stdarg.h>
// Non standard: Arduino.h also chosen if ARDUINO is not defined. To facilitate use in non-Arduino test environments
#if ARDUINO < 100
#include "WProgram.h"
#else
#include "Arduino.h"
#endif
// PGM stubs to facilitate use in non-Arduino test environments
#ifndef PGM_P
#define PGM_P const char *
#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
#define PSTR(str) (str)
#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))
#endif
typedef void (*printfunction)(Print*, int);
// *************************************************************************
// Uncomment line below to fully disable logging, and reduce project size
// ************************************************************************
//#define DISABLE_LOGGING
#define LOG_LEVEL_SILENT 0
#define LOG_LEVEL_FATAL 1
#define LOG_LEVEL_ERROR 2
#define LOG_LEVEL_WARNING 3
#define LOG_LEVEL_INFO 4
#define LOG_LEVEL_NOTICE 4
#define LOG_LEVEL_TRACE 5
#define LOG_LEVEL_VERBOSE 6
#define CR "\n"
#define LF "\r"
#define NL "\n\r"
#define LOGGING_VERSION 1_0_4
/**
* ArduinoLog is a minimalistic framework to help the programmer output log statements to an output of choice,
* fashioned after extensive logging libraries such as log4cpp ,log4j and log4net. In case of problems with an
* application, it is helpful to enable logging so that the problem can be located. ArduinoLog is designed so
* that log statements can remain in the code with minimal performance cost. In order to facilitate this the
* loglevel can be adjusted, and (if your code is completely tested) all logging code can be compiled out.
*
* ---- Wildcards
*
* %s display as string (char*)
* %S display as string from flash memory (__FlashStringHelper* or char[] PROGMEM)
* %c display as single character
* %C display as single character or as hexadecimal value (prefixed by `0x`) if not a printable character
* %d display as integer value
* %l display as long value
* %u display as unsigned long value
* %x display as hexadecimal value
* %X display as hexadecimal value prefixed by `0x` and leading zeros
* %b display as binary number
* %B display as binary number, prefixed by `0b`
* %t display as boolean value "t" or "f"
* %T display as boolean value "true" or "false"
* %D,%F display as double value
* %p display a printable object
*
* ---- Loglevels
*
* 0 - LOG_LEVEL_SILENT no output
* 1 - LOG_LEVEL_FATAL fatal errors
* 2 - LOG_LEVEL_ERROR all errors
* 3 - LOG_LEVEL_WARNING errors and warnings
* 4 - LOG_LEVEL_INFO errors, warnings and notices
* 4 - LOG_LEVEL_NOTICE Same as INFO, kept for backward compatibility
* 5 - LOG_LEVEL_TRACE errors, warnings, notices, traces
* 6 - LOG_LEVEL_VERBOSE all
*/
class Logging
{
public:
/**
* default Constructor
*/
Logging()
#ifndef DISABLE_LOGGING
: _level(LOG_LEVEL_SILENT),
_showLevel(true),
_logOutput(NULL)
#endif
{
}
/**
* Initializing, must be called as first. Note that if you use
* this variant of Init, you need to initialize the baud rate
* yourself, if printer happens to be a serial port.
*
* \param level - logging levels <= this will be logged.
* \param printer - place that logging output will be sent to.
* \return void
*
*/
void begin(int level, Print *output, bool showLevel = true);
/**
* Set the log level.
*
* \param level - The new log level.
* \return void
*/
void setLevel(int level);
/**
* Get the log level.
*
* \return The current log level.
*/
int getLevel() const;
/**
* Set whether to show the log level.
*
* \param showLevel - true if the log level should be shown for each log
* false otherwise.
* \return void
*/
void setShowLevel(bool showLevel);
/**
* Get whether the log level is shown during logging
*
* \return true if the log level is be shown for each log
* false otherwise.
*/
bool getShowLevel() const;
/**
* Sets a function to be called before each log command.
*
* \param f - The function to be called
* \return void
*/
void setPrefix(printfunction f);
/**
* clears prefix.
*
* \return void
*/
void clearPrefix();
/**
* Sets a function to be called after each log command.
*
* \param f - The function to be called
* \return void
*/
void setSuffix(printfunction f);
/**
* clears suffix.
*
* \return void
*/
void clearSuffix();
/**
* Output a fatal error message. Output message contains
* F: followed by original message
* Fatal error messages are printed out at
* loglevels >= LOG_LEVEL_FATAL
*
* \param msg format string to output
* \param ... any number of variables
* \return void
*/
template <class T, typename... Args> void fatal(T msg, Args... args){
#ifndef DISABLE_LOGGING
printLevel(LOG_LEVEL_FATAL, false, msg, args...);
#endif
}
template <class T, typename... Args> void fatalln(T msg, Args... args){
#ifndef DISABLE_LOGGING
printLevel(LOG_LEVEL_FATAL, true, msg, args...);
#endif
}
/**
* Output an error message. Output message contains
* E: followed by original message
* Error messages are printed out at
* loglevels >= LOG_LEVEL_ERROR
*
* \param msg format string to output
* \param ... any number of variables
* \return void
*/
template <class T, typename... Args> void error(T msg, Args... args){
#ifndef DISABLE_LOGGING
printLevel(LOG_LEVEL_ERROR, false, msg, args...);
#endif
}
template <class T, typename... Args> void errorln(T msg, Args... args){
#ifndef DISABLE_LOGGING
printLevel(LOG_LEVEL_ERROR, true, msg, args...);
#endif
}
/**
* Output a warning message. Output message contains
* W: followed by original message
* Warning messages are printed out at
* loglevels >= LOG_LEVEL_WARNING
*
* \param msg format string to output
* \param ... any number of variables
* \return void
*/
template <class T, typename... Args> void warning(T msg, Args...args){
#ifndef DISABLE_LOGGING
printLevel(LOG_LEVEL_WARNING, false, msg, args...);
#endif
}
template <class T, typename... Args> void warningln(T msg, Args...args){
#ifndef DISABLE_LOGGING
printLevel(LOG_LEVEL_WARNING, true, msg, args...);
#endif
}
/**
* Output a notice message. Output message contains
* N: followed by original message
* Notice messages are printed out at
* loglevels >= LOG_LEVEL_NOTICE
*
* \param msg format string to output
* \param ... any number of variables
* \return void
*/
template <class T, typename... Args> void notice(T msg, Args...args){
#ifndef DISABLE_LOGGING
printLevel(LOG_LEVEL_NOTICE, false, msg, args...);
#endif
}
template <class T, typename... Args> void noticeln(T msg, Args...args){
#ifndef DISABLE_LOGGING
printLevel(LOG_LEVEL_NOTICE, true, msg, args...);
#endif
}
template <class T, typename... Args> void info(T msg, Args...args) {
#ifndef DISABLE_LOGGING
printLevel(LOG_LEVEL_INFO, false, msg, args...);
#endif
}
template <class T, typename... Args> void infoln(T msg, Args...args) {
#ifndef DISABLE_LOGGING
printLevel(LOG_LEVEL_INFO, true, msg, args...);
#endif
}
/**
* Output a trace message. Output message contains
* N: followed by original message
* Trace messages are printed out at
* loglevels >= LOG_LEVEL_TRACE
*
* \param msg format string to output
* \param ... any number of variables
* \return void
*/
template <class T, typename... Args> void trace(T msg, Args... args){
#ifndef DISABLE_LOGGING
printLevel(LOG_LEVEL_TRACE, false, msg, args...);
#endif
}
template <class T, typename... Args> void traceln(T msg, Args... args){
#ifndef DISABLE_LOGGING
printLevel(LOG_LEVEL_TRACE, true, msg, args...);
#endif
}
/**
* Output a verbose message. Output message contains
* V: followed by original message
* Debug messages are printed out at
* loglevels >= LOG_LEVEL_VERBOSE
*
* \param msg format string to output
* \param ... any number of variables
* \return void
*/
template <class T, typename... Args> void verbose(T msg, Args... args){
#ifndef DISABLE_LOGGING
printLevel(LOG_LEVEL_VERBOSE, false, msg, args...);
#endif
}
template <class T, typename... Args> void verboseln(T msg, Args... args){
#ifndef DISABLE_LOGGING
printLevel(LOG_LEVEL_VERBOSE, true, msg, args...);
#endif
}
private:
void print(const char *format, va_list args);
void print(const __FlashStringHelper *format, va_list args);
void print(const Printable& obj, va_list args)
{
_logOutput->print(obj);
}
void printFormat(const char format, va_list *args);
template <class T> void printLevel(int level, bool cr, T msg, ...)
{
#ifndef DISABLE_LOGGING
if (level > _level)
{
return;
}
if (level < LOG_LEVEL_SILENT)
{
level = LOG_LEVEL_SILENT;
}
if (_prefix != NULL)
{
_prefix(_logOutput, level);
}
if (_showLevel) {
static const char levels[] = "FEWITV";
_logOutput->print(levels[level - 1]);
_logOutput->print(": ");
}
va_list args;
va_start(args, msg);
print(msg, args);
if(_suffix != NULL)
{
_suffix(_logOutput, level);
}
if (cr)
{
_logOutput->print(CR);
}
#endif
}
#ifndef DISABLE_LOGGING
int _level;
bool _showLevel;
Print* _logOutput;
printfunction _prefix = NULL;
printfunction _suffix = NULL;
#endif
};
extern Logging Log;
Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

+22
View File
@@ -0,0 +1,22 @@
MIT License
Copyright (c) 2017,2018,2021 Thijs Elenbaas, MrRobot62, rahuldeo2047, NOX73,
dhylands, Josha, blemasle, mfalkvidd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+219
View File
@@ -0,0 +1,219 @@
![ArduinoLog logo](/Images/logo.png?raw=true )
ArduinoLog - C++ Log library for Arduino devices
====================
[![Build Status](https://travis-ci.org/thijse/Arduino-Log.svg?branch=master)](https://travis-ci.org/thijse/Arduino-Log)
[![License](https://img.shields.io/badge/license-MIT%20License-blue.svg)](http://doge.mit-license.org)
*An minimalistic Logging framework for Arduino-compatible embedded systems.*
ArduinoLog is a minimalistic framework to help the programmer output log statements to an output of choice, fashioned after extensive logging libraries such as log4cpp ,log4j and log4net. In case of problems with an application, it is helpful to enable logging so that the problem can be located. ArduinoLog is designed so that log statements can remain in the code with minimal performance cost. In order to facilitate this the loglevel can be adjusted, and (if your code is completely tested) all logging code can be compiled out.
## Features
* Different log levels (Error, Info, Warn, Debug, Verbose )
* Supports multiple variables
* Supports formatted strings
* Supports formatted strings from flash memory
* Fixed memory allocation (zero malloc)
* MIT License
## Tested for
* All Arduino boards (Uno, Due, Mini, Micro, Yun...)
* ESP8266
* ESP32
## Downloading
This package has been published to the Arduino & PlatformIO package managers, but you can also download it from GitHub.
- By directly loading fetching the Archive from GitHub:
1. Go to [https://github.com/thijse/Arduino-Log](https://github.com/thijse/Arduino-Log)
2. Click the DOWNLOAD ZIP button in the panel on the
3. Rename the uncompressed folder **Arduino-Log-master** to **Arduino-Log**.
4. You may need to create the libraries subfolder if its your first library.
5. Place the **Arduino-Log** library folder in your **<arduinosketchfolder>/libraries/** folder.
5. Restart the IDE.
6. For more information, [read this extended manual](http://thijs.elenbaas.net/2012/07/installing-an-arduino-library/)
## Quick start
```c++
Serial.begin(9600);
// Initialize with log level and log output.
Log.begin (LOG_LEVEL_VERBOSE, &Serial);
// Start logging text and formatted values
Log.errorln ( "Log as Error with binary values : %b, %B" , 23 , 345808);
Log.warning (F("Log as Warning with integer values from Flash : %d, %d"CR) , 34 , 799870);
```
See [Log-basic.ino](examples/Log-basic/Log-basic.ino) example
## Usage
### Initialisation
The log library needs to be initialized with the log level of messages to show and the log output. The latter will often be the Serial interface.
Optionally, you can indicate whether to show the log type (error, debug, etc) for each line.
```
begin(int level, Print* logOutput, bool showLevel)
begin(int level, Print* logOutput)
```
The loglevels available are
```
* 0 - LOG_LEVEL_SILENT no output
* 1 - LOG_LEVEL_FATAL fatal errors
* 2 - LOG_LEVEL_ERROR all errors
* 3 - LOG_LEVEL_WARNING errors, and warnings
* 4 - LOG_LEVEL_NOTICE errors, warnings and notices
* 5 - LOG_LEVEL_TRACE errors, warnings, notices & traces
* 6 - LOG_LEVEL_VERBOSE all
```
example
```
Log.begin(LOG_LEVEL_ERROR, &Serial, true);
```
if you want to fully remove all logging code, uncomment `#define DISABLE_LOGGING` in `ArduinoLog.h`, this may significantly reduce your sketch/library size.
### Log events
The library allows you to log on different levels by the following functions
```c++
void fatal (const char *format, va_list logVariables);
void error (const char *format, va_list logVariables);
void warning (const char *format, va_list logVariables);
void notice (const char *format, va_list logVariables);
void trace (const char *format, va_list logVariables);
void verbose (const char *format, va_list logVariables);
```
where the format string can be used to format the log variables
```
* %s display as string (char*)
* %S display as string from flash memory (__FlashStringHelper* or char[] PROGMEM)
* %c display as single character
* %C display as single character or as hexadecimal value (prefixed by `0x`) if not a printable character
* %d display as integer value
* %l display as long value
* %u display as unsigned long value
* %x display as hexadecimal value
* %X display as hexadecimal value prefixed by `0x` and leading zeros
* %b display as binary number
* %B display as binary number, prefixed by `0b`
* %t display as boolean value "t" or "f"
* %T display as boolean value "true" or "false"
* %D,%F display as double value
* %p display a printable object
```
Newlines can be added using the `CR` keyword or by using the `...ln` version of each of the log functions. The difference when using the `...ln` is that the newline is placed after suffix, and only a single newline can be added. Some terminals prefer `NL` (New line).
### Examples
```c++
Log.fatal (F("Log as Fatal with string value from Flash : %s"CR ) , "value" );
Log.errorln ( "Log as Error with binary values : %b, %B" , 23 , 345808);
Log.warning (F("Log as Warning with integer values from Flash : %d, %d"CR) , 34 , 799870);
Log.notice ( "Log as Notice with hexadecimal values : %x, %X"CR , 21 , 348972);
Log.trace ( "Log as Trace with Flash string : %S"CR ) , F("value") );
Log.verboseln (F("Log as Verbose with bool value from Flash : %t, %T" ) , true, false );
```
### Disable library
(if your code is completely tested) all logging code can be compiled out. Do this by uncommenting
```c++
#define DISABLE_LOGGING
```
in `Logging.h`. This may significantly reduce your project size.
## Advanced usage
Advanced features are demonstrated in [Log-advanced](examples/Log-advanced/Log-advanced.ino) example.
### Displaying a printable object
Some Arduino objects are printable. That is, they implement the `Printable` interface and are able for format their own representation
As an example, the IPadress object is printable:
```c++
IPAddress ipAddress(192, 168, 0, 1);
Log.verboseln ("ip address : %p", ipAddress);
```
[this example](https://forum.arduino.cc/t/printable-classes/438816) shows how to make your own classes printable
### Storing messages in Flash memory
Flash strings log variables can be stored and reused at several places to reduce final hex size.
```c++
const __FlashStringHelper * logAs = F("Log as");
Log.fatal (F("%S Fatal with string value from Flash : %s"CR ) , logAs, "value" );
Log.error ( "%S Error with binary values : %b, %B"CR , logAs, 23 , 345808);
```
If you want to declare that string globally (outside of a function), you will need to use the PROGMEM macro instead.
```c++
const char LOG_AS[] PROGMEM = "Log as ";
void logError() {
Log.error ( "%S Error with binary values : %b, %B"CR , PSTRPTR(LOG_AS), 23 , 345808);
}
```
### Custom logging format
You can modify your logging format by defining a custom prefix & suffix for each log line. For example:
```c++
void printPrefix(Print* _logOutput, int logLevel) {
printTimestamp(_logOutput);
printLogLevel (_logOutput, logLevel);
}
```
will result in log timestamps very similar to e.g. NLOG:
```
00:47:51.432 VERBOSE Message to be logged
```
## Credit
Based on library by
* [Bernd Klein](https://github.com/mrRobot62)
Bugfixes & features by
* [rahuldeo2047](https://github.com/rahuldeo2047)
* [NOX73](https://github.com/NOX73)
* [Dave Hylands](https://github.com/dhylands)
* [Jos Hanon](https://github.com/Josha)
* [Bertrand Lemasle](https://github.com/blemasle)
* [Mikael Falkvidd](https://github.com/mfalkvidd)
* [Rowan Goemans](https://github.com/rowanG077)
* [Nils Bokermann](https://github.com/sanddorn)
* [Florian](https://github.com/1technophile)
* [wrong-kendall](https://github.com/wrong-kendall)
* [bitli](https://github.com/bitli)
* [ChristianBauerAMDC](https://github.com/ChristianBauerAMDC)
## On using and modifying libraries
- [http://www.arduino.cc/en/Main/Libraries](http://www.arduino.cc/en/Main/Libraries)
- [http://www.arduino.cc/en/Reference/Libraries](http://www.arduino.cc/en/Reference/Libraries)
## Copyright
ArduinoLog (Copyright © 2017,2018, 2019, 2021) is provided under MIT License.
@@ -0,0 +1,94 @@
#include <ArduinoLog.h>
#include <Ethernet.h>
/*
_ ___ ___ _ _ ___ _ _ ___ _ ___ ___
/_\ | _ \ \| | | |_ _| \| |/ _ \| | / _ \ / __|
/ _ \| / |) | |_| || || .` | (_) | |_| (_) | (_ |
/_/ \_\_|_\___/ \___/|___|_|\_|\___/|____\___/ \___|
Log library example showing several advanced features
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
This example sketch shows most of the features of the ArduinoLog library
*/
const char * charArray = "this is a string";
const char flashCharArray1[] PROGMEM = "this is a string";
String stringValue1 = "this is a string";
IPAddress ipAdress(192, 168, 0, 1);
void setup() {
// Set up serial port and wait until connected
Serial.begin(9600);
while(!Serial && !Serial.available()){}
Log.setPrefix(printPrefix); // set prefix similar to NLog
Log.setSuffix(printSuffix); // set suffix
Log.begin(LOG_LEVEL_VERBOSE, &Serial);
Log.setShowLevel(false); // Do not show loglevel, we will do this in the prefix
}
void loop() {
// set up some random variables
//__FlashStringHelper cannot be declared outside a function
const __FlashStringHelper * flashCharArray2 = F("this is a string");
Log.notice ( "Log global Flash string value : %S" CR, flashCharArray1 );
Log.traceln ( "Log local Flash string value : %S" CR, flashCharArray2 );
Log.notice ( "Log string value : %s" CR, stringValue1.c_str());
Log.verboseln (F("Log ip adress : %p") , ipAdress );
delay(5000);
}
void printPrefix(Print* _logOutput, int logLevel) {
printTimestamp(_logOutput);
printLogLevel (_logOutput, logLevel);
}
void printTimestamp(Print* _logOutput) {
// Division constants
const unsigned long MSECS_PER_SEC = 1000;
const unsigned long SECS_PER_MIN = 60;
const unsigned long SECS_PER_HOUR = 3600;
const unsigned long SECS_PER_DAY = 86400;
// Total time
const unsigned long msecs = millis() ;
const unsigned long secs = msecs / MSECS_PER_SEC;
// Time in components
const unsigned long MiliSeconds = msecs % MSECS_PER_SEC;
const unsigned long Seconds = secs % SECS_PER_MIN ;
const unsigned long Minutes = (secs / SECS_PER_MIN) % SECS_PER_MIN;
const unsigned long Hours = (secs % SECS_PER_DAY) / SECS_PER_HOUR;
// Time as string
char timestamp[20];
sprintf(timestamp, "%02d:%02d:%02d.%03d ", Hours, Minutes, Seconds, MiliSeconds);
_logOutput->print(timestamp);
}
void printLogLevel(Print* _logOutput, int logLevel) {
/// Show log description based on log level
switch (logLevel)
{
default:
case 0:_logOutput->print("SILENT " ); break;
case 1:_logOutput->print("FATAL " ); break;
case 2:_logOutput->print("ERROR " ); break;
case 3:_logOutput->print("WARNING "); break;
case 4:_logOutput->print("INFO " ); break;
case 5:_logOutput->print("TRACE " ); break;
case 6:_logOutput->print("VERBOSE "); break;
}
}
void printSuffix(Print* _logOutput, int logLevel) {
_logOutput->print("");
}
@@ -0,0 +1,90 @@
#include <ArduinoLog.h>
/*
_ ___ ___ _ _ ___ _ _ ___ _ ___ ___
/_\ | _ \ \| | | |_ _| \| |/ _ \| | / _ \ / __|
/ _ \| / |) | |_| || || .` | (_) | |_| (_) | (_ |
/_/ \_\_|_\___/ \___/|___|_|\_|\___/|____\___/ \___|
Log library basic example
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
This example sketch shows most of the most used features of the ArduinoLog library
*/
int intValue1 , intValue2;
long longValue1, longValue2;
bool boolValue1, boolValue2;
const char charNotPrintable = 0x8B;
const char * charArray = "this is a string";
const char flashCharArray1[] PROGMEM = "this is a string";
String stringValue1 = "this is a string";
float floatValue;
double doubleValue;
void setup() {
// Set up serial port and wait until connected
Serial.begin(9600);
while(!Serial && !Serial.available()){}
randomSeed(analogRead(0));
// Pass log level, whether to show log level, and print interface.
// Available levels are:
// LOG_LEVEL_SILENT, LOG_LEVEL_FATAL, LOG_LEVEL_ERROR, LOG_LEVEL_WARNING, LOG_LEVEL_INFO, LOG_LEVEL_TRACE, LOG_LEVEL_VERBOSE
// Note: if you want to fully remove all logging code, uncomment #define DISABLE_LOGGING in Logging.h
// this will significantly reduce your project size
Log.begin(LOG_LEVEL_VERBOSE, &Serial);
//Start logging
Log.notice(F(CR "******************************************" CR)); // Info string with Newline
Log.notice( "*** Logging example " CR); // Info string in flash memory
Log.notice(F("******************* ")); Log.notice("*********************** " CR); // two info strings without newline will end up on same line
}
void loop() {
// set up some random variables
intValue1 = random(100);
intValue2 = random(10000);
longValue1 = random(1000000);
longValue2 = random(100000000);
boolValue1 = random(2)==0;
boolValue2 = random(2)==1;
floatValue = 12.34;
doubleValue= 1234.56789;
Log.notice ( "Log as Info with integer values : %d, %d" CR , intValue1, intValue2);
Log.notice (F("Log as Info with hex values : %x, %X" CR ), intValue1, intValue1);
Log.notice ( "Log as Info with hex values : %x, %X" CR , intValue2, intValue2);
Log.notice (F("Log as Info with binary values : %b, %B" CR ), intValue1, intValue1);
Log.notice ( "Log as Info with binary values : %b, %B" CR , intValue2, intValue2);
Log.notice (F("Log as Info with long values : %l, %l" CR ), longValue1, longValue2);
Log.notice ( "Log as Info with bool values : %t, %T" CR , boolValue1, boolValue2);
Log.notice (F("Log as Info with char value : %c" CR ), charArray[0]);
Log.notice ( "Log as Info with char value : %C" CR , charNotPrintable);
Log.notice (F("Log as Info with string value : %s" CR ), charArray);
Log.notice ( "Log as Info with Flash string value : %S" CR , flashCharArray1);
Log.notice ( "Log as Info with string value : %s" CR , stringValue1.c_str());
Log.notice (F("Log as Info with float value : %F" CR ), floatValue);
Log.notice ( "Log as Info with float value : %F" CR , floatValue);
Log.notice (F("Log as Info with double value : %D" CR ), doubleValue);
Log.notice ( "Log as Info with double value : %D" CR , doubleValue);
Log.notice (F("Log as Debug with mixed values : %d, %d, %l, %l, %t, %T" CR ), intValue1 , intValue2 ,
longValue1, longValue2,
boolValue1, boolValue2);
Log.trace ( "Log as Trace with bool value : %T" CR , boolValue1);
Log.traceln ( "Log as Trace with bool value : %T" , boolValue1);
Log.warning ( "Log as Warning with bool value : %T" CR , boolValue1);
Log.warningln( "Log as Warning with bool value : %T" , boolValue1);
Log.error ( "Log as Error with bool value : %T" CR , boolValue1);
Log.errorln ( "Log as Error with bool value : %T" , boolValue1);
Log.fatal ( "Log as Fatal with bool value : %T" CR , boolValue1);
Log.fatalln ( "Log as Fatal with bool value : %T" , boolValue1);
Log.verboseln(F("Log as Verbose with bool value : %T" ), boolValue2);
Log.verbose (F("Log as Verbose with bool value : %T" CR ), boolValue2);
delay(5000);
}
+58
View File
@@ -0,0 +1,58 @@
#######################################
# Syntax Coloring Map ArduinoLog library
#######################################
#######################################
# Instances (KEYWORD1)
#######################################
Logging KEYWORD1
Log KEYWORD1
#######################################
# Datatypes (KEYWORD1)
#######################################
#######################################
# Methods and Functions (KEYWORD2)
#######################################
fatal KEYWORD2
fatalln KEYWORD2
error KEYWORD2
errorln KEYWORD2
warning KEYWORD2
warningln KEYWORD2
info KEYWORD2
infoln KEYWORD2
notice KEYWORD2
noticeln KEYWORD2
trace KEYWORD2
traceln KEYWORD2
verbose KEYWORD2
verboseln KEYWORD2
begin KEYWORD2
setLevel KEYWORD2
getLevel KEYWORD2
setShowLevel KEYWORD2
getShowLevel KEYWORD2
setPrefix KEYWORD2
setSuffix KEYWORD2
clearPrefix KEYWORD2
clearSuffix KEYWORD2
#######################################
# Instances (KEYWORD2)
#######################################
Logging KEYWORD2
Log KEYWORD2
#######################################
# Constants (LITERAL1)
#######################################
LOG_LEVEL_SILENT LITERAL1 Constants
LOG_LEVEL_FATAL LITERAL1 Constants
LOG_LEVEL_ERROR LITERAL1 Constants
LOG_LEVEL_WARNING LITERAL1 Constants
LOG_LEVEL_NOTICE LITERAL1 Constants
LOG_LEVEL_INFO LITERAL1 Constants
LOG_LEVEL_TRACE LITERAL1 Constants
LOG_LEVEL_VERBOSE LITERAL1 Constants
+19
View File
@@ -0,0 +1,19 @@
{
"name": "ArduinoLog",
"keywords": "logging, debug, log, log levels, AVR, ESP8266",
"description": "ArduinoLog is a minimalistic logging framework to help the programmer output log statements to a variety of output targets. ArduinoLog is designed so that log statements can remain in the code with minimal performance cost. In order to facilitate this the loglevel can be adjusted, and if the code is completely tested all logging code can be compiled out. Tested for AVR, ESP8266 & ESP32 boards. Detailed instructions for use on Github page.",
"version": "1.1.1",
"authors": {
"name": "Thijs Elenbaas",
"url": "https://github.com/thijse",
"maintainer": true
},
"repository": {
"type": "git",
"url": "https://github.com/thijse/Arduino-Log"
},
"homepage": "https://github.com/thijse/Arduino-Log/",
"frameworks": ["arduino"],
"platforms": "*",
"examples": "examples/*/*.ino"
}
@@ -0,0 +1,10 @@
name=ArduinoLog
version=1.1.1
author=Thijs Elenbaas
maintainer=Thijs Elenbaas <thijs@contemplated.nl>
sentence=Small logging framework
paragraph=ArduinoLog is a minimalistic logging framework to help the programmer output log statements to a variety of output targets. ArduinoLog is designed so that log statements can remain in the code with minimal performance cost. In order to facilitate this the loglevel can be adjusted, and if the code is completely tested all logging code can be compiled out. Tested for AVR, ESP8266 & ESP32 boards. Detailed instructions for use on Github page.
category=Communication
url=https://github.com/thijse/Arduino-Log/
architectures=*
includes=ArduinoLog.h