Skip to content

pongasoft/re-logging

Repository files navigation

Introduction

This project started as a clone of loguru. Since 2.0.0, this is a very stripped-down version of loguru that works well in the context of a Rack Extension. See here for more details.

Install

  • Include re-logging.cmake in the project
  • Add ${re-logging_INCLUDE_DIRS} to target_include_directories()
  • Because of the rack extension environment/limitations, logging.cpp can only be compiled in native builds

The project is then included like this:

#include <logging.h>

It is strongly recommended to use re-cmake for building a rack extension.

Check RE Quickstart for a quick and convenient way to generate a blank rack extension that use re-logging.

Usage

This project offers a set of macros:

MacroDescription
DLOG_F(verbosity, ...) The main macro used for logging (note that the name was kept from loguru). Using verbosity FATAL will cause the message to be displayed and the program aborted.
DCHECK_F(test, ...)This macro checks that the expression resolves to true and aborts if not
DCHECK_NOTNULL_F(x, ...)This macro checks that the expression is not null and aborts if not
DCHECK_EQ_F(a, b, ...)This macro checks that a == b and aborts if not
DCHECK_NE_F(a, b, ...)This macro checks that a != b and aborts if not
DCHECK_LT_F(a, b, ...)This macro checks that a < b and aborts if not
DCHECK_LE_F(a, b, ...)This macro checks that a <= b and aborts if not
DCHECK_GT_F(a, b, ...)This macro checks that a > b and aborts if not
DCHECK_GE_F(a, b, ...)This macro checks that a >= b and aborts if not
ABORT_F(...) Logs the message and aborts. Note that if RE_LOGGING_INIT_FOR_TEST is called, then it will throw a catchable exception instead of aborting which is useful for testing purposes
RE_LOGGING_INIT_FOR_RE(re_name)This macro can be called when the device is created to make the output nicer
RE_LOGGING_INIT_FOR_TEST(prefix)This macro can be used from tests to replace "abort" with exception (which can be checked)
RE_LOGGING_SET_VERBOSITY(verbosity) This macro changes the verbosity level. Possible values are:
  • FATAL
  • ERROR
  • WARNING
  • INFO (default)
  • VERBOSE
JBOX_LOGVALUES(iMessage, ...) Allows writing simpler code
// using JBOX_TRACEVALUES
TJBox_Value instanceIDValue = JBox_MakeNumber(JBox_GetNumber(iParams[0]));
TJBox_Value array[1];
array[0] = instanceIDValue;
JBOX_TRACEVALUES("instance ID = ^0", array, 1);

// using JBOX_LOGVALUES JBOX_LOGVALUES("instance ID = ^0", iParams[0]));

This project offers a set of C defines:

DefineDefaultDescription
RE_LOGGING_DEFAULT_VERBOSITY INFO The default level of verbosity. Can be changed at runtime with the RE_LOGGING_SET_VERBOSITY macro
RE_LOGGING_STRIP_FILE_PATH 1 Whether to display only the filename (1) by stripping the file path or the full path (0)

Release notes

2.0.2 - 2025/08/16

  • Simplified prefix logic

2.0.1 - 2025/08/15

  • Fixed prefix override

2.0.0 - 2025/08/15

  • Removed most of the loguru implementation in favor of a lighter implementation (#1)
  • Only the major loguru APIs were kept (DLOG_F, ABORT_F, DCHECK_F and DCHECK_*_F variants)
  • Added RE_LOGGING_SET_VERBOSITY macro to change the logging verbosity at runtime
  • Added RE_LOGGING_DEFAULT_VERBOSITY C define to change the default logging verbosity at compilation time (default to INFO)
  • Added RE_LOGGING_STRIP_FILE_PATH C define to change if the filename or the full path is displayed (default to filename)
  • Replaced loguru::init_for_re (now deprecated) with the macro RE_LOGGING_INIT_FOR_RE
  • Replaced loguru::init_for_test (now deprecated) with the macro RE_LOGGING_INIT_FOR_TEST

1.0.2 - 2024/10/08

  • Does not fail anymore when included via FetchContent_MakeAvailable

1.0.1 - 2022/02/01

  • Fix for Windows 10 build

1.0.0 - 2022/01/24

  • First release.

License

  • This project is released under the terms of the Apache 2.0 license

  • This project is a very stripped-down version of loguru which is distributed with the following license:

    This software is in the public domain. Where that dedication is not recognized, you are granted a perpetual, irrevocable license to copy, modify and distribute it as you see fit

  • This project uses the Rack extension SDK released under the Rack Extension License agreement

About

A stripped-down version of loguru for Rack Extension development

Resources

License

Stars

Watchers

Forks

Packages

No packages published