mirror of https://github.com/nirenjan/libx52.git
Squashed 'lib/pinelog/' changes from 27a5eab..0256807
0256807 Use strrchr only if the compiler supports __builtin_strrchr 204aade Use __builtin_strrchr to get file base name aa0a554 Remove the use of config.h 8983bf8 Ignore test and benchmark programs git-subtree-dir: lib/pinelog git-subtree-split: 02568074170f0725196de4e52450db024cc39895reverse-scroll
parent
dc72e43f1e
commit
4c9ef85223
|
@ -35,3 +35,7 @@ test-driver
|
||||||
|
|
||||||
# Build directory
|
# Build directory
|
||||||
/build/
|
/build/
|
||||||
|
|
||||||
|
# Test and benchmark programs
|
||||||
|
test_*
|
||||||
|
bench_*
|
||||||
|
|
|
@ -125,11 +125,3 @@ definitions.
|
||||||
Pinelog is intended to be integrated into your application source tree, either
|
Pinelog is intended to be integrated into your application source tree, either
|
||||||
by means of including the sources directly, or by including the repository as
|
by means of including the sources directly, or by including the repository as
|
||||||
a Git submodule or subtree.
|
a Git submodule or subtree.
|
||||||
|
|
||||||
The default build of Pinelog uses an autotools generated `config.h` file, which
|
|
||||||
includes checks for the following GCC attributes. If you don't care about these,
|
|
||||||
then either create a dummy config.h which includes the macros
|
|
||||||
`HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR`, `HAVE_FUNC_ATTRIBUTE_DESTRUCTOR` and
|
|
||||||
`HAVE_FUNC_ATTRIBUTE_FORMAT`, or use the `AX_GCC_FUNC_ATTRIBUTE` macro to check
|
|
||||||
for the `constructor`, `destructor` and `format` attributes in your
|
|
||||||
application's `configure.ac` file.
|
|
||||||
|
|
|
@ -16,14 +16,8 @@ LT_INIT
|
||||||
PKG_PROG_PKG_CONFIG
|
PKG_PROG_PKG_CONFIG
|
||||||
PKG_INSTALLDIR
|
PKG_INSTALLDIR
|
||||||
AX_COMPILER_FLAGS
|
AX_COMPILER_FLAGS
|
||||||
AX_GCC_FUNC_ATTRIBUTE([constructor])
|
|
||||||
AX_GCC_FUNC_ATTRIBUTE([destructor])
|
|
||||||
AX_GCC_FUNC_ATTRIBUTE([format])
|
|
||||||
|
|
||||||
AC_SUBST([PINELOG_CFLAGS])
|
AC_SUBST([PINELOG_CFLAGS])
|
||||||
|
|
||||||
# Configuration headers
|
|
||||||
AC_CONFIG_HEADERS([config.h])
|
|
||||||
|
|
||||||
AC_CONFIG_FILES([Makefile])
|
AC_CONFIG_FILES([Makefile])
|
||||||
AC_OUTPUT
|
AC_OUTPUT
|
||||||
|
|
17
pinelog.c
17
pinelog.c
|
@ -6,7 +6,6 @@
|
||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
@ -78,8 +77,10 @@ static FILE *output_stream = NULL;
|
||||||
static int log_level = PINELOG_DEFAULT_LEVEL;
|
static int log_level = PINELOG_DEFAULT_LEVEL;
|
||||||
|
|
||||||
/* Initialize defaults */
|
/* Initialize defaults */
|
||||||
#if HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR
|
#if defined __has_attribute
|
||||||
__attribute__((constructor))
|
# if __has_attribute(constructor)
|
||||||
|
__attribute__((constructor))
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
void pinelog_set_defaults(void)
|
void pinelog_set_defaults(void)
|
||||||
{
|
{
|
||||||
|
@ -87,8 +88,10 @@ void pinelog_set_defaults(void)
|
||||||
log_level = PINELOG_DEFAULT_LEVEL;
|
log_level = PINELOG_DEFAULT_LEVEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if HAVE_FUNC_ATTRIBUTE_DESTRUCTOR
|
#if defined __has_attribute
|
||||||
__attribute__((destructor))
|
# if __has_attribute(destructor)
|
||||||
|
__attribute__((destructor))
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
void pinelog_close_output_stream(void)
|
void pinelog_close_output_stream(void)
|
||||||
{
|
{
|
||||||
|
@ -167,7 +170,8 @@ void pinelog_log_message(int level, const char *file, int line, const char *fmt,
|
||||||
level = PINELOG_LVL_TRACE;
|
level = PINELOG_LVL_TRACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR
|
#if defined __has_attribute
|
||||||
|
#if !__has_attribute(constructor)
|
||||||
/*
|
/*
|
||||||
* Validate and set output stream. Only necessary if the compiler doesn't
|
* Validate and set output stream. Only necessary if the compiler doesn't
|
||||||
* support the constructor attribute
|
* support the constructor attribute
|
||||||
|
@ -176,6 +180,7 @@ void pinelog_log_message(int level, const char *file, int line, const char *fmt,
|
||||||
output_stream = PINELOG_DEFAULT_STREAM;
|
output_stream = PINELOG_DEFAULT_STREAM;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#if PINELOG_SHOW_DATE
|
#if PINELOG_SHOW_DATE
|
||||||
do {
|
do {
|
||||||
|
|
30
pinelog.h
30
pinelog.h
|
@ -18,7 +18,6 @@
|
||||||
#ifndef LOGGING_H
|
#ifndef LOGGING_H
|
||||||
#define LOGGING_H
|
#define LOGGING_H
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#ifndef PINELOG_TEST
|
#ifndef PINELOG_TEST
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -123,10 +122,11 @@ int pinelog_get_level(void);
|
||||||
*
|
*
|
||||||
* @returns None
|
* @returns None
|
||||||
*/
|
*/
|
||||||
#if HAVE_FUNC_ATTRIBUTE_FORMAT
|
#if defined __has_attribute
|
||||||
__attribute__((format(printf, 4, 5)))
|
# if __has_attribute(format)
|
||||||
|
__attribute__((format(printf, 4, 5)))
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void pinelog_log_message(int level, const char *file, int line, const char *fmt, ...);
|
void pinelog_log_message(int level, const char *file, int line, const char *fmt, ...);
|
||||||
|
|
||||||
// Test harness will redefine pinelog_exit
|
// Test harness will redefine pinelog_exit
|
||||||
|
@ -134,34 +134,44 @@ void pinelog_log_message(int level, const char *file, int line, const char *fmt,
|
||||||
#define pinelog_exit exit
|
#define pinelog_exit exit
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Base filename
|
||||||
|
#if defined __has_builtin
|
||||||
|
# if __has_builtin(__builtin_strrchr)
|
||||||
|
# define PINELOG_FILE __builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
#ifndef PINELOG_FILE
|
||||||
|
# define PINELOG_FILE __FILE__
|
||||||
|
#endif
|
||||||
|
|
||||||
#define PINELOG_FATAL(fmt, ...) do { \
|
#define PINELOG_FATAL(fmt, ...) do { \
|
||||||
if (PINELOG_LVL_FATAL <= pinelog_get_level()) { \
|
if (PINELOG_LVL_FATAL <= pinelog_get_level()) { \
|
||||||
pinelog_log_message(PINELOG_LVL_FATAL, __FILE__, __LINE__, fmt, ##__VA_ARGS__); \
|
pinelog_log_message(PINELOG_LVL_FATAL, PINELOG_FILE, __LINE__, fmt, ##__VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
pinelog_exit(1); \
|
pinelog_exit(1); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define PINELOG_ERROR(fmt, ...) do { \
|
#define PINELOG_ERROR(fmt, ...) do { \
|
||||||
if (PINELOG_LVL_ERROR <= pinelog_get_level()) { \
|
if (PINELOG_LVL_ERROR <= pinelog_get_level()) { \
|
||||||
pinelog_log_message(PINELOG_LVL_ERROR, __FILE__, __LINE__, fmt, ##__VA_ARGS__); \
|
pinelog_log_message(PINELOG_LVL_ERROR, PINELOG_FILE, __LINE__, fmt, ##__VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define PINELOG_WARN(fmt, ...) do { \
|
#define PINELOG_WARN(fmt, ...) do { \
|
||||||
if (PINELOG_LVL_WARNING <= pinelog_get_level()) { \
|
if (PINELOG_LVL_WARNING <= pinelog_get_level()) { \
|
||||||
pinelog_log_message(PINELOG_LVL_WARNING, __FILE__, __LINE__, fmt, ##__VA_ARGS__); \
|
pinelog_log_message(PINELOG_LVL_WARNING, PINELOG_FILE, __LINE__, fmt, ##__VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
#define PINELOG_INFO(fmt, ...) do { \
|
#define PINELOG_INFO(fmt, ...) do { \
|
||||||
if (PINELOG_LVL_INFO <= pinelog_get_level()) { \
|
if (PINELOG_LVL_INFO <= pinelog_get_level()) { \
|
||||||
pinelog_log_message(PINELOG_LVL_INFO, __FILE__, __LINE__, fmt, ##__VA_ARGS__); \
|
pinelog_log_message(PINELOG_LVL_INFO, PINELOG_FILE, __LINE__, fmt, ##__VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
#define PINELOG_DEBUG(fmt, ...) do { \
|
#define PINELOG_DEBUG(fmt, ...) do { \
|
||||||
if (PINELOG_LVL_DEBUG <= pinelog_get_level()) { \
|
if (PINELOG_LVL_DEBUG <= pinelog_get_level()) { \
|
||||||
pinelog_log_message(PINELOG_LVL_DEBUG, __FILE__, __LINE__, fmt, ##__VA_ARGS__); \
|
pinelog_log_message(PINELOG_LVL_DEBUG, PINELOG_FILE, __LINE__, fmt, ##__VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
|
@ -169,7 +179,7 @@ void pinelog_log_message(int level, const char *file, int line, const char *fmt,
|
||||||
#ifndef PINELOG_DISABLE_TRACE
|
#ifndef PINELOG_DISABLE_TRACE
|
||||||
#define PINELOG_TRACE(fmt, ...) do { \
|
#define PINELOG_TRACE(fmt, ...) do { \
|
||||||
if (PINELOG_LVL_TRACE <= pinelog_get_level()) { \
|
if (PINELOG_LVL_TRACE <= pinelog_get_level()) { \
|
||||||
pinelog_log_message(PINELOG_LVL_TRACE, __FILE__, __LINE__, fmt, ##__VA_ARGS__); \
|
pinelog_log_message(PINELOG_LVL_TRACE, PINELOG_FILE, __LINE__, fmt, ##__VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
} while(0)
|
} while(0)
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -98,9 +98,22 @@ static int test_setup(int level, int filter, const char *file, int line)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PINELOG_SHOW_BACKTRACE) {
|
if (PINELOG_SHOW_BACKTRACE) {
|
||||||
|
char * basename = NULL;
|
||||||
|
#if defined __has_builtin
|
||||||
|
#if __has_builtin(__builtin_strrchr)
|
||||||
|
basename = strrchr(file, '/');
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (basename != NULL) {
|
||||||
|
basename++;
|
||||||
|
} else {
|
||||||
|
// Override the const
|
||||||
|
basename = (char *)file;
|
||||||
|
}
|
||||||
expected_len += snprintf(&expected_output[expected_len],
|
expected_len += snprintf(&expected_output[expected_len],
|
||||||
sizeof(expected_output) - expected_len,
|
sizeof(expected_output) - expected_len,
|
||||||
"%s:%d ", file, line);
|
"%s:%d ", basename, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Reference in New Issue