Git Product home page Git Product logo

asynclogger's Introduction

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)

asynclogger's People

Contributors

yimura avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.