embeddedartistry / arduino-logger Goto Github PK
View Code? Open in Web Editor NEWFlexible logging library for the Arduino SDK, allowing the same logging interface to be used with multiple outputs.
License: MIT License
Flexible logging library for the Arduino SDK, allowing the same logging interface to be used with multiple outputs.
License: MIT License
I don't know much cpp, and relatively new to Arduino ecosystem. While trying to use the example, I get following error.
I installed, arduino-printf, arduino-logger and tried with https://github.com/greiman/SdFat-beta and https://github.com/greiman/SdFs (which say deprecated). Still same error.
Users/bsr/Documents/Arduino/libraries/arduino-logger-master/src/AVRSDRotationalLogger.h:76:13: error: 'SdFs' has not been declared
void begin(SdFs& sd_inst)
^~~~
/Users/bsr/Documents/Arduino/libraries/arduino-logger-master/src/AVRSDRotationalLogger.h:186:2: error: 'SdFs' does not name a type; did you mean 'SdFile'?
SdFs* fs_;
^~~~
SdFile
/Users/bsr/Documents/Arduino/libraries/arduino-logger-master/src/AVRSDRotationalLogger.h:188:2: error: 'FsFile' does not name a type; did you mean 'SDFile'?
FsFile file_;
^~~~~~
SDFile
/Users/bsr/Documents/Arduino/libraries/arduino-logger-master/src/AVRSDRotationalLogger.h: In member function 'virtual size_t AVRSDRotationalLogger::size() const':
/Users/bsr/Documents/Arduino/libraries/arduino-logger-master/src/AVRSDRotationalLogger.h:39:10: error: 'file_' was not declared in this scope
return file_.size();
^~~~~
/Users/bsr/Documents/Arduino/libraries/arduino-logger-master/src/AVRSDRotationalLogger.h:39:10: note: suggested alternative: 'fileno'
return file_.size();
^~~~~
fileno
/Users/bsr/Documents/Arduino/libraries/arduino-logger-master/src/AVRSDRotationalLogger.h: In member function 'virtual size_t AVRSDRotationalLogger::capacity() const':
/Users/bsr/Documents/Arduino/libraries/arduino-logger-master/src/AVRSDRotationalLogger.h:45:10: error: 'fs_' was not declared in this scope
return fs_ ? fs_->card()->sectorCount() << 9 : 0;
^~~
/Users/bsr/Documents/Arduino/libraries/arduino-logger-master/src/AVRSDRotationalLogger.h:45:10: note: suggested alternative: 'fbs_t'
return fs_ ? fs_->card()->sectorCount() << 9 : 0;
^~~
fbs_t
/Users/bsr/Documents/Arduino/libraries/arduino-logger-master/src/AVRSDRotationalLogger.h: In member function 'virtual void AVRSDRotationalLogger::flush()':
/Users/bsr/Documents/Arduino/libraries/arduino-logger-master/src/AVRSDRotationalLogger.h:50:7: error: 'file_' was not declared in this scope
if(!file_.open(filename_, O_WRITE | O_APPEND))
^~~~~
/Users/bsr/Documents/Arduino/libraries/arduino-logger-master/src/AVRSDRotationalLogger.h:50:7: note: suggested alternative: 'fileno'
if(!file_.open(filename_, O_WRITE | O_APPEND))
^~~~~
fileno
/Users/bsr/Documents/Arduino/libraries/arduino-logger-master/src/AVRSDRotationalLogger.h:55:11: error: 'file_' was not declared in this scope
int r = file_.write(buffer_, counter);
I need to add documentation on using the meson build system + using this project as a meson subproject.
Feedback from Kelley:
It's not obvious that it needs to be singleton. Might be useful to have multiple loggers at some point. If desirable to only have one instance, users can enforce that by convention. (just instantiate one)
My response:
Agreed with you here. There's currently nothing that prevents multiple loggers from being declared and used, but the interface won't be friendly. That will be improved per your suggestion.
The original goal was to abstract things so users didn't have to worry about properly passing around a logger instance to multiple files/modules. I originally had a client misuse some logging code by declaring multiple loggers and being surprised that some messages were missing from the buffer.
I'll think about how to modify the design so that it works conveniently if you want a global logger instance, and still works well if you want to create multiple loggers.
I had this thought yesterday, because the core logic I used is general C++ and not tied to Arduino. I've created a repo for a C++ embedded logger to house some of the core code and generalize it. The goal is that the core library would live there, and the arduino-logging library would submodule it, provide arduino-specific logging strategies, examples, and support the library organizational structure.
There's a two problems I'm thinking about ways to address:
I like a more organized project structure, and Arduino enforces a top-level file set for libraries, or else things aren't properly discovered
I think I can solve this with wrapper headers, but I ran into some include problems earlier today, so I need to work out the kinks
There are C++14/C++17 features that I use in the original library that had to be stripped out for the Arduino ecosystem, I'm not sure how I want to manage that dichotomy
These macros are supported by the library, but we don't have any examples that show how they are used. We should add some!
You can see them used in the tests, for a reference.
Right now, we do this check per-character, which is quite inefficient:
virtual void log_add_char_to_buffer(char c)
{
if(auto_flush() && (internal_size() == internal_capacity()))
{
flush();
}
else if (internal_size() == internal_capacity())
{
overrun_occurred_ = true;
}
log_putc(c);
}
Ideally we'd check for the full contents of the string to be added to the log, splitting earlier than the character level. Perhaps this occurs in print()?
Filtering message routing based on log level needs to be checked. I'd expect a user to implement that strategy manually, but need to verify that the appropriate hooks are there to enable that
What if a user wanted to compile-out all logging without relying on the macros? In this case, I could see using a "log disable" strategy of some sort.
We could make a class that doesn't perform any logging. With it, we can see how effective such a strategy would be. Do calls eventually get compiled out because they are no-ops? Does the class itself?
Request from Kelley:
Please test a bit with Arduino 1.5 version soon to see if it supports the lang features you're using.. One product wuses 1.5 and another uses 1.6/1.8 version. If not, and hard to adapt, I vote continuing with 1.6/1/8 version, and we can get that working and ponder 1.5 later.
We want milliseconds from boot.
How can we take in a timestamp without a) requiring a system clock, and b) using the millis() function directly?
Also, how can we generalize the format for possibility of HH::MM::SS vs millis from boot?
We do not currently handle strings stored in flash via the F() macro.
https://andybrown.me.uk/wk/wp-content/images//avr-gcc-4.7.0/WString.h
https://github.com/esp8266/Arduino/blob/master/cores/esp8266/Print.h
We can add an option to the rotational SD logger strategy which supports a parameter that defines the maximum size of a log file. Once that file size is met, the file is closed and a new one is opened.
Possibly create a general file abstraction, so I can write to OS X files or SD card files?
hi i try to clone project to my local but getting error in multiple files one example as below:
Please make sure you have the correct access rights
and the repository exists.
fatal: clone of '[email protected]:embeddedartistry/cppcheck-rules.git' into submodule path 'C:/arduino-logger/build/analysis/cppcheck/cppcheck-rules' failed
Failed to clone 'analysis/cppcheck/cppcheck-rules'. Retry scheduled
Cloning into 'C:/arduino-logger/build/analysis/vale/vale-styleguide'...
fatal: Could not read from remote repository.
thank you
give a summary of the class, the design approach (expanding with custom strategies), and outline functions that the user can/should override.
From Kelley:
Consider generalizing the project name for broader C++ use. The library is generic but just happens to support Arduino. (and doesn't use streams)
We should also define an option in the rotational log file strategy that allow the user to specify the maximal number of log files.
I said:
I remembered why I went the macro route in my original code. It wasn't because I wanted to hide the inst(), that was just a bonus. The real reason for using macros is that there's no other way to get file, line number, or function information unless you use the preprocessor. That will change in C++20... but we can't use that.
From Kelley:
Wondering if there could be a TRACE(...) macro that prints the file, line, etc.
Log::error("null pointer. %s\n", TRACE());
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.