Commit ebb06d72 authored by Sebastian Ramacher's avatar Sebastian Ramacher

Replace _girara_debug with girara_log

But keep old functions around until we bump the SONAME.
Signed-off-by: Sebastian Ramacher's avatarSebastian Ramacher <sebastian+dev@ramacher.at>
parent 9ee8b11b
/* See LICENSE file for license and copyright information */
#include "utils.h"
#include "log.h"
#include <stdarg.h>
#include <stdio.h>
static girara_debug_level_t debug_level = GIRARA_DEBUG;
static girara_log_level_t log_level = GIRARA_DEBUG;
void
_girara_debug(const char* function, int line, girara_debug_level_t level, const char* format, ...)
girara_vlog(const char* location, girara_log_level_t level, const char* format, va_list ap)
{
if (level < debug_level) {
if (level < log_level) {
return;
}
......@@ -25,28 +26,62 @@ _girara_debug(const char* function, int line, girara_debug_level_t level, const
fprintf(stderr, "info: ");
break;
case GIRARA_DEBUG:
fprintf(stderr, "debug: (%s:%d) ", function, line);
if (location != NULL) {
fprintf(stderr, "log: %s: ", location);
} else {
fprintf(stderr, "log: ");
}
break;
default:
return;
}
vfprintf(stderr, format, ap);
fprintf(stderr, "\n");
}
void
girara_log(const char* location, girara_log_level_t level, const char* format, ...)
{
va_list ap;
va_start(ap, format);
vfprintf(stderr, format, ap);
girara_vlog(location, level, format, ap);
va_end(ap);
}
fprintf(stderr, "\n");
girara_log_level_t
girara_get_log_level()
{
return log_level;
}
void
girara_set_log_level(girara_log_level_t level)
{
log_level = level;
}
/* old compat function, remove once we bump the SONAME */
void
_girara_log(const char* file, int line, girara_log_level_t level, const char* format, ...)
{
char* tmp = g_strdup_printf("%s:%d", file, line);
va_list ap;
va_start(ap, format);
girara_vlog(tmp, level, format, ap);
va_end(ap);
}
girara_debug_level_t
girara_log_level_t
girara_get_debug_level()
{
return debug_level;
return girara_get_log_level();
}
void
girara_set_debug_level(girara_debug_level_t level)
girara_set_debug_level(girara_log_level_t level)
{
debug_level = level;
girara_set_log_level(level);
}
/* See LICENSE file for license and copyright information */
#ifndef GIRARA_LOG_H
#define GIRARA_LOG_H
#include <glib.h>
#include <stdarg.h>
#include "types.h"
#include "macros.h"
/**
* Prints a debug message. The arguments are passed to @ref _girara_log as
* last argument.
*/
#define girara_debug(...) girara_log(G_STRLOC, GIRARA_DEBUG, __VA_ARGS__)
/**
* Prints an info message. The arguments are passed to @ref _girara_log as
* last argument.
*/
#define girara_info(...) girara_log(G_STRLOC, GIRARA_INFO, __VA_ARGS__)
/**
* Prints a warning message. The arguments are passed to @ref _girara_log as
* last argument.
*/
#define girara_warning(...) girara_log(G_STRLOC, GIRARA_WARNING, __VA_ARGS__)
/**
* Prints an error message. The arguments are passed to @ref _girara_log as
* last argument.
*/
#define girara_error(...) girara_log(G_STRLOC, GIRARA_ERROR, __VA_ARGS__)
/**
* Print a message.
*
* @param location location of the call
* @param level The log level of the message.
* @param format printf like format string
*/
void girara_log(const char* location, girara_log_level_t level,
const char* format, ...) GIRARA_PRINTF(3, 4);
/**
* Print a message.
*
* @param location location of the call
* @param level The log level of the message.
* @param format printf like format string
* @param ap varag list
*/
void girara_vlog(const char* location, girara_log_level_t level,
const char* format, va_list ap);
/**
* Get the log level.
* @returns The log level.
*/
girara_log_level_t girara_get_log_level();
/**
* Set the log level. Any message with a level lower than the log level will
* be discarded.
* @param level The new log level.
*/
void girara_set_log_level(girara_log_level_t level);
#endif
......@@ -53,15 +53,15 @@ enum
};
/**
* Debug levels
* Log levels
*/
typedef enum girara_debug_level_e
typedef enum girara_log_level_e
{
GIRARA_DEBUG, /**> Debug messages */
GIRARA_INFO, /**> Information debug output */
GIRARA_WARNING, /**> Warning level */
GIRARA_ERROR /**> Error */
} girara_debug_level_t;
} girara_log_level_t;
/**
* Mode identifier
......
......@@ -4,8 +4,10 @@
#define GIRARA_UTILS_H
#include <stdio.h>
#include "types.h"
#include "macros.h"
#include "log.h"
/**
* Enum for directories specified in the XDG specification.
......@@ -113,51 +115,6 @@ void girara_clean_line(char* line);
*/
void* girara_safe_realloc(void** ptr, size_t size) GIRARA_ALLOC_SIZE(2);
/**
* Prints a debug message. The arguments are passed to @ref _girara_debug as
* last argument.
*/
#define girara_debug(...) _girara_debug(__func__, __LINE__, GIRARA_DEBUG, __VA_ARGS__)
/**
* Prints an info message. The arguments are passed to @ref _girara_debug as
* last argument.
*/
#define girara_info(...) _girara_debug(__func__, __LINE__, GIRARA_INFO, __VA_ARGS__)
/**
* Prints a warning message. The arguments are passed to @ref _girara_debug as
* last argument.
*/
#define girara_warning(...) _girara_debug(__func__, __LINE__, GIRARA_WARNING, __VA_ARGS__)
/**
* Prints an error message. The arguments are passed to @ref _girara_debug as
* last argument.
*/
#define girara_error(...) _girara_debug(__func__, __LINE__, GIRARA_ERROR, __VA_ARGS__)
/**
* Print a message.
*
* @param function The calling function
* @param line The line of the call
* @param level The debug level of the message.
* @param format printf like format string
*/
void _girara_debug(const char* function, int line, girara_debug_level_t level,
const char* format, ...) GIRARA_PRINTF(4, 5);
/**
* Get the debug level.
* @returns The debug level.
*/
girara_debug_level_t girara_get_debug_level();
/**
* Set the debug level. Any message with a level lower than the debug level will
* be discarded.
* @param level The new debug level.
*/
void girara_set_debug_level(girara_debug_level_t level);
/**
* Escape \\, \\t, ", ' and spaces in strings.
* @param value The string to be escaped.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment