Merge log-printf.c into log.c, inline with prototypes in log.h & platform files log_*.c
This commit is contained in:
parent
3ac1d64b4f
commit
f19d233fad
3 changed files with 65 additions and 97 deletions
|
@ -40,11 +40,10 @@ if LIBUSB_ENABLED
|
|||
endif
|
||||
|
||||
if WITH_LOG
|
||||
libnfc_la_SOURCES += log-printf.c log_posix.c
|
||||
libnfc_la_SOURCES += log_posix.c
|
||||
endif
|
||||
|
||||
EXTRA_DIST = \
|
||||
CMakeLists.txt \
|
||||
log-printf.c \
|
||||
log_posix.c \
|
||||
log_win32.c
|
||||
|
|
|
@ -1,92 +0,0 @@
|
|||
/*-
|
||||
* Copyright (C) 2011 Romain Tartière
|
||||
* Copyright (C) 2011, 2012 Romuald Conty
|
||||
* Copyright (C) 2013 Alex Lian
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* 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 Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#include "log.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifndef LOG
|
||||
// Leaving in a preprocessor error, as the build system should skip this
|
||||
// file otherwise.
|
||||
#error "No logging defined, but log-printf.c still compiled."
|
||||
#else // LOG
|
||||
|
||||
// Internal methods so different platforms can route the logging
|
||||
// Offering both forms of the variadic function
|
||||
// These are implemented in the log_<platform> specific file
|
||||
void log_put_internal(const char *format, ...);
|
||||
void log_vput_internal(const char *format, va_list args);
|
||||
|
||||
void
|
||||
log_init(const nfc_context *context)
|
||||
{
|
||||
#ifdef ENVVARS
|
||||
char str[32];
|
||||
sprintf(str, "%"PRIu32, context->log_level);
|
||||
setenv("LIBNFC_LOG_LEVEL", str, 1);
|
||||
#else
|
||||
(void)context;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
log_exit(void)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
log_put(const uint8_t group, const char *category, const uint8_t priority, const char *format, ...)
|
||||
{
|
||||
char *env_log_level = NULL;
|
||||
#ifdef ENVVARS
|
||||
env_log_level = getenv("LIBNFC_LOG_LEVEL");
|
||||
#endif
|
||||
uint32_t log_level;
|
||||
if (NULL == env_log_level) {
|
||||
// LIBNFC_LOG_LEVEL is not set
|
||||
#ifdef DEBUG
|
||||
log_level = 3;
|
||||
#else
|
||||
log_level = 1;
|
||||
#endif
|
||||
} else {
|
||||
log_level = atoi(env_log_level);
|
||||
}
|
||||
|
||||
// printf("log_level = %"PRIu32" group = %"PRIu8" priority = %"PRIu8"\n", log_level, group, priority);
|
||||
if (log_level) { // If log is not disabled by log_level=none
|
||||
if (((log_level & 0x00000003) >= priority) || // Global log level
|
||||
(((log_level >> (group * 2)) & 0x00000003) >= priority)) { // Group log level
|
||||
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
log_put_internal("%s\t%s\t", log_priority_to_str(priority), category);
|
||||
log_vput_internal(format, va);
|
||||
log_put_internal("\n");
|
||||
va_end(va);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // LOG
|
67
libnfc/log.c
67
libnfc/log.c
|
@ -16,12 +16,13 @@
|
|||
*/
|
||||
|
||||
#include "log.h"
|
||||
/*
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
/*
|
||||
int
|
||||
|
@ -70,3 +71,63 @@ log_priority_to_str(const int priority)
|
|||
return "unknown";
|
||||
}
|
||||
|
||||
|
||||
#ifdef LOG
|
||||
// Internal methods so different platforms can route the logging
|
||||
// Offering both forms of the variadic function
|
||||
// These are implemented in the log_<platform> specific file
|
||||
void log_put_internal(const char *format, ...);
|
||||
void log_vput_internal(const char *format, va_list args);
|
||||
|
||||
void
|
||||
log_init(const nfc_context *context)
|
||||
{
|
||||
#ifdef ENVVARS
|
||||
char str[32];
|
||||
sprintf(str, "%"PRIu32, context->log_level);
|
||||
setenv("LIBNFC_LOG_LEVEL", str, 1);
|
||||
#else
|
||||
(void)context;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
log_exit(void)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
log_put(const uint8_t group, const char *category, const uint8_t priority, const char *format, ...)
|
||||
{
|
||||
char *env_log_level = NULL;
|
||||
#ifdef ENVVARS
|
||||
env_log_level = getenv("LIBNFC_LOG_LEVEL");
|
||||
#endif
|
||||
uint32_t log_level;
|
||||
if (NULL == env_log_level) {
|
||||
// LIBNFC_LOG_LEVEL is not set
|
||||
#ifdef DEBUG
|
||||
log_level = 3;
|
||||
#else
|
||||
log_level = 1;
|
||||
#endif
|
||||
} else {
|
||||
log_level = atoi(env_log_level);
|
||||
}
|
||||
|
||||
// printf("log_level = %"PRIu32" group = %"PRIu8" priority = %"PRIu8"\n", log_level, group, priority);
|
||||
if (log_level) { // If log is not disabled by log_level=none
|
||||
if (((log_level & 0x00000003) >= priority) || // Global log level
|
||||
(((log_level >> (group * 2)) & 0x00000003) >= priority)) { // Group log level
|
||||
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
log_put_internal("%s\t%s\t", log_priority_to_str(priority), category);
|
||||
log_vput_internal(format, va);
|
||||
log_put_internal("\n");
|
||||
va_end(va);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // LOG
|
||||
|
|
Loading…
Reference in a new issue