add logger docs
This commit is contained in:
@@ -1,3 +1,13 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the split-flap project.
|
||||||
|
* Copyright (c) 2024-2025 GuniaLabs (www.dennisgunia.de)
|
||||||
|
* Authors: Dennis Gunia
|
||||||
|
*
|
||||||
|
* This program is licenced under AGPL-3.0 license.
|
||||||
|
*
|
||||||
|
* This section provides a simple logging functionality
|
||||||
|
*/
|
||||||
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -5,10 +15,15 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
int log_level_global = 4;
|
int log_level_global = 4; // set default log level to WARNING
|
||||||
|
|
||||||
const char *loglevel[] = {"TRACE","DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"};
|
const char *loglevel[] = {"TRACE","DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Initialize logger with specified log level
|
||||||
|
*
|
||||||
|
* @param log_level: log level to set
|
||||||
|
*/
|
||||||
void init_logger(int log_level)
|
void init_logger(int log_level)
|
||||||
{
|
{
|
||||||
log_level_global = log_level;
|
log_level_global = log_level;
|
||||||
@@ -16,6 +31,13 @@ void init_logger(int log_level)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Log message with specified log level
|
||||||
|
*
|
||||||
|
* @param level: log level of message
|
||||||
|
* @param message: message format string
|
||||||
|
* @param ...: additional arguments for message format
|
||||||
|
*/
|
||||||
void log_message(int level, const char *message, ...)
|
void log_message(int level, const char *message, ...)
|
||||||
{
|
{
|
||||||
if (level >= log_level_global)
|
if (level >= log_level_global)
|
||||||
@@ -31,6 +53,12 @@ void log_message(int level, const char *message, ...)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Log message header with specified log level
|
||||||
|
*
|
||||||
|
* @param level: log level of message
|
||||||
|
* @return 1 if message should be logged, 0 otherwise
|
||||||
|
*/
|
||||||
int log_message_header(int level)
|
int log_message_header(int level)
|
||||||
{
|
{
|
||||||
if (level >= log_level_global)
|
if (level >= log_level_global)
|
||||||
|
|||||||
Reference in New Issue
Block a user