Skip to content

Commit f8c352c

Browse files
committed
Updated prefix & suffix example
Added ESP32 tested statement
1 parent d05e81f commit f8c352c

File tree

4 files changed

+115
-105
lines changed

4 files changed

+115
-105
lines changed

ArduinoLog.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,15 @@ class Logging
311311
va_list args;
312312
va_start(args, msg);
313313
print(msg, args);
314-
if (cr) { _logOutput->print(CR); }
314+
315315
if(_suffix != NULL)
316316
{
317317
_suffix(_logOutput);
318318
}
319+
if (cr)
320+
{
321+
_logOutput->print(CR);
322+
}
319323
#endif
320324
}
321325

LICENSE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
MIT License
22

3-
Copyright (c) 2017,2018,2021 Thijs Elenbaas, MrRobot62, rahuldeo2047, NOX73, dhylands, Josha
4-
blemasle, mfalkvidd
3+
Copyright (c) 2017,2018,2021 Thijs Elenbaas, MrRobot62, rahuldeo2047, NOX73,
4+
dhylands, Josha, blemasle, mfalkvidd
55

66
Permission is hereby granted, free of charge, to any person obtaining a copy
77
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ArduinoLog is a minimalistic framework to help the programmer output log stateme
2020

2121
* All Arduino boards (Uno, Due, Mini, Micro, Yun...)
2222
* ESP8266
23+
* ESP32
2324

2425
## Downloading
2526

@@ -175,4 +176,4 @@ Bugfixes & features by
175176

176177
## Copyright
177178

178-
ArduinoLog is provided Copyright © 2017,2018, 2019 under MIT License.
179+
ArduinoLog is provided Copyright © 2017,2018, 2019, 2021 under MIT License.

examples/Log/Log.ino

