RAVENNAKIT
Loading...
Searching...
No Matches
log.hpp File Reference
#include "platform.hpp"
#include "env.hpp"
#include "string.hpp"
#include <atomic>
#include <cstdlib>
#include "ravennakit/core/format.hpp"

Go to the source code of this file.

Namespaces

namespace  rav

Macros

#define RAV_ENABLE_SPDLOG   0
#define RAV_LOG_TRACE(...)
#define RAV_LOG_DEBUG(...)
#define RAV_LOG_CRITICAL(...)
#define RAV_LOG_ERROR(...)
#define RAV_LOG_WARNING(...)
#define RAV_LOG_INFO(...)
#define RAV_LOG(...)
#define CATCH_LOG_UNCAUGHT_EXCEPTIONS

Enumerations

enum class  LogLevel {
  off , critical , error , warning ,
  info , debug , trace
}

Functions

void rav::set_log_level (const char *level)
 Sets the log level for the application based on the given string.
void rav::set_log_level_from_env (const char *env_var="RAV_LOG_LEVEL")
 Tries to find given environment variable and set the log level accordingly.

Variables

std::atomic log_level = LogLevel::info

Macro Definition Documentation

◆ CATCH_LOG_UNCAUGHT_EXCEPTIONS

#define CATCH_LOG_UNCAUGHT_EXCEPTIONS
Value:
catch (const rav::Exception& e) { \
RAV_LOG_CRITICAL("rav::Exception caught: {} - please handle your exceptions before reaching this point.", e.what()); \
} \
catch (const std::exception& e) { \
RAV_LOG_CRITICAL("std::exception caucght: {} - please handle your exceptions before reaching this point.", e.what()); \
} \
catch (...) { \
RAV_LOG_CRITICAL("unknown exception caucght - please handle your exceptions before reaching this point."); \
}
const char * what() const noexcept override
Definition exception.hpp:59

Definition at line 135 of file log.hpp.

◆ RAV_ENABLE_SPDLOG

#define RAV_ENABLE_SPDLOG   0

Definition at line 35 of file log.hpp.

◆ RAV_LOG

#define RAV_LOG ( ...)
Value:
if (log_level.load() >= LogLevel::trace) { \
fmt::println("[L] " __VA_ARGS__); \
}
std::atomic log_level
Definition log.hpp:82
@ trace
Definition log.hpp:80

Definition at line 127 of file log.hpp.

◆ RAV_LOG_CRITICAL

#define RAV_LOG_CRITICAL ( ...)
Value:
if (log_level.load() >= LogLevel::critical) { \
fmt::println("[C] " __VA_ARGS__); \
}
@ critical
Definition log.hpp:80

Definition at line 99 of file log.hpp.

◆ RAV_LOG_DEBUG

#define RAV_LOG_DEBUG ( ...)
Value:
if (log_level.load() >= LogLevel::debug) { \
fmt::println("[D] " __VA_ARGS__); \
}
@ debug
Definition log.hpp:80

Definition at line 92 of file log.hpp.

◆ RAV_LOG_ERROR

#define RAV_LOG_ERROR ( ...)
Value:
if (log_level.load() >= LogLevel::error) { \
fmt::println("[E] " __VA_ARGS__); \
}
@ error
Definition log.hpp:80

Definition at line 106 of file log.hpp.

◆ RAV_LOG_INFO

#define RAV_LOG_INFO ( ...)
Value:
if (log_level.load() >= LogLevel::info) { \
fmt::println("[I] " __VA_ARGS__); \
}
@ info
Definition log.hpp:80

Definition at line 120 of file log.hpp.

◆ RAV_LOG_TRACE

#define RAV_LOG_TRACE ( ...)
Value:
if (log_level.load() >= LogLevel::trace) { \
fmt::println("[T] " __VA_ARGS__); \
}

Definition at line 85 of file log.hpp.

◆ RAV_LOG_WARNING

#define RAV_LOG_WARNING ( ...)
Value:
if (log_level.load() >= LogLevel::warning) { \
fmt::println("[W] " __VA_ARGS__); \
}
@ warning
Definition log.hpp:80

Definition at line 113 of file log.hpp.

Enumeration Type Documentation

◆ LogLevel

enum class LogLevel
strong
Enumerator
off 
critical 
error 
warning 
info 
debug 
trace 

Definition at line 80 of file log.hpp.

Variable Documentation

◆ log_level

std::atomic log_level = LogLevel::info
inline

Definition at line 82 of file log.hpp.