{"id":24889096,"url":"https://github.com/timothy-liuxf/simple_logger","last_synced_at":"2025-10-16T06:30:32.856Z","repository":{"id":114735770,"uuid":"587459270","full_name":"Timothy-Liuxf/simple_logger","owner":"Timothy-Liuxf","description":"simple_logger - A simple, multifunctional and header-only logging library for C++17.","archived":false,"fork":false,"pushed_at":"2024-08-23T09:29:49.000Z","size":114,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-08-23T22:08:50.304Z","etag":null,"topics":["cpp","cpp17","header-only","logging"],"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/Timothy-Liuxf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-10T19:57:34.000Z","updated_at":"2024-08-23T09:24:47.000Z","dependencies_parsed_at":"2024-08-22T21:41:02.571Z","dependency_job_id":null,"html_url":"https://github.com/Timothy-Liuxf/simple_logger","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Timothy-Liuxf%2Fsimple_logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Timothy-Liuxf%2Fsimple_logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Timothy-Liuxf%2Fsimple_logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Timothy-Liuxf%2Fsimple_logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Timothy-Liuxf","download_url":"https://codeload.github.com/Timothy-Liuxf/simple_logger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236684455,"owners_count":19188642,"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":["cpp","cpp17","header-only","logging"],"created_at":"2025-02-01T16:17:16.873Z","updated_at":"2025-10-16T06:30:27.578Z","avatar_url":"https://github.com/Timothy-Liuxf.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# simple_logger\n\n![display](./assets/display.png)\n\n## Introduction\n\n`simple_logger`, a simple, multifunctional and header-only log library for C++17.\n\n## Highlights\n\n+ :white_check_mark: Simple: Header-only, easy and convenient to use​\n+ :white_check_mark: Multiple styles to use: C++ `iostream` style, function style and ​format style\n+ :white_check_mark: High performance: Templatized, no runtime polymorphism\n+ :white_check_mark: Customizable thread-safety: Provide both thread-safe and thread-unsafe mode. No extra performance overhead in thread-unsafe mode.\n\n## Supported Platform\n\n+ Unix-like Operating Systems (Linux, MacOS, FreeBSD, ...)\n+ Windows x86/x64 (MSVC, MinGW, MinGW-w64, Cygwin, ...)\n+ ...\n\n## Supported Compiler\n\nMSVC, GCC and Clang, etc. supporting **C++17 standard or above**.\n\n## Clone this Repository\n\nRun:\n\n```shell\n$ git clone https://github.com/Timothy-Liuxf/simple_logger.git --recursive\n```\n\nor\n\n```shell\n$ git clone https://github.com/Timothy-Liuxf/simple_logger.git\n$ cd simple_logger\n$ git submodule update --init --recursive\n```\n\n## Get Started\n\n`simple_logger` is a header-only library and needn't to be built. Just add the `include` and `third_party/fmt/include` directories into the *include directories* of your C++ project and include `simple_logger/simple_logger.hpp` to get started.\n\n### Log Levels\n\nThere are six log levels in `simple_logger`: `Trace`, `Debug`, `Info`, `Warn`, `Error` and `Fatal`. The first two levels will print log messages into `stdout`, while the other two will print into `stderr`. By default, log messages in `Debug` level and `Trace` level are **NOT** printed.\n\n### Quick Start\n\nThere are three styles to log messages.\n\n#### C++ Style\n\nYou can log messages in C++ `iostream` style:\n\n```c++\n#include \u003csimple_logger/simple_logger.hpp\u003e\n\nusing namespace simple_logger;\n\nint main() {\n  logger.Trace() \u003c\u003c \"This message shouldn't be printed by default!\";\n  logger.Debug() \u003c\u003c \"This message shouldn't be printed by default!\";\n  logger.Info() \u003c\u003c \"Info message: \u003c\" \u003c\u003c 8888 \u003c\u003c '\u003e';\n  logger.Warn() \u003c\u003c \"Warn message: \u003c\" \u003c\u003c 8888 \u003c\u003c '\u003e';\n  logger.Error() \u003c\u003c \"Error message: \u003c\" \u003c\u003c 8888 \u003c\u003c '\u003e';\n  logger.Fatal() \u003c\u003c \"Fatal message: \u003c\" \u003c\u003c 8888 \u003c\u003c '\u003e';\n  return 0;\n}\n```\n\n#### Function Style\n\nYou can also log messages just as a variadic function:\n\n```c++\n#include \u003csimple_logger/simple_logger.hpp\u003e\n\nusing namespace simple_logger;\n\nint main() {\n  logger.Trace(\"This message shouldn't be printed by default!\");\n  logger.Debug(\"This message shouldn't be printed by default!\");\n  logger.Info(\"Info message: \u003c\", 8888, '\u003e');\n  logger.Warn(\"Warn message: \u003c\", 8888, '\u003e');\n  logger.Error(\"Error message: \u003c\", 8888, '\u003e');\n  logger.Fatal(\"Fatal message: \u003c\", 8888, '\u003e');\n  return 0;\n}\n```\n\n#### format style\n\nYou can also log messages in C++20 format library style:\n\n```c++\n#include \u003csimple_logger/simple_logger.hpp\u003e\n\nusing namespace simple_logger;\n\nint main() {\n  logger.Tracef(\"This message shouldn't be printed by default!\");\n  logger.Debugf(\"This message shouldn't be printed by default!\");\n  logger.Infof(\"Info message: \u003c{}\u003e\", 8888);\n  logger.Warnf(\"Warn message: \u003c{}\u003e\", 8888);\n  logger.Errorf(\"Error message: \u003c{}\u003e\", 8888);\n  logger.Fatalf(\"Fatal message: \u003c{}\u003e\", 8888);\n  return 0;\n}\n```\n\n### Format multiple objects\n\nWith [fmtlib](https://fmt.dev), `simple_logger` can support almost all formatting methods in fmtlib. Such as:\n\n1. Format ranges:\n\n   ```c++\n   #include \u003csimple_logger/simple_logger.hpp\u003e\n   \n   #include \u003cfmt/ranges.h\u003e\n   #include \u003carray\u003e\n   \n   using namespace simple_logger;\n   \n   int main() {\n     std::array arr {0, 1, 2, 3};\n     logger.Infof(\"Info message: {}\", arr);\n     return 0;\n   }\n   ```\n\n2. Format time:\n\n   ```c++\n   #include \u003csimple_logger/simple_logger.hpp\u003e\n   \n   #include \u003cfmt/chrono.h\u003e\n   #include \u003cchrono\u003e\n   \n   using namespace simple_logger;\n   \n   int main() {\n     auto current_time = fmt::localtime(\n         std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()));\n     logger.Infof(\"Info message: current_time: {:%Y-%m-%d %H:%M:%S}\",\n                  current_time);\n     return 0;\n   }\n   ```\n\n3. Literal-based format\n\n   ```c++\n   #include \u003csimple_logger/simple_logger.hpp\u003e\n   \n   #include \u003cfmt/format.h\u003e\n   \n   using namespace simple_logger;\n   \n   int main() {\n     using fmt::literals::operator\"\"_a;\n     logger.Infof(\"Info message: {num}\", \"num\"_a = 5);\n     return 0;\n   }\n   ```\n\n4. For more usage, please see [fmtlib API documentation](https://fmt.dev/latest/api.html).\n\n### Specify Log Levels\n\nTo specify log levels, you should define the following macros before including `simple_logger/simple_logger.hpp`:\n\n+ `SIMPLE_LOGGER_DISABLE_LOG`: No logs will be printed\n+ `SIMPLE_LOGGER_ENABLE_LOG_TRACE`: Log messages on `Trace`, `Debug`, `Info`, `Warning`, `Error` and `Fatal` levels will be printed\n+ `SIMPLE_LOGGER_ENABLE_LOG_DEBUG`: Log messages on `Debug`, `Info`, `Warning`, `Error` and `Fatal` levels will be printed\n+ `SIMPLE_LOGGER_ENABLE_LOG_INFO`: Log messages on `Info`, `Warning`, `Error` and `Fatal` levels will be printed\n+ `SIMPLE_LOGGER_ENABLE_LOG_WARN`: Log messages on `Warning`, `Error` and `Fatal` levels will be printed\n+ `SIMPLE_LOGGER_ENABLE_LOG_ERROR`: Log messages on `Error` and `Fatal` levels will be printed\n+ `SIMPLE_LOGGER_ENABLE_LOG_FATAL`: Only log messages on `Fatal` level will be printed\n+ If no macro is defined, it behaves just as `SIMPLE_LOGGER_ENABLE_LOG_INFO` is defined\n\n### Thread Safety\n\nThe log object `logger` is thread-safe. To use thread-unsafe log to avoid improve performance, you can use `uslogger`. For an example, the following code will cause chaos (changing `uslogger` to `logger` would fix it):\n\n```c++\n#include \u003csimple_logger/simple_logger.hpp\u003e\n\n#include \u003cmemory\u003e\n#include \u003cthread\u003e\n#include \u003cutility\u003e\n#include \u003cvector\u003e\n\nconstexpr std::size_t nthreads = 128;\n\nusing namespace simple_logger;\n\nint main(int argc, char*[]) {\n  std::vector\u003cstd::unique_ptr\u003cstd::thread\u003e\u003e threads(nthreads);\n  for (std::size_t i = 0; i \u003c nthreads; ++i) {\n    threads[i] = std::make_unique\u003cstd::thread\u003e([i, argc] {\n      std::this_thread::yield();\n      uslogger.Info() \u003c\u003c \"Thread-unsafe \"\n                      \u003c\u003c \"log. \"\n                      \u003c\u003c \"[argc: \" \u003c\u003c argc \u003c\u003c \"] \"\n                      \u003c\u003c \"At \"\n                      \u003c\u003c \"Index: \" \u003c\u003c i \u003c\u003c \".\";\n    });\n  }\n  for (std::size_t i = 0; i \u003c nthreads; ++i) {\n    threads[i]-\u003ejoin();\n    threads[i].reset();\n  }\n  return 0;\n}\n```\n\n## Build Examples\n\nSource code of the examples are in the `examples` directory.\n\nTo build the examples:\n\nFor all platforms with **CMake**, run:\n\n```shell\n$ mkdir build\n$ cd build\n$ cmake ..\n$ make -j$(nproc)\n```\n\nFor Unix-like platforms with **GNU Autotools**, run:\n\n```shell\n$ autoreconf -i\n$ BUILD_TEST_EXAMPLES=1 ./configure\n$ make -j$(nproc)\n```\n\nTo run the examples, then run:\n\n```shell\n$ ./examples/\u003cexample_name\u003e\n```\n\nThe `\u003cexample_name\u003e` is the same as the name of the corresponding source file after removing the extension name `.cc`.\n\n## Author\n\nCopyright (C) 2023, [Timothy Liu](https://github.com/Timothy-Liuxf)\n\nAll rights reserved\n\n## LICENSE\n\n[MIT License](https://github.com/Timothy-Liuxf/simple_logger/blob/master/LICENSE.txt)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimothy-liuxf%2Fsimple_logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimothy-liuxf%2Fsimple_logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimothy-liuxf%2Fsimple_logger/lists"}