Skip to content

Commit

Permalink
Removing dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucarbou committed Feb 13, 2024
1 parent f7cd2ff commit 9ece2ae
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 35 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Expand Up @@ -67,9 +67,6 @@ jobs:
- name: Install core
run: arduino-cli core install --additional-urls "${{ matrix.index_url }}" ${{ matrix.core }}

- name: Install StreamUtils
run: arduino-cli lib install StreamUtils@1.8.0

- name: Build AdvancedLogger
run: arduino-cli compile --library . --warnings all -b ${{ matrix.board }} "examples/AdvancedLogger/AdvancedLogger.ino"

Expand Down
10 changes: 1 addition & 9 deletions library.json
@@ -1,6 +1,6 @@
{
"name": "MycilaLogger",
"version": "2.1.0",
"version": "2.2.0",
"description": "A simple and efficient logging library",
"keywords": "logging",
"homepage": "https://github.com/mathieucarbou/MycilaLogger",
Expand All @@ -18,14 +18,6 @@
"espressif32"
],
"headers": "MycilaLogger.h",
"dependencies": [
{
"owner": "bblanchon",
"name": "StreamUtils",
"version": "^1.8.0",
"platforms": "espressif32"
}
],
"export": {
"include": [
"examples",
Expand Down
3 changes: 1 addition & 2 deletions library.properties
@@ -1,5 +1,5 @@
name=MycilaLogger
version=2.1.0
version=2.2.0
author=Mathieu Carbou <mathieu.carbou@gmail.com>
maintainer=Mathieu Carbou <mathieu.carbou@gmail.com>
sentence=A simple and efficient logging library
Expand All @@ -8,4 +8,3 @@ category=Other
url=https://github.com/mathieucarbou/MycilaLogger
architectures=esp32
license=MIT
depends=StreamUtils
3 changes: 2 additions & 1 deletion platformio.ini
Expand Up @@ -3,7 +3,8 @@ build_flags =
-Wall
-Wextra
; -D MYCILA_LOGGER_CUSTOM_LEVEL
lib_deps = bblanchon/StreamUtils @ 1.8.0

lib_deps =

upload_protocol = esptool
upload_port = /dev/cu.usbserial-0001
Expand Down
39 changes: 19 additions & 20 deletions src/MycilaLogger.h
Expand Up @@ -4,18 +4,31 @@
*/
#pragma once

#include <StreamUtils.h>
#include <Arduino.h>
#include <Print.h>
#include <WString.h>
#include <esp32-hal-log.h>
#include <vector>

#define MYCILA_LOGGER_VERSION "2.1.0"
#define MYCILA_LOGGER_VERSION "2.2.0"
#define MYCILA_LOGGER_VERSION_MAJOR 2
#define MYCILA_LOGGER_VERSION_MINOR 1
#define MYCILA_LOGGER_VERSION_MINOR 2
#define MYCILA_LOGGER_VERSION_REVISION 0

#define MYCILA_LOGGER_TASK_NAME_LENGTH "10"
#define MYCILA_LOGGER_TAG_LENGTH "10"

namespace Mycila {
class LoggerBuffer : public Print {
public:
size_t write(const uint8_t* p, size_t n) override { return _buffer.concat(reinterpret_cast<const char*>(p), n) ? n : 0; }
size_t write(uint8_t c) override { return _buffer.concat(static_cast<char>(c)) ? 1 : 0; }
const String& buffer() const { return _buffer; }

private:
String _buffer;
};

class LoggerClass {
public:
#ifdef MYCILA_LOGGER_CUSTOM_LEVEL
Expand All @@ -34,18 +47,6 @@ namespace Mycila {

std::vector<Print*>& getOutputs() { return _outputs; }

template <typename... Args>
void debug(const char* tag, const __FlashStringHelper* format, Args... args) { log(ARDUHAL_LOG_LEVEL_DEBUG, tag, reinterpret_cast<const char*>(format), args...); }

template <typename... Args>
void info(const char* tag, const __FlashStringHelper* format, Args... args) { log(ARDUHAL_LOG_LEVEL_INFO, tag, reinterpret_cast<const char*>(format), args...); }

template <typename... Args>
void warn(const char* tag, const __FlashStringHelper* format, Args... args) { log(ARDUHAL_LOG_LEVEL_WARN, tag, reinterpret_cast<const char*>(format), args...); }

template <typename... Args>
void error(const char* tag, const __FlashStringHelper* format, Args... args) { log(ARDUHAL_LOG_LEVEL_ERROR, tag, reinterpret_cast<const char*>(format), args...); }

template <typename... Args>
void debug(const char* tag, const char* format, Args... args) { log(ARDUHAL_LOG_LEVEL_DEBUG, tag, format, args...); }

Expand All @@ -58,7 +59,6 @@ namespace Mycila {
template <typename... Args>
void error(const char* tag, const char* format, Args... args) { log(ARDUHAL_LOG_LEVEL_ERROR, tag, format, args...); }

private:
template <typename... Args>
void log(uint8_t level, const char* tag, const char* format, Args... args) {
#ifdef MYCILA_LOGGER_CUSTOM_LEVEL
Expand All @@ -69,7 +69,7 @@ namespace Mycila {
return;
#endif

StringPrint buffer;
LoggerBuffer buffer;

#if CONFIG_ARDUHAL_LOG_COLORS
buffer.print(_colors[level]);
Expand All @@ -85,9 +85,8 @@ namespace Mycila {

buffer.print("\r\n");

for (auto& output : _outputs) {
output->print(buffer.str());
}
for (auto& output : _outputs)
output->print(buffer.buffer());
}

private:
Expand Down

0 comments on commit 9ece2ae

Please sign in to comment.