Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

Data Serializer and Logger #21

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Data Serializer and Logger #21

wants to merge 5 commits into from

Conversation

cowsed
Copy link
Contributor

@cowsed cowsed commented Jul 14, 2023

Fair warning, I don't know if this works because I do not have a brain (it builds tho).

Serializer

Usage:

Serializer s; // create an empty serializer

s.set_bool("do_stuff", true);
s.set_double("voltage", 11.54);
s.set_int("auto_program", 12);
s.set_string("name", "Flynn");

s.save_to_disk("out.txt"); // Save to disk. If this is not called, nothing will be saved

Serializer s2("out.txt"); // load data from out.txt
s2.bool_or("do_stuff", false); // retrieve 'do_stuff' or false if 'do_stuff' is not specified
s2.double_or("voltage", 0.0); // retrieve 'voltage or 0.0 if 'voltage' is not specified
s2.int_or("auto_program", 1); // retrieve 'auto_program' or 1 if 'auto_program is not specified
s2.string_or("name", "No Name");  // retrieve 'name or No Name if 'name is not specified

Logger

    Logger l("log.txt"); // Will automatically write to "log.txt"

    // "Bare" logging
    l.Log("Text with manual newline\n");
    l.Logln("Text with automatic newline");
    l.Logf("Formatted %s %c", "Text", '!');


    // Tagged logging (DEBUG, NOTICE, WARNING, ERROR, CRITICAL)
    l.Log(LogLevel::WARNING, "Text with manual newline\n");
    l.Logln(LogLevel::ERROR, "Text with automatic newline");
    l.Logf(LogLevel::DEBUG, "Formatted %s %c", "Text", '!');

Open Questions:

  • Should logger include timestamps
  • Should all log lines have a level or should no log lines have a level.
  • Will this be performant enough (VEX Sd card functions are wild, maybe we should add some buffering inside Logger and also have Logger.flush(); which will then do the actual saving)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant