Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Asyncronous C++20 logger with std::format and fmt::format support.

License

Notifications You must be signed in to change notification settings

Yimura/AsyncLogger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

24 Commits

Repository files navigation

AsyncLogger

Modern Asyncronous Logger using C++20 and std::format (falls back on fmt::format if not available) without using macro's! Uses std::source_location to get the location where a log was made.

CMake variables

  • USE_FMT : Force AsyncLogger to use fmt formatting instead of std formatting if it's available.

How to use

Very simple example application showing how to implement it.

main.cpp

#include "AsyncLogger/Logger.hpp"
#include <filesystem>
#include <iostream>
// expose LOG, LOGF, eLogLevel::DEBUG, eLogLevel::INFO, etc...
using namespace al;
void COUT_LOG(LogMessagePtr msg)
{
 const auto& location = msg->Location();
 const auto file = std::filesystem::path(msg->Location().file_name()).filename().string();
 std::cout << "[" << file << ":" << location.line() << "] " << msg->Message();
}
int main()
{
 Logger::Init();
 Logger::AddSink(COUT_LOG);
 LOG(INFO) << "Test " << 1 << 2 << 3 << " some float (" << 3.5f << ")";
 Logger::Destroy();
 return 0;
}

Logs the following output:

[main.cpp:20] Test 123 some float (3.5)

CMakeLists.txt

cmake_minimum_required(VERSION 3.20)
set(CMAKE_CXX_STANDARD 20 GLOBAL)
project(my_app LANGUAGES CXX VERSION 0.0.1)
add_subdirectory(AsyncLogger)
add_executable(${PROJECT_NAME} src/main.cpp)
target_link_libraries(${PROJECT_NAME} AsyncLogger)

CMakeLists.txt using FetchContent

cmake_minimum_required(VERSION 3.20)
set(CMAKE_CXX_STANDARD 20 GLOBAL)
project(my_app LANGUAGES CXX VERSION 0.0.1)
include(FetchContent)
FetchContent_Declare(
 AsyncLogger
 GIT_REPOSITORY https://github.com/Yimura/AsyncLogger.git
 GIT_TAG master
 GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(AsyncLogger)
add_executable(${PROJECT_NAME} src/main.cpp)
target_link_libraries(${PROJECT_NAME} AsyncLogger)

About

Asyncronous C++20 logger with std::format and fmt::format support.

Resources

License

Stars

Watchers

Forks

Contributors 4

AltStyle によって変換されたページ (->オリジナル) /