Skip to content

Unspectacular, std::format based, thread-safe logging to stderr for C++

License

Notifications You must be signed in to change notification settings

wolmibo/logcerr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

logcerr

Unspectacular, std::format based, thread-safe logging to stderr for C++.

Features

  • (Optional) merging of successive, identical messages
  • (Optional) colored output on linux
  • Access to the output lock to mix log and custom write operations
  • No explicit initialization required

Limitations

  • Calling any function except logcerr::debugging_enabled before or after main is undefined behaviour

Example

#include <logcerr/log.hpp>
#include <thread>

int main() {
  logcerr::log("Hello, world!");

  std::jthread async{[](){
    logcerr::thread_name("async");

    std::this_thread::sleep_for(std::chrono::milliseconds(4));

    logcerr::error("This is an error from another thread");
  }};

  for (int i = 0; i < 10; ++i) {
    std::this_thread::sleep_for(std::chrono::milliseconds(1));

    logcerr::log("This message will be repeated {} times", 10);
  }
}

Possible output:

[00:00:00.000 main] Hello, world!
[00:00:00.001 main] This message will be repeated 10 times
[00:00:00.004 main] This message will be repeated 10 times (x2)
[00:00:00.004 async] *[Error]* This is an error from another thread
[00:00:00.005 main] This message will be repeated 10 times
[00:00:00.012 main] This message will be repeated 10 times (x6)

Build Requirements

  • GCC 12 or higher
  • fmt if the compiler does not provide __cpp_lib_format

About

Unspectacular, std::format based, thread-safe logging to stderr for C++

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published