Skip to content

Commit

Permalink
Several optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
Farossco committed Apr 18, 2020
1 parent 92d5868 commit 1c18dc3
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This library allows you to easily add logging to your program. It is mainly made
* Several log levels (Error, Warning, Info, Trace, Verbose)
* Multi-output: Logs the message on several outputs at once
* Logging using the iostream style (`<<`)
* Supports all kind of Print output (File handling coming soon)
* Supports all kind of Print output
* Displays a prefix with a clock and the logging level (Configurable)

## Tested for
Expand Down
4 changes: 2 additions & 2 deletions examples/ArduinoLogger/multiLogger.ino
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ void setup ()
verb << "This is a verbose message" << dendl; // Double end of line

logger.edit (Serial, LOG_LEVEL_INFO); // This will log info messages and bellow
logger.edit (Serial1, LOG_LEVEL_TRACE); // This will log info messages and bellow
logger.edit (Serial1, LOG_LEVEL_TRACE); // This will log trace messages and bellow

err << "This is an error message" << endl;
warn << "This is a warning message" << endl;
inf << "This is an info message" << endl;
trace << "I'm only showing up on Serial1" << endl; // This will only be displayed on Serial1
trace << "I'm only showing up on Serial1" << endl; // This will only be displayed on Serial1
verb << "I'm not displayed at all :'(" << dendl; // This will not be displayed at all

// By default, the date is displayed with the prefix,
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
],
"frameworks": "arduino",
"platforms": "*",
"version": "1.1.0"
"version": "1.1.1"
}
10 changes: 4 additions & 6 deletions src/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ void Logger::printPrefix (uint8_t index)
if (output->dateEnabled)
{
stream->print (F ("["));
stream->print (clock());
stream->print (getClock());
stream->print (F ("] "));
}

Expand Down Expand Up @@ -371,13 +371,11 @@ const char * Logger::debugLevelName (uint8_t debugLevel)
}
}

String Logger::clock ()
char * Logger::getClock ()
{
char buf[25];
sprintf (clock, "%.2d/%.2d/%.4d %.2d:%.2d:%.2d::%.3ld", day(), month(), year(), hour(), minute(), second(), (millis() % 1000));

sprintf (buf, "%.2d/%.2d/%.4d %.2d:%.2d:%.2d::%.3ld", day(), month(), year(), hour(), minute(), second(), (millis() % 1000));

return buf;
return clock;
}

Logger err (LOG_LEVEL_ERROR);
Expand Down
3 changes: 2 additions & 1 deletion src/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class Logger : public ostream
pos_type tellpos ();
void setflags ();

String clock ();
char * getClock ();
LogOutput * getLogOutputFromStream (Print & stream) const;
void initLogOutput (LogOutput * output, Print & stream, uint8_t level,
bool prefixEnabled,
Expand All @@ -136,6 +136,7 @@ class Logger : public ostream
static LogOutput * _outputs; // Ouputs array
static uint8_t _nOutputs; // Outputs counter
static uint8_t _nDisplayed; // Enabled outputs counter
char clock[30]; // 00/00/1970 00:00:00::000
};

Logger& endl (Logger& logger);
Expand Down
4 changes: 4 additions & 0 deletions src/ostream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ void ostream::putNum (uint32_t n, bool neg)
{
*--str = 'x';
}
else if (flags() & bin)
{
*--str = 'b';
}
*--str = '0';
}
uint8_t len = end - str;
Expand Down

0 comments on commit 1c18dc3

Please sign in to comment.