Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ArduinoLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ void Logging::begin(int level, Print* logOutput, bool showLevel)
setLevel(level);
setShowLevel(showLevel);
_logOutput = logOutput;
_semaphore = xSemaphoreCreateMutex();
xSemaphoreGive(_semaphore);
#endif
}

Expand Down
53 changes: 29 additions & 24 deletions ArduinoLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Licensed under the MIT License <http://opensource.org/licenses/MIT>.
#pragma once
#include <inttypes.h>
#include <stdarg.h>
#include <mutex>

// Non standard: Arduino.h also chosen if ARDUINO is not defined. To facilitate use in non-Arduino test environments
#if ARDUINO < 100
Expand Down Expand Up @@ -346,30 +347,33 @@ class Logging
{
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);

if(xSemaphoreTake(_semaphore, (TickType_t) 10 )) {

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);
}
xSemaphoreGive(_semaphore);
}
#endif
}
Expand All @@ -378,6 +382,7 @@ class Logging
int _level;
bool _showLevel;
Print* _logOutput;
SemaphoreHandle_t _semaphore;

printfunction _prefix = NULL;
printfunction _suffix = NULL;
Expand Down