https://github.com/artivis/lspdlog

Lazy spdlog

https://github.com/artivis/lspdlog

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (7.1%) to scientific vocabulary
Last synced: 9 months ago · JSON representation

Repository

Lazy spdlog

Basic Info
  • Host: GitHub
  • Owner: artivis
  • License: mit
  • Language: CMake
  • Default Branch: master
  • Size: 16.6 KB
Statistics
  • Stars: 6
  • Watchers: 2
  • Forks: 3
  • Open Issues: 0
  • Releases: 0
Created over 9 years ago · Last pushed over 6 years ago
Metadata Files
Readme License

README.md

lspdlog - Lazy spdlog

============================================

A simple wrapper package to enable cool logging for your project.

This package is nothing but a tiny hacky wrapper around spdlog logging library.
It has no other aim than enabling a bunch of macros to ease logging for your project.

For a more customizable logging please refer directly to spdlog wiki.

Disclamer:

All credits go to Gabi Melman and spdlog contributors, for this super fast C++ logging library.
I have only over-engineered a tiny cmake/cpp layer on top of it.

Requirements

  • c++11 compliant compiler.
  • internet connexion (spdlog is downloaded from github).

Install

  1. Simply clone or copy this package in your project directory:

    terminal $ cd ~/your_project/root_directory/ ~/your_project/root_directory$ git clone https://github.com/artivis/lspdlog.git

    or else

    terminal $ cd ~/your_project/root_directory/ ~/your_project/root_directory$ git submodule add https://github.com/artivis/lspdlog.git

  2. In your project CMakeLists.txt:

    ```cmake find_package(Threads REQUIRED)

    addsubdirectory(lspdlog) includedirectories(${LSPDLOGINCLUDEDIRS})

    addexecutable(myproject myproject.cpp) adddependencies(myproject spdlog) targetlinklibraries(myproject ${CMAKETHREADLIBS_INIT}) ```

  3. Compile your project.

  4. Nop that's it.

Enabling logging in file (Optional):

In order to enable a specific macro that logs in a file (see below), add to your project CMakeLists.txt:

```cmake

Set 'ON' to enable 'TRACE' macro.

option(LSPDLOGENABLETRACE_LOGGING "Enable trace logging." ON)

Set 'ON' to enable 'LOG' macro.

option(LSPDLOGENABLEDATA_LOGGING "Enable data logging." ON)

find_package(Threads REQUIRED)

addsubdirectory(lspdlog) includedirectories(${LSPDLOGINCLUDEDIRS})

addexecutable(myproject myproject.cpp) adddependencies(myproject spdlog) targetlinklibraries(myproject ${CMAKETHREADLIBS_INIT}) ```

Now what ?

This package defines automatically the following macros:

cpp YOUR_PROJECT_NAME_INFO(...); YOUR_PROJECT_NAME_WARN(...); YOUR_PROJECT_NAME_DEBUG(...); YOUR_PROJECT_NAME_ERROR(...);

Optionally:

cpp YOUR_PROJECT_NAME_TRACE(...); YOUR_PROJECT_NAME_LOG(...); YOUR_PROJECT_NAME_SCOPED_LOG(...);

An example:

Given your project CMakeLists.txt:

```cmake project(myawesomeproject)

Set 'ON' to enable 'TRACE' macro.

option(LSPDLOGENABLETRACE_LOGGING "Enable trace logging." OFF)

Set 'ON' to enable 'LOG' macro.

option(LSPDLOGENABLEDATA_LOGGING "Enable data logging." OFF)

find_package(Threads REQUIRED) #<-- necessary

lspdlog & spdlog require c++11 #<-- necessary and

set(CMAKECXXFLAGS "${CMAKECXXFLAGS} -std=c++11") #<-- automatically set

SET(CMAKEBUILDTYPE "DEBUG")

addsubdirectory(lspdlog) #<-- necessary includedirectories(${LSPDLOGINCLUDEDIRS}) #<-- necessary

addexecutable(myproject myproject.cpp) adddependencies(myproject spdlog) #<-- necessary, waits for downloading spdlog targetlinklibraries(myproject ${CMAKETHREADLIBS_INIT}) #<-- necessary ```

and your main file my_project.cpp:

```cpp

include "lspdlog/logging.h"

int main() { std::cout << "Hello world." << std::endl;

MYAWESOMEPROJECTINFO("Yep ", "that is"); MYAWESOMEPROJECTWARN("way\t", 2); MYAWESOMEPROJECTDEBUG("(I meant 'too'"); MYAWESOMEPROJECTERROR("easy");

return 0; } ```

the following gets printed in your terminal:

terminal Hello world. [info] Yep that is [warning] way 2 [debug] (I meant 'too') [error] easy

Now if we re-compile in release:

cmake SET(CMAKE_BUILD_TYPE "RELEASE")

terminal Hello world. [info] Yep that is [warning] way 2 [error] easy

Data logging (optional):

Given that you have set ON the data logging option (see section Install (optional)), the following macro is enabled:

cpp MY_AWESOME_PROJECT_LOG("Some data ", 2, " save.");

This functionality creates a .my_awesome_project folder in the user HOME directory such as:

terminal ~/.my_awesome_project$

where it will save all data passed to the MY_AWESOME_PROJECT_LOG(...) macro.
In order to keep things a little ordered, each time you run your program, the macro also creates a sub-directory named after the current date (MMDDYY - month-day-year) within which it saves the log file named after the current time (HHMMSS - hour-minutes-seconds):

terminal $ cat ~/.my_awesome_project/11_04_16/11_25_47.log [11:25:47.351422712] Some data 2 log.

This functionality can be enabled/disabled at runtime with the following macro:

```cpp MYAWESOMEPROJECTENABLEDATALOG(); MYAWESOMEPROJECTLOG("will get logged.");

MYAWESOMEPROJECTDISABLEDATALOG(); MYAWESOMEPROJECTLOG("will NOT get logged.");

{ MYAWESOMEPROJECTSCOPEDENABLELOG(); MYAWESOMEPROJECTLOG("will get logged."); }

MYAWESOMEPROJECT_LOG("will NOT get logged."); ```

Notice that the ~/.my_awesome_project directory and sub-directories are created (if they don't already exists) if the logging is enabled, either through CMake or manually.

Todo

  • [ ] fix (do) install rules & ExternalProject_Add
  • [x] trace macro
  • [x] scoped log macro
  • [ ] critical macro
  • [ ] async logger
  • [ ] enable more customization

Owner

  • Name: Jeremie Deray
  • Login: artivis
  • Kind: user
  • Location: France
  • Company: @CanonicalLtd

Roboticist / Software Developer, ROS(2) / C++ enthusiast.

GitHub Events

Total
Last Year

Issues and Pull Requests

Last synced: about 1 year ago

All Time
  • Total issues: 0
  • Total pull requests: 1
  • Average time to close issues: N/A
  • Average time to close pull requests: 1 minute
  • Total issue authors: 0
  • Total pull request authors: 1
  • Average comments per issue: 0
  • Average comments per pull request: 0.0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
  • asyafalni (1)
Top Labels
Issue Labels
Pull Request Labels