Skip to content

testillano/logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C++ syslog wrapper library

License: MIT Documentation Ask Me Anything ! Maintenance Main project workflow

The syslog.h library, could waste time parsing strings which are not going to be finally logged. Indeed, stdarg.h is used behind so this could make slower programs when using syslog traces.

This library is a simple wrapper static class over syslog.h in order to check the log level in advance and also provides useful macro definitions to ease messages formatting:

You should protect a whole block of code which only shall be processed when the appropriate log level is assigned:

LOGDEBUG, LOGINFORMATIONAL, LOGNOTICE and LOGWARNING are used for that.

Integration

logger.hpp is the single required file in include/ert or released here. You need to add

#include <ert/logger.hpp>

CMake

Embedded

Replication

To embed the library directly into an existing CMake project, place the entire source tree in a subdirectory and call add_subdirectory() in your CMakeLists.txt file:

# Typically you don't care so much for a third party library's examples to be
# run from your own project's code.
set(ERT_LOGGER_BuildExamples OFF CACHE INTERNAL "")

add_subdirectory(ert_logger)
...
add_library(foo ...)
...
target_link_libraries(foo PRIVATE ert_logger::ert_logger)
FetchContent

Since CMake v3.11, FetchContent can be used to automatically download the repository as a dependency at configure type.

Example:

include(FetchContent)

FetchContent_Declare(ert_logger
  GIT_REPOSITORY https://github.com/testillano/logger.git
  GIT_TAG vx.y.z)

FetchContent_GetProperties(ert_logger)
if(NOT ert_json_POPULATED)
  FetchContent_Populate(ert_logger)
  add_subdirectory(${ert_logger_SOURCE_DIR} ${ert_logger_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()

Build

$ cmake .
$ make

For debug compilation, do the following:

$ cmake -DCMAKE_BUILD_TYPE=Debug .
$ make
Doxygen documentation

This requires doxygen installed: sudo apt-get install doxygen.

$ make doc

Execute example

$ build/Release/bin/logme

Usage: logme <log level> [--verbose (to print traces on console)]

Log levels allowed: Debug|Informational|Notice|Warning|Error|Critical|Alert|Emergency

Install

$ sudo make install

Contributing

Please, execute astyle formatting (using frankwolf image) before any pull request:

$ sources=$(find . -name "*.hpp" -o -name "*.cpp")
$ docker run -it --rm -v $PWD:/data frankwolf/astyle ${sources}

About

C++ syslog wrapper library

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published