adityatelang74

Fast C++ Logging Library - spdlog

GitHub release GitHub issues GitHub stars

Table of Contents

Overview

spdlog is a fast C++ logging library designed for ease of use and high performance. It is a header-only library, which means you can easily include it in your projects without complicated setup. With support for various logging levels and formats, spdlog makes logging in C++ applications straightforward.

For the latest releases, visit Releases.

Features

Installation

To use spdlog, you can download it directly from the Releases section. Look for the latest release and download the necessary files.

Clone the Repository

You can also clone the repository using Git:

git clone https://github.com/adityatelang74/spdlog.git

After cloning, navigate to the directory and include the header files in your project.

CMake Integration

If you are using CMake, you can easily integrate spdlog into your project by adding the following lines to your CMakeLists.txt:

add_subdirectory(spdlog)
target_link_libraries(your_target PRIVATE spdlog::spdlog)

Usage

To start using spdlog, include the header in your source files:

#include "spdlog/spdlog.h"

Basic Logging

Here is a simple example of how to log messages:

#include "spdlog/spdlog.h"

int main() {
    spdlog::info("Hello, {}!", "world");
    return 0;
}

Log Levels

You can use different log levels to categorize your messages:

spdlog::debug("This is a debug message");
spdlog::info("This is an info message");
spdlog::warn("This is a warning message");
spdlog::error("This is an error message");
spdlog::critical("This is a critical message");

Custom Formatting

You can customize the format of your log messages:

spdlog::set_pattern("%Y-%m-%d %H:%M:%S [%l] %v");
spdlog::info("Custom formatted message");

Examples

Console Logging

To log messages to the console, you can use the default logger:

spdlog::info("Logging to console");

File Logging

To log messages to a file, create a file logger:

auto file_logger = spdlog::basic_logger_mt("file_logger", "logs.txt");
file_logger->info("Logging to a file");

Asynchronous Logging

To enable asynchronous logging, you can set up a logger like this:

spdlog::set_async_mode(8192); // Set queue size
auto async_logger = spdlog::stdout_color_mt("async_logger");
async_logger->info("Asynchronous logging enabled");

Contributing

We welcome contributions to spdlog! If you would like to contribute, please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes and commit them.
  4. Push your changes to your fork.
  5. Submit a pull request.

Please ensure your code follows the existing style and includes tests where applicable.

License

spdlog is licensed under the MIT License. See the LICENSE file for more details.

Contact

For questions or support, feel free to reach out via the issues section on GitHub or contact me directly.

For the latest releases, visit Releases.