{"id":13438964,"url":"https://github.com/badaix/aixlog","last_synced_at":"2025-04-04T22:07:22.542Z","repository":{"id":39917663,"uuid":"97391526","full_name":"badaix/aixlog","owner":"badaix","description":"Header-only C++ logging library","archived":false,"fork":false,"pushed_at":"2025-01-23T10:19:06.000Z","size":175,"stargazers_count":140,"open_issues_count":7,"forks_count":28,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-28T21:07:28.254Z","etag":null,"topics":["android-log","cpp11","eventlog","log","logcat","logging","macos-log","outputdebugstring","syslog"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/badaix.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-16T15:11:54.000Z","updated_at":"2025-03-23T03:21:49.000Z","dependencies_parsed_at":"2024-06-20T11:59:00.791Z","dependency_job_id":"2408aec0-afab-4398-9efb-c76bb4ec6d56","html_url":"https://github.com/badaix/aixlog","commit_stats":{"total_commits":134,"total_committers":5,"mean_commits":26.8,"dds":0.08955223880597019,"last_synced_commit":"fd4a341740ee840092963de852584ec8ff811c4f"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badaix%2Faixlog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badaix%2Faixlog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badaix%2Faixlog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badaix%2Faixlog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/badaix","download_url":"https://codeload.github.com/badaix/aixlog/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247256112,"owners_count":20909240,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android-log","cpp11","eventlog","log","logcat","logging","macos-log","outputdebugstring","syslog"],"created_at":"2024-07-31T03:01:10.034Z","updated_at":"2025-04-04T22:07:22.526Z","avatar_url":"https://github.com/badaix.png","language":"C++","readme":"# AixLog\n\nHeader-only C++ logging library\n\n[![Github Releases](https://img.shields.io/github/release/badaix/aixlog.svg)](https://github.com/badaix/aixlog/releases)\n[![Build Status](https://travis-ci.org/badaix/aixlog.svg?branch=master)](https://travis-ci.org/badaix/aixlog)\n[![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/badaix/aixlog.svg)](https://lgtm.com/projects/g/badaix/aixlog/context:cpp)  \n\n## Features\n\n* Single header file implementation\n  * Simply include and use it!\n  * No dependcies, just vanilla C++11\n* Permissive MIT license\n* Use ostream operator `\u003c\u003c`\n  * Unobtrusive, typesafe and expressive\n  * Easy to switch from existing \"cout logging\"\n* Fancy name\n* Native support for various platforms (through Sinks)\n  * Linux, Unix: Syslog\n  * macOS: Unified logging (os_log), Syslog (\u003c10.12)\n  * Android: Android Log\n  * Windows: Event log, OutputDebugString\n* Several Sinks:\n  * cout\n  * cerr\n  * Sink with custom callback function\n    * implement your own log sink in a lambda with a single line of code\n  * Easy to add more...\n* Manipulators for\n  * Different log levels: `TRACE, DEBUG, INFO, NOTICE, WARNING, ERROR, FATAL`  \n    `LOG(ERROR) \u003c\u003c \"some error happened!\"`  \n    `LOG(DEBUG) \u003c\u003c \"Just a debug message\"`\n  * Conditional logging: simply put `COND(bool)` in front   \n    `LOG(INFO) \u003c\u003c COND(false) \u003c\u003c \"will not be logged\\n\"`  \n    `LOG(INFO) \u003c\u003c COND(true) \u003c\u003c \"will be logged\\n\"`\n  * Support for tags:  \n    `LOG(INFO, \"my tag\") \u003c\u003c \"some message\"`  \n    ...is the same as...  \n    `LOG(INFO) \u003c\u003c TAG(\"my tag\") \u003c\u003c \"some message\"`\n  * Capture function and line number and timestamp\n  * Filters: filter by tag and/or by severity what message is logged where, e.g.\n    * Add a syslog sink with the filters `*:error`, `SYSLOG:trace` to receive only messages with severity `error` or with tag `SYSLOG`\n    * Add another `cout` sink with filter `*:debug` to receive all messages with `debug` or higher severity\n  * Support for colors:\n    * Foreground: `LOG(INFO) \u003c\u003c COLOR(red) \u003c\u003c \"red foreground\"`\n    * Foreground and background: `LOG(INFO) \u003c\u003c COLOR(yellow, blue) \u003c\u003c \"yellow on blue background\"`\n\n## Basic usage\n\nTo use AixLog, you must once pass a log sink to `AixLog:Log::init`, e.g. a `SinkCout`:\n\n```c++\nAixLog::Log::init\u003cAixLog::SinkCout\u003e(AixLog::Severity::trace);\nLOG(INFO) \u003c\u003c \"Hello, World!\\n\";\n```\n\nThis will print\n\n```\n2017-09-28 11-01-16.049 [Info] (main) Hello, World!\n```\n\nThere are two overloads for `AixLog:Log::init`:\n\n1. one creates and returns an instance of a Sink (as in the example above)\n\n   ```c++\n   auto sink = AixLog::Log::init\u003cAixLog::SinkCout\u003e(AixLog::Severity::trace);\n   ```\n\nThe `sink` can be used to change the severity or to remove it from the Logger\n\n2. one takes a vector of Sinks\n\n   ```c++\n   auto sink_cout = make_shared\u003cAixLog::SinkCout\u003e(AixLog::Severity::trace);\n   auto sink_file = make_shared\u003cAixLog::SinkFile\u003e(AixLog::Severity::trace, \"logfile.log\");\n   AixLog::Log::init({sink_cout, sink_file});\n   ```\n\nThis will log to both: `cout` and to file `logfile.log`\n\n## Advanced usage\n\nYou can easily fit AixLog to your needs by adding your own sink, that derives from the `Sink` class. Or even more simple, by using `SinkCallback` with a custom call back function:\n\n```c++\nAixLog::Log::init\u003cAixLog::SinkCallback\u003e(AixLog::Severity::trace, AixLog::Type::all, \n    [](const AixLog::Metadata\u0026 metadata, const std::string\u0026 message)\n    {\n        cout \u003c\u003c \"Callback:\\n\\tmsg:   \" \u003c\u003c message \u003c\u003c \"\\n\\ttag:   \" \u003c\u003c metadata.tag.text \u003c\u003c \"\\n\\tsever: \" \u003c\u003c AixLog::Log::to_string(metadata.severity) \u003c\u003c \" (\" \u003c\u003c (int)metadata.severity \u003c\u003c \"\\n\";\n        if (metadata.timestamp)\n            cout \u003c\u003c \"\\ttime:  \" \u003c\u003c metadata.timestamp.to_string() \u003c\u003c \"\\n\";\n        if (metadata.function)\n            cout \u003c\u003c \"\\tfunc:  \" \u003c\u003c metadata.function.name \u003c\u003c \"\\n\\tline:  \" \u003c\u003c metadata.function.line \u003c\u003c \"\\n\\tfile:  \" \u003c\u003c metadata.function.file \u003c\u003c \"\\n\";\n    }\n);\nLOG(INFO) \u003c\u003c TAG(\"test\") \u003c\u003c \"Hello, Lambda!\\n\";\n```\n\nThis will print\n\n```\nCallback:\n    msg:   Hello, Lambda!\n    tag:   test\n    sever: Info (2)\n    type:  normal\n    time:  2017-09-28 11-46-32.179\n    func:  main\n    line:  36\n    file:  aixlog_test.cpp\n```\n\n## Usage example\n\n```c++\n#include \"aixlog.hpp\"\n\nusing namespace std;\n\nint main(int argc, char** argv)\n{\n    AixLog::Log::init(\n        {\n            /// Log normal (i.e. non-special) logs to SinkCout\n            make_shared\u003cAixLog::SinkCout\u003e(AixLog::Severity::trace, \"cout: %Y-%m-%d %H-%M-%S.#ms [#severity] (#tag) #message\"),\n            /// Log error and higher severity messages to cerr\n            make_shared\u003cAixLog::SinkCerr\u003e(AixLog::Severity::error, AixLog::Type::all, \"cerr: %Y-%m-%d %H-%M-%S.#ms [#severity] (#tag)\"),\n            /// Log special logs to native log (Syslog on Linux, Android Log on Android, EventLog on Windows, Unified logging on Apple)\n            make_shared\u003cAixLog::SinkNative\u003e(\"aixlog\", AixLog::Severity::trace, AixLog::Type::special),\n            /// Callback log sink with cout logging in a lambda function\n            /// Could also do file logging\n            make_shared\u003cAixLog::SinkCallback\u003e(AixLog::Severity::trace, AixLog::Type::all, \n                [](const AixLog::Metadata\u0026 metadata, const std::string\u0026 message)\n                {\n                    cout \u003c\u003c \"Callback:\\n\\tmsg:   \" \u003c\u003c message \u003c\u003c \"\\n\\ttag:   \" \u003c\u003c metadata.tag.text \u003c\u003c \"\\n\\tsever: \" \u003c\u003c AixLog::Log::to_string(metadata.severity) \u003c\u003c \" (\" \u003c\u003c (int)metadata.severity \u003c\u003c \"\\n\";\n                    if (metadata.timestamp)\n                        cout \u003c\u003c \"\\ttime:  \" \u003c\u003c metadata.timestamp.to_string() \u003c\u003c \"\\n\";\n                    if (metadata.function)\n                        cout \u003c\u003c \"\\tfunc:  \" \u003c\u003c metadata.function.name \u003c\u003c \"\\n\\tline:  \" \u003c\u003c metadata.function.line \u003c\u003c \"\\n\\tfile:  \" \u003c\u003c metadata.function.file \u003c\u003c \"\\n\";\n                }\n            )\n        }\n    );\n\n    /// Log with info severity\n    LOG(INFO) \u003c\u003c \"LOG(INFO)\\n\";\n    /// ... with a tag\n    LOG(INFO, \"guten tag\") \u003c\u003c \"LOG(INFO, \\\"guten tag\\\")\\n\";\n    /// ... with an explicit tag (same result as above)\n    LOG(INFO) \u003c\u003c TAG(\"guten tag\") \u003c\u003c \"LOG(INFO) \u003c\u003c TAG(\\\"guten tag\\\")\\n\";\n\n    /// Different log severities\n    LOG(FATAL) \u003c\u003c \"LOG(FATAL)\\nLOG(FATAL) Second line\\n\";\n    LOG(FATAL) \u003c\u003c TAG(\"hello\") \u003c\u003c \"LOG(FATAL) \u003c\u003c TAG(\\\"hello\\\") no line break\";\n    LOG(FATAL) \u003c\u003c \"LOG(FATAL) 2 no line break\";\n    LOG(ERROR) \u003c\u003c \"LOG(ERROR): change in log-level will add a line break\";\n    LOG(WARNING) \u003c\u003c \"LOG(WARNING)\";\n    LOG(NOTICE) \u003c\u003c \"LOG(NOTICE)\";\n    LOG(INFO) \u003c\u003c \"LOG(INFO)\\n\";\n    LOG(INFO) \u003c\u003c TAG(\"my tag\") \u003c\u003c \"LOG(INFO) \u003c\u003c TAG(\\\"my tag\\\")n\";\n    LOG(DEBUG) \u003c\u003c \"LOG(DEBUG)\\n\";\n    LOG(TRACE) \u003c\u003c \"LOG(TRACE)\\n\";\n\n    /// Conditional logging\n    LOG(DEBUG) \u003c\u003c COND(1 == 1) \u003c\u003c \"LOG(DEBUG) will be logged\\n\";\n    LOG(DEBUG) \u003c\u003c COND(1 == 2) \u003c\u003c \"LOG(DEBUG) will not be logged\\n\";\n\n    /// Colors :-)\n    LOG(FATAL) \u003c\u003c \"LOG(FATAL) \" \u003c\u003c AixLog::Color::red \u003c\u003c \"red\" \u003c\u003c AixLog::Color::none \u003c\u003c \", default color\\n\";\n    LOG(FATAL) \u003c\u003c \"LOG(FATAL) \" \u003c\u003c COLOR(red) \u003c\u003c \"red\" \u003c\u003c COLOR(none) \u003c\u003c \", default color (using macros)\\n\";\n    LOG(FATAL) \u003c\u003c \"LOG(FATAL) \" \u003c\u003c AixLog::TextColor(AixLog::Color::yellow, AixLog::Color::blue) \u003c\u003c \"yellow on blue background\" \u003c\u003c AixLog::Color::none \u003c\u003c \", default color\\n\";\n    LOG(FATAL) \u003c\u003c \"LOG(FATAL) \" \u003c\u003c COLOR(yellow, blue) \u003c\u003c \"yellow on blue background\" \u003c\u003c COLOR(none) \u003c\u003c \", default color (using macros)\\n\";\n}\n```\n","funding_links":[],"categories":["C++"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbadaix%2Faixlog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbadaix%2Faixlog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbadaix%2Faixlog/lists"}