Skip to content

Added log ids to logs #440

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Added log ids to logs #440

wants to merge 2 commits into from

Conversation

gorbit99
Copy link
Contributor

@gorbit99 gorbit99 commented May 8, 2025

This PR attempts to implement #226, but is currently very work-in-progress and exists as more of a starting point than a final draft.

Each module of the code, besides getting the prefix, also gets an identifier, usually a lowercase version of its name, like "sensormanager" or "battery" or "fs", etc etc. Each module then has a list of numbers corresponding to one or a few messages all falling within the same narrow category, for example, the "Handshake successful, server is ..." message gets the unique HandshakeSuccessful id (connection-5), but anything that's manual calibration related would likely get the CalibrationInstruction id (sensor-9).

The format is then as follows:

{connection-5} [UPDConnection] [DEBUG] Handshake is successful, server is ...

The benefits of this technique:

  • Everything is specified, nothing is up to chance or code generation
  • "Collisions" are only possible if the programmer messes up, which are easy to notice
  • Changing texts around has no effect on the ids
  • The format string is still visible and is where it's used

And the cons:

  • Everything needs to be manually set up
  • If it's necessary to separate out a bunch of lines uniquely, that will be a lot of enum values

There are a couple other ways to go about this, in particular

  • Creating either pairs of a format string and an id then referencing that instead
  • Keeping all the strings used in the project in a single file then referencing them by ID

For several reasons I didn't like either of those options, so I went with this one instead.

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

Successfully merging this pull request may close these issues.

1 participant