Skip to content
forked from linkdd/logfmtxx

Header only C++23 structured logging library using logfmt

License

Notifications You must be signed in to change notification settings

BigPeet/logfmtxx

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

logfmtxx

Header-only C++23 structured logging library using the logfmt format.

Installation

Just copy the include/logfmtxx.hpp in your project.

Or with Shipp, add it to your dependencies:

{
  "name": "myproject",
  "version": "0.1.0",
  "dependencies": [
    {
      "name": "logfmtxx",
      "url": "https://github.com/linkdd/logfmtxx.git",
      "version": "v0.1.0"
    }
  ]
}

Usage

First, include the relevant headers:

#include <iostream> // if you wish to print logs with std::cout or std::cerr
#include <logfmtxx.hpp>

Then create a logger:

auto logger = logfmtxx::logger{
  [](const std::string& message) {
    std::cout << message << std::endl;
  }
};

Or with global fields:

auto logger = logfmtxx::logger{
  [](const std::string& message) {
    std::cout << message << std::endl;
  },
  logfmtxx::field{"foo", 42},
  logfmtxx::field{"bar", 3.14}
};

Then, call the log() method:

logger.log(logfmtxx::level::info, "hello world");

The result should be:

time="2001-01-01T00:00:00Z" level=info message="hello world" foo=42 bar=3.14000

You can add extra fields as well:

logger.log(
  logfmtxx::level::error,
  "internal server error",
  logfmtxx::field{"http.method", "GET"},
  logfmtxx::field{"http.path", "/"},
  logfmtxx::field{"http.status", 500}
);

The result should be:

time="2001-01-01T00:00:00Z" level=error message="internal server error" foo=42 bar=3.14000 http.method="GET" http.path="/" http.status=500

License

This software is released under the terms of the BSD 0-clause License.

About

Header only C++23 structured logging library using logfmt

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 99.9%
  • Makefile 0.1%