Lines changed: 106 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,106 @@
1-
#include <ArduinoLog.h>
2-
/*
3-
_ ___ ___ _ _ ___ _ _ ___ _ ___ ___
4-
/_\ | _ \ \| | | |_ _| \| |/ _ \| | / _ \ / __|
5-
/ _ \| / |) | |_| || || .` | (_) | |_| (_) | (_ |
6-
/_/ \_\_|_\___/ \___/|___|_|\_|\___/|____\___/ \___|
7-
8-
Log library example
9-
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
10-
11-
This example sketch shows most of the features of the ArduinoLog library
12-
13-
*/
14-
15-
16-
int intValue1 , intValue2;
17-
long longValue1, longValue2;
18-
bool boolValue1, boolValue2;
19-
const char * charArray = "this is a string";
20-
const char flashCharArray1[] PROGMEM = "this is a string";
21-
String stringValue1 = "this is a string";
22-
float floatValue;
23-
double doubleValue;
24-
25-
void setup() {
26-
// Set up serial port and wait until connected
27-
Serial.begin(9600);
28-
while(!Serial && !Serial.available()){}
29-
randomSeed(analogRead(0));
30-
// Pass log level, whether to show log level, and print interface.
31-
// Available levels are:
32-
// LOG_LEVEL_SILENT, LOG_LEVEL_FATAL, LOG_LEVEL_ERROR, LOG_LEVEL_WARNING, LOG_LEVEL_NOTICE, LOG_LEVEL_TRACE, LOG_LEVEL_VERBOSE
33-
// Note: if you want to fully remove all logging code, uncomment #define DISABLE_LOGGING in Logging.h
34-
// this will significantly reduce your project size
35-
36-
Log.begin(LOG_LEVEL_VERBOSE, &Serial);
37-
//Log.setPrefix(printTimestamp); // Uncomment to get timestamps as prefix
38-
//Log.setSuffix(printNewline); // Uncomment to get newline as suffix
39-
40-
//Start logging
41-
42-
Log.notice(F(CR "******************************************" CR)); // Info string with Newline
43-
Log.notice( "*** Logging example " CR); // Info string in flash memory
44-
Log.notice(F("******************* ")); Log.notice("*********************** " CR); // two info strings without newline
45-
}
46-
47-
void loop() {
48-
// set up some random variables
49-
intValue1 = random(100);
50-
intValue2 = random(10000);
51-
longValue1 = random(1000000);
52-
longValue2 = random(100000000);
53-
boolValue1 = random(2)==0;
54-
boolValue2 = random(2)==1;
55-
floatValue = 12.34;
56-
doubleValue= 1234.56789;
57-
58-
//__FlashStringHelper cannot be declared outside a function
59-
const __FlashStringHelper * flashCharArray2 = F("this is a string");
60-
61-
Log.notice ( "Log as Info with integer values : %d, %d" CR , intValue1, intValue2);
62-
Log.notice (F("Log as Info with hex values : %x, %X" CR ), intValue1, intValue1);
63-
Log.notice ( "Log as Info with hex values : %x, %X" CR , intValue2, intValue2);
64-
Log.notice (F("Log as Info with binary values : %b, %B" CR ), intValue1, intValue1);
65-
Log.notice ( "Log as Info with binary values : %b, %B" CR , intValue2, intValue2);
66-
Log.notice (F("Log as Info with long values : %l, %l" CR ), longValue1, longValue2);
67-
Log.notice ( "Log as Info with bool values : %t, %T" CR , boolValue1, boolValue2);
68-
Log.notice (F("Log as Info with string value : %s" CR ), charArray);
69-
Log.notice ( "Log as Info with Flash string value : %S" CR , flashCharArray1);
70-
Log.notice ( "Log as Info with Flash string value : %S" CR , flashCharArray2);
71-
Log.notice ( "Log as Info with string value : %s" CR , stringValue1.c_str());
72-
Log.notice (F("Log as Info with float value : %F" CR ), floatValue);
73-
Log.notice ( "Log as Info with float value : %F" CR , floatValue);
74-
Log.notice (F("Log as Info with double value : %D" CR ), doubleValue);
75-
Log.notice ( "Log as Info with double value : %D" CR , doubleValue);
76-
Log.notice (F("Log as Debug with mixed values : %d, %d, %l, %l, %t, %T" CR ), intValue1 , intValue2,
77-
longValue1, longValue2, boolValue1, boolValue2);
78-
Log.noticeln ( "Log as Info with integer values : %d, %d" , intValue1, intValue2);
79-
Log.trace ( "Log as Trace with bool value : %T" CR , boolValue1);
80-
Log.traceln ( "Log as Trace with bool value : %T" , boolValue1);
81-
Log.warning ( "Log as Warning with bool value : %T" CR , boolValue1);
82-
Log.warningln( "Log as Warning with bool value : %T" , boolValue1);
83-
Log.error ( "Log as Error with bool value : %T" CR , boolValue1);
84-
Log.errorln ( "Log as Error with bool value : %T" , boolValue1);
85-
Log.fatal ( "Log as Fatal with bool value : %T" CR , boolValue1);
86-
Log.fatalln ( "Log as Fatal with bool value : %T" , boolValue1);
87-
Log.verboseln(F("Log as Verbose with bool value : %T" ), boolValue2);
88-
Log.verbose (F("Log as Verbose with bool value : %T" CR CR CR ), boolValue2);
89-
delay(5000);
90-
}
91-
92-
void printTimestamp(Print* _logOutput) {
93-
char c[12];
94-
int m = sprintf(c, "%10lu ", millis());
95-
_logOutput->print(c);
96-
}
97-
98-
void printNewline(Print* _logOutput) {
99-
_logOutput->print('\n');
100-
}
101-
1+
#include <ArduinoLog.h>
2+
/*
3+
_ ___ ___ _ _ ___ _ _ ___ _ ___ ___
4+
/_\ | _ \ \| | | |_ _| \| |/ _ \| | / _ \ / __|
5+
/ _ \| / |) | |_| || || .` | (_) | |_| (_) | (_ |
6+
/_/ \_\_|_\___/ \___/|___|_|\_|\___/|____\___/ \___|
7+
8+
Log library example
9+
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
10+
11+
This example sketch shows most of the features of the ArduinoLog library
12+
13+
*/
14+
15+
16+
int intValue1 , intValue2;
17+
long longValue1, longValue2;
18+
bool boolValue1, boolValue2;
19+
const char * charArray = "this is a string";
20+
const char flashCharArray1[] PROGMEM = "this is a string";
21+
String stringValue1 = "this is a string";
22+
float floatValue;
23+
double doubleValue;
24+
25+
void setup() {
26+
// Set up serial port and wait until connected
27+
Serial.begin(9600);
28+
while(!Serial && !Serial.available()){}
29+
randomSeed(analogRead(0));
30+
// Pass log level, whether to show log level, and print interface.
31+
// Available levels are:
32+
// LOG_LEVEL_SILENT, LOG_LEVEL_FATAL, LOG_LEVEL_ERROR, LOG_LEVEL_WARNING, LOG_LEVEL_NOTICE, LOG_LEVEL_TRACE, LOG_LEVEL_VERBOSE
33+
// Note: if you want to fully remove all logging code, uncomment #define DISABLE_LOGGING in Logging.h
34+
// this will significantly reduce your project size
35+
36+
Log.begin(LOG_LEVEL_VERBOSE, &Serial);
37+
38+
39+
//Start logging
40+
41+
Log.notice(F(CR "******************************************" CR)); // Info string with Newline
42+
Log.notice( "*** Logging example " CR); // Info string in flash memory
43+
Log.notice(F("******************* ")); Log.notice("*********************** " CR); // two info strings without newline
44+
}
45+
46+
void loop() {
47+
// set up some random variables
48+
intValue1 = random(100);
49+
intValue2 = random(10000);
50+
longValue1 = random(1000000);
51+
longValue2 = random(100000000);
52+
boolValue1 = random(2)==0;
53+
boolValue2 = random(2)==1;
54+
floatValue = 12.34;
55+
doubleValue= 1234.56789;
56+
57+
//__FlashStringHelper cannot be declared outside a function
58+
const __FlashStringHelper * flashCharArray2 = F("this is a string");
59+
60+
Log.notice ( "Log as Info with integer values : %d, %d" CR , intValue1, intValue2);
61+
Log.notice (F("Log as Info with hex values : %x, %X" CR ), intValue1, intValue1);
62+
Log.notice ( "Log as Info with hex values : %x, %X" CR , intValue2, intValue2);
63+
Log.notice (F("Log as Info with binary values : %b, %B" CR ), intValue1, intValue1);
64+
Log.notice ( "Log as Info with binary values : %b, %B" CR , intValue2, intValue2);
65+
Log.notice (F("Log as Info with long values : %l, %l" CR ), longValue1, longValue2);
66+
Log.notice ( "Log as Info with bool values : %t, %T" CR , boolValue1, boolValue2);
67+
Log.notice (F("Log as Info with string value : %s" CR ), charArray);
68+
Log.notice ( "Log as Info with Flash string value : %S" CR , flashCharArray1);
69+
Log.notice ( "Log as Info with Flash string value : %S" CR , flashCharArray2);
70+
Log.notice ( "Log as Info with string value : %s" CR , stringValue1.c_str());
71+
Log.notice (F("Log as Info with float value : %F" CR ), floatValue);
72+
Log.notice ( "Log as Info with float value : %F" CR , floatValue);
73+
Log.notice (F("Log as Info with double value : %D" CR ), doubleValue);
74+
Log.notice ( "Log as Info with double value : %D" CR , doubleValue);
75+
Log.notice (F("Log as Debug with mixed values : %d, %d, %l, %l, %t, %T" CR ), intValue1 , intValue2,
76+
longValue1, longValue2, boolValue1, boolValue2);
77+
78+
Log.trace ( "Log as Trace with bool value : %T" CR , boolValue1);
79+
Log.traceln ( "Log as Trace with bool value : %T" , boolValue1);
80+
Log.warning ( "Log as Warning with bool value : %T" CR , boolValue1);
81+
Log.warningln( "Log as Warning with bool value : %T" , boolValue1);
82+
Log.error ( "Log as Error with bool value : %T" CR , boolValue1);
83+
Log.errorln ( "Log as Error with bool value : %T" , boolValue1);
84+
Log.fatal ( "Log as Fatal with bool value : %T" CR , boolValue1);
85+
Log.fatalln ( "Log as Fatal with bool value : %T" , boolValue1);
86+
Log.verboseln(F("Log as Verbose with bool value : %T" ), boolValue2);
87+
Log.verbose (F("Log as Verbose with bool value : %T" CR ), boolValue2);
88+
89+
Log.setPrefix(printTimestamp); // set timestamp as prefix
90+
Log.setSuffix(printCarret); // set carret as suffix
91+
Log.verboseln(F("Log with suffix & prefix"));
92+
Log.setPrefix(NULL); // set timestamp as prefix
93+
Log.setSuffix(NULL); // set carret as suffix
94+
95+
delay(5000);
96+
}
97+
98+
void printTimestamp(Print* _logOutput) {
99+
char c[12];
100+
int m = sprintf(c, "%10lu ", millis());
101+
_logOutput->print(c);
102+
}
103+
104+
void printCarret(Print* _logOutput) {
105+
_logOutput->print('>');
106+
}

0 commit comments

Comments
 (0)