Skip to content

[RFC] C++ Example Logging Statements  #356

@kxyr

Description

@kxyr

This RFC aims to collect a variety of use cases of logging statements, that will be used to establish the convention and design of the C++ Logging API/SDK in #337.

The goal is to obtain a collection of observability-specific logging statements that:

  • use different data types (custom or built in)
  • use different formats (template or string), and
  • are simple and intuitive to learn and write.

Example Submission
Simple structured logging of a map:

unordered_map<string, int> mymap = {{ "First", 1 },
                                    { "Second",2 }
                                    { "Third", 3 }
                                                 }; 

Write the map to the logger, along with the severity and message:

logger.DEBUG("Outputting a map ", mymap);

This code snippet creates a log with a map attached to it. This is a type of structured logging, since the data holds a relationship with itself through key/value pairs. If this log were converted to JSON, it may have the following structure:

{
    "SeverityLevel": DEBUG,
    "Timestamp": Oct 07 10:59AM, 
    "Message": "Outputting a map", 
    "map1": {
        "First": 1,
        "Second": 2,
        "Third": 3
    }
}

Request for Comments

Please comment below to add examples of log formats and the different ways logging can be performed in C++, with the relevant data definitions (if applicable).

cc: @MarkSeufert @alolita @reyang @maxgolov @ThomsonTan

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions