-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* boxes - Command line filter to draw/remove ASCII boxes around text | ||
* Copyright (c) 1999-2023 Thomas Jensen and the boxes contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public | ||
* License, version 3, as published by the Free Software Foundation. | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied | ||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
* details. | ||
* You should have received a copy of the GNU General Public License along with this program. | ||
* If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | ||
*/ | ||
|
||
/* | ||
* Simple makeshift log facility, mostly used for handling debug output. | ||
*/ | ||
|
||
#include <stdarg.h> | ||
#include "tools.h" | ||
#include "logging.h" | ||
|
||
log_level_t current_log_level = INFO; | ||
|
||
char *log_level_name[] = { | ||
"TRACE", "DEBUG", "INFO", "WARN", "ERROR" | ||
}; | ||
|
||
|
||
void log(log_level_t log_level, const char *module, const char *format, ...) | ||
{ | ||
char *s = (char *) malloc(512); | ||
va_list va; | ||
va_start(va, format); | ||
vsprintf(s, format, va); | ||
va_end(va); | ||
|
||
switch(log_level) { | ||
case TRACE: | ||
case DBG: | ||
if (log_level >= current_log_level) { | ||
bx_fprintf(stderr, "%5s %s: %s\n", log_level_name[log_level], module, s); | ||
} | ||
break; | ||
|
||
case INFO: | ||
if (log_level >= current_log_level) { | ||
bx_fprintf(stdout, s); | ||
} | ||
break; | ||
|
||
case WARN: | ||
case ERROR: | ||
if (log_level >= current_log_level) { | ||
bx_fprintf(stderr, "%5s: %s\n", log_level_name[log_level], s); | ||
} | ||
break; | ||
} | ||
} | ||
|
||
|
||
/* vim: set cindent sw=4: */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* boxes - Command line filter to draw/remove ASCII boxes around text | ||
* Copyright (c) 1999-2023 Thomas Jensen and the boxes contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public | ||
* License, version 3, as published by the Free Software Foundation. | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied | ||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
* details. | ||
* You should have received a copy of the GNU General Public License along with this program. | ||
* If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | ||
*/ | ||
|
||
/* | ||
* Simple makeshift log facility. | ||
*/ | ||
|
||
#ifndef LOGGING_H | ||
#define LOGGING_H | ||
|
||
|
||
typedef enum _log_level_t { | ||
/** the finest log level */ | ||
TRACE, | ||
|
||
/** a debug message, should be called `DEBUG` */ | ||
DBG, | ||
|
||
/** normal informational message */ | ||
INFO, | ||
|
||
/** a warning message, which should not happen, but can be tolerated */ | ||
WARN, | ||
|
||
/** an error message, normally this will also lead to abnormal program termination */ | ||
ERROR | ||
} log_level_t; | ||
|
||
|
||
/** currently active log level, determine whether a message gets printed */ | ||
extern log_level_t current_log_level; | ||
|
||
|
||
/** log level names for printing */ | ||
extern char *log_level_name[]; | ||
|
||
|
||
/** | ||
* Print a log message. Log messages of level INFO will be printed in `stdout`, others on `stderr`. | ||
* @param log_level the log level | ||
* @param module the module name as per `__FILE__` | ||
* @param format format string for the mesage, followed by the placeholder arguments | ||
*/ | ||
void log(log_level_t log_level, const char *module, const char *format, ...); | ||
|
||
|
||
#endif | ||
|
||
/* vim: set cindent sw=4: */ |