Split logging internals so that platforms may choose additional or alternate spew mechanisms
In the case of windows, allow for the OutputDebugString call in addition to logging to stderr. Useful for the dll scenario and debugging in Visual Studio.
This commit is contained in:
parent
563054d2a2
commit
b3c6ea86ad
5 changed files with 122 additions and 5 deletions
|
@ -46,7 +46,12 @@ SET(LIBRARY_SOURCES nfc nfc-device nfc-emulation nfc-internal conf iso14443-subr
|
|||
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
IF(LIBNFC_LOG)
|
||||
LIST(APPEND LIBRARY_SOURCES log-printf)
|
||||
IF(WIN32)
|
||||
SET(CMAKE_C_FLAGS "-fgnu89-inline ${CMAKE_C_FLAGS}")
|
||||
LIST(APPEND LIBRARY_SOURCES log-printf log_win32)
|
||||
ELSE(WIN32)
|
||||
LIST(APPEND LIBRARY_SOURCES log-printf log_posix)
|
||||
ENDIF(WIN32)
|
||||
ENDIF(LIBNFC_LOG)
|
||||
ADD_LIBRARY(nfc SHARED ${LIBRARY_SOURCES})
|
||||
|
||||
|
|
|
@ -45,5 +45,7 @@ endif
|
|||
|
||||
EXTRA_DIST = \
|
||||
CMakeLists.txt \
|
||||
log-printf.c
|
||||
log-printf.c \
|
||||
log_posix.c \
|
||||
log_win32.c
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/*-
|
||||
* 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
|
||||
|
@ -31,6 +32,12 @@
|
|||
#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)
|
||||
{
|
||||
|
@ -71,11 +78,17 @@ log_put(const uint8_t group, const char *category, const uint8_t priority, const
|
|||
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);
|
||||
fprintf(stderr, "%s\t%s\t", log_priority_to_str(priority), category);
|
||||
vfprintf(stderr, format, va);
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
// fprintf(stderr, "%s\t%s\t", log_priority_to_str(priority), category);
|
||||
// vfprintf(stderr, format, va);
|
||||
// fprintf(stderr, "\n");
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
41
libnfc/log_posix.c
Normal file
41
libnfc/log_posix.c
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*-
|
||||
* 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>
|
||||
|
||||
void
|
||||
log_vput_internal(const char *format, va_list args)
|
||||
{
|
||||
vfprintf(stderr, format, args);
|
||||
}
|
||||
|
||||
void
|
||||
log_put_internal(const char *format, ...)
|
||||
{
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
vfprintf(stderr, format, va);
|
||||
va_end(va);
|
||||
}
|
56
libnfc/log_win32.c
Normal file
56
libnfc/log_win32.c
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*-
|
||||
* 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 <strsafe.h>
|
||||
|
||||
void
|
||||
log_output_debug(const char *format, va_list args)
|
||||
{
|
||||
char buffer[1024];
|
||||
HRESULT hr = StringCbVPrintf( buffer, sizeof( buffer ), format, args );
|
||||
// Spew what we got, even if the buffer is not sized large enough
|
||||
if ( (STRSAFE_E_INSUFFICIENT_BUFFER == hr) || (S_OK == hr) )
|
||||
OutputDebugString( buffer );
|
||||
}
|
||||
|
||||
void
|
||||
log_vput_internal(const char *format, va_list args)
|
||||
{
|
||||
vfprintf(stderr, format, args);
|
||||
// Additional windows output to the debug window for debugging purposes
|
||||
log_output_debug(format, args);
|
||||
}
|
||||
|
||||
void
|
||||
log_put_internal(const char *format, ...)
|
||||
{
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
vfprintf(stderr, format, va);
|
||||
// Additional windows output to the debug window for debugging purposes
|
||||
log_output_debug(format, va);
|
||||
va_end(va);
|
||||
}
|
Loading…
Reference in a new issue