Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic Message Logger #4

Open
6 tasks
EvanLF6768 opened this issue Oct 25, 2023 · 0 comments
Open
6 tasks

Basic Message Logger #4

EvanLF6768 opened this issue Oct 25, 2023 · 0 comments
Assignees

Comments

@EvanLF6768
Copy link
Contributor

EvanLF6768 commented Oct 25, 2023

A simple interface for logging messages to a serial console with a printf like API to act as the complete bare minimum for logging. In future, something more advanced such as WPILog to facilitate namespaces and datalogging would be preferred.

Frontend

printf-like

// Get the primary logger singleton
auto log = Logging::GetLog();
// The different functions are different log levels
log.Trace("Super verbose information which isn't very important during normal operation, only enabled in debug builds");
log.Debug("Slightly more important information which should not exist during normal operation, only enabled in debug builds");
log.Info("General details which do not imply there is an issue");
log.Warn("Something strange might be going on (eg. a secondary sensor is not connected), but all subsystems can continue to operate");
log.Error("A subsystem has failed");
log.Fatal("Core components cannot operate");

// Specify the level through an enum instead
log.LogMessage(Logging::Level::kWarn, "Can be used for variable log levels");

// Specify format arguments
log.Info("The meaning of life: {}", 42);

RAII Output Iterator

The printf like API will likely be written in terms of this.

{
    // Create a new message handle
    auto msg = Logging::GetLog().MessageBuilder(Logging::Level::kWarn);
    // Write a single character
    *msg++ = 'F';
    // Use format
    std::format_to(msg, "Hello {}", "World!");
    // Message is committed at the end of the scope
}

Metadata

To the beginning of each message the following should be appended:

  • Timestamp (seconds since boot to the nearest microsecond)
  • Level
  • Current FreeRTOS task
    At the end of the message a newline and a null character (acting as an end of message sentinal) should be appended.

For example Warn("foo {}", 42) could become something like [13.894662|WARN|MyTask] foo 42\n\0.

Backend

Messages should be written to an arbitrary number of OutputPort objects. An implementation for a USB VCOM port should be written.

Checkpoints

  • Freestanding Hello World via USB VCOM
  • Logging::GetLog() and temporary proof of concept function log.RawMessage(str) which directly sends the message with no metadata, formatting or use of OutputPort abstraction
  • Extract USB code into an OutputPort object, unit testing
  • MessageBuilder without log levels or metadata
  • Log levels (no other metadata) and all frontend functions
  • Timestamp and current task
@EvanLF6768 EvanLF6768 assigned EvanLF6768 and AronDK and unassigned EvanLF6768 Feb 20, 2024
@EvanLF6768 EvanLF6768 changed the title Implement Logger Basic Message Logger May 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants