/**
* API version
*/
-#define DBDRV_API_VERSION 17
+#define DBDRV_API_VERSION 18
//
void LIBNETXMS_EXPORTABLE ThreadPoolGetInfo(ThreadPool *p, ThreadPoolInfo *info);
bool LIBNETXMS_EXPORTABLE ThreadPoolGetInfo(const TCHAR *name, ThreadPoolInfo *info);
StringList LIBNETXMS_EXPORTABLE *ThreadPoolGetAllPools();
-void LIBNETXMS_EXPORTABLE ThreadPoolSetDebugCallback(void (*cb)(int, const TCHAR *, va_list));
/**
* Wrapper data for ThreadPoolExecute
TCHAR LIBNETXMS_EXPORTABLE *safe_fgetts(TCHAR *buffer, int len, FILE *f);
-BOOL LIBNETXMS_EXPORTABLE nxlog_open(const TCHAR *logName, UINT32 flags, const TCHAR *msgModule,
- unsigned int msgCount, const TCHAR **messages);
+bool LIBNETXMS_EXPORTABLE nxlog_open(const TCHAR *logName, UINT32 flags, const TCHAR *msgModule,
+ unsigned int msgCount, const TCHAR **messages, DWORD debugMsg);
void LIBNETXMS_EXPORTABLE nxlog_close(void);
void LIBNETXMS_EXPORTABLE nxlog_write(DWORD msg, WORD wType, const char *format, ...);
-BOOL LIBNETXMS_EXPORTABLE nxlog_set_rotation_policy(int rotationMode, int maxLogSize, int historySize, const TCHAR *dailySuffix);
-BOOL LIBNETXMS_EXPORTABLE nxlog_rotate();
+void LIBNETXMS_EXPORTABLE nxlog_debug(int level, const TCHAR *format, ...);
+void LIBNETXMS_EXPORTABLE nxlog_debug2(int level, const TCHAR *format, va_list args);
+bool LIBNETXMS_EXPORTABLE nxlog_set_rotation_policy(int rotationMode, int maxLogSize, int historySize, const TCHAR *dailySuffix);
+bool LIBNETXMS_EXPORTABLE nxlog_rotate();
+void LIBNETXMS_EXPORTABLE nxlog_set_debug_level(int level);
+int LIBNETXMS_EXPORTABLE nxlog_get_debug_level();
typedef void (*NxLogConsoleWriter)(const TCHAR *, ...);
void LIBNETXMS_EXPORTABLE nxlog_set_console_writer(NxLogConsoleWriter writer);
MUTEX mutex, NXCPCompressionMethod compressionMethod = NXCP_COMPRESSION_NONE);
BOOL LIBNETXMS_EXPORTABLE NXCPGetPeerProtocolVersion(SOCKET hSocket, int *pnVersion, MUTEX mutex);
-bool LIBNETXMS_EXPORTABLE InitCryptoLib(UINT32 dwEnabledCiphers, void (*debugCallback)(int, const TCHAR *, va_list args));
+bool LIBNETXMS_EXPORTABLE InitCryptoLib(UINT32 dwEnabledCiphers);
UINT32 LIBNETXMS_EXPORTABLE NXCPGetSupportedCiphers();
String LIBNETXMS_EXPORTABLE NXCPGetSupportedCiphersAsText();
NXCP_ENCRYPTED_MESSAGE LIBNETXMS_EXPORTABLE *NXCPEncryptMessage(NXCPEncryptionContext *pCtx, NXCP_MESSAGE *pMsg);
int LIBNXDB_EXPORTABLE DBConnectionPoolGetAcquiredCount();
void LIBNXDB_EXPORTABLE DBSetLongRunningThreshold(UINT32 threshold);
-void LIBNXDB_EXPORTABLE DBSetDebugPrintCallback(void (*cb)(int, const TCHAR *, va_list));
ObjectArray<PoolConnectionInfo> LIBNXDB_EXPORTABLE *DBConnectionPoolGetConnectionList();
void LIBNXDB_EXPORTABLE DBGetPerfCounters(LIBNXDB_PERF_COUNTERS *counters);
*/
bool OpenLocalDatabase()
{
- s_driver = DBLoadDriver(_T("sqlite.ddr"), _T(""), g_debugLevel == 9, NULL, NULL);
+ s_driver = DBLoadDriver(_T("sqlite.ddr"), _T(""), nxlog_get_debug_level() == 9, NULL, NULL);
if (s_driver == NULL)
{
return false;
UINT32 g_dwStartupDelay = 0;
UINT32 g_dwMaxSessions = 32;
UINT32 g_dwSNMPTrapPort = 162;
-UINT32 g_debugLevel = (UINT32)NXCONFIG_UNINITIALIZED_VALUE;
#ifdef _WIN32
UINT16 g_sessionAgentPort = 28180;
#else
static TCHAR s_dailyLogFileSuffix[64] = _T("");
static Config *s_registry = NULL;
static TCHAR s_executableName[MAX_PATH];
+static UINT32 s_debugLevel = (UINT32)NXCONFIG_UNINITIALIZED_VALUE;
static CONDITION s_subAgentsStopCondition = INVALID_CONDITION_HANDLE;
#if defined(_WIN32)
{ _T("CreateCrashDumps"), CT_BOOLEAN, 0, 0, AF_CATCH_EXCEPTIONS, 0, &g_dwFlags, NULL },
{ _T("DataDirectory"), CT_STRING, 0, 0, MAX_PATH, 0, g_szDataDirectory, NULL },
{ _T("DailyLogFileSuffix"), CT_STRING, 0, 0, 64, 0, s_dailyLogFileSuffix, NULL },
- { _T("DebugLevel"), CT_LONG, 0, 0, 0, 0, &g_debugLevel, &g_debugLevel },
+ { _T("DebugLevel"), CT_LONG, 0, 0, 0, 0, &s_debugLevel, &s_debugLevel },
{ _T("DisableIPv4"), CT_BOOLEAN, 0, 0, AF_DISABLE_IPV4, 0, &g_dwFlags, NULL },
{ _T("DisableIPv6"), CT_BOOLEAN, 0, 0, AF_DISABLE_IPV6, 0, &g_dwFlags, NULL },
{ _T("DumpDirectory"), CT_STRING, 0, 0, MAX_PATH, 0, s_dumpDir, NULL },
(g_dwFlags & AF_CENTRAL_CONFIG) ? _T("-M ") : _T(""),
(g_dwFlags & AF_CENTRAL_CONFIG) ? g_szConfigServer : _T(""),
(g_dwFlags & AF_CENTRAL_CONFIG) ? _T(" ") : _T(""),
- g_debugLevel, szPlatformSuffixOption,
+ s_debugLevel, szPlatformSuffixOption,
(g_dwFlags & AF_DAEMON) ? 0 : GetCurrentProcessId());
DebugPrintf(INVALID_INDEX, 1, _T("Restarting agent with command line '%s'"), szCmdLine);
(g_dwFlags & AF_CENTRAL_CONFIG) ? _T("-M ") : _T(""),
(g_dwFlags & AF_CENTRAL_CONFIG) ? g_szConfigServer : _T(""),
(g_dwFlags & AF_CENTRAL_CONFIG) ? _T(" ") : _T(""),
- (int)g_debugLevel, szPlatformSuffixOption,
+ (int)s_debugLevel, szPlatformSuffixOption,
(unsigned long)s_pid);
DebugPrintf(INVALID_INDEX, 1, _T("Restarting agent with command line '%s'"), szCmdLine);
return ExecuteCommand(szCmdLine, NULL, NULL);
{
if (logLevel == EVENTLOG_DEBUG_TYPE)
{
- if (debugLevel <= (int)g_debugLevel)
+ if (debugLevel <= (int)s_debugLevel)
nxlog_write(MSG_DEBUG, EVENTLOG_DEBUG_TYPE, "s", pszMsg);
}
else
TCHAR *pItem, *pEnd;
TCHAR regPath[MAX_PATH];
- if (g_debugLevel == (UINT32)NXCONFIG_UNINITIALIZED_VALUE)
- g_debugLevel = 0;
+ if (s_debugLevel == (UINT32)NXCONFIG_UNINITIALIZED_VALUE)
+ s_debugLevel = 0;
if (!_tcscmp(g_szDataDirectory, _T("{default}")))
{
((g_dwFlags & AF_DAEMON) ? 0 : NXLOG_PRINT_TO_STDOUT),
_T("NXAGENTD.EXE"),
#ifdef _WIN32
- 0, NULL))
+ 0, NULL, MSG_DEBUG))
#else
- g_dwNumMessages, g_szMessages))
+ g_dwNumMessages, g_szMessages, MSG_DEBUG))
#endif
{
_ftprintf(stderr, _T("FATAL ERROR: Cannot open log file\n"));
return FALSE;
}
nxlog_write(MSG_USE_CONFIG_D, NXLOG_INFO, "s", g_szConfigIncludeDir);
- nxlog_write(MSG_DEBUG_LEVEL, NXLOG_INFO, "d", g_debugLevel);
-
- ThreadPoolSetDebugCallback(DebugPrintfCallback);
+ nxlog_write(MSG_DEBUG_LEVEL, NXLOG_INFO, "d", s_debugLevel);
+ nxlog_set_debug_level(s_debugLevel);
if (_tcscmp(g_masterAgent, _T("not_set")))
{
DebugPrintf(INVALID_INDEX, 1, _T("Subagent API initialized"));
// Initialize cryptografy
- if (!InitCryptoLib(s_enabledCiphers, DebugPrintfCallback))
+ if (!InitCryptoLib(s_enabledCiphers))
{
nxlog_write(MSG_INIT_CRYPTO_FAILED, EVENTLOG_ERROR_TYPE, "e", WSAGetLastError());
return FALSE;
SSL_load_error_strings();
#endif
- DBSetDebugPrintCallback(DebugPrintfCallback);
DBInit(MSG_DB_LIBRARY, MSG_SQL_ERROR);
if (!OpenLocalDatabase())
g_dwFlags |= AF_DAEMON;
break;
case 'D': // Turn on debug output
- g_debugLevel = strtoul(optarg, &eptr, 0);
- if ((*eptr != 0) || (g_debugLevel > 9))
+ s_debugLevel = strtoul(optarg, &eptr, 0);
+ if ((*eptr != 0) || (s_debugLevel > 9))
{
fprintf(stderr, "Invalid debug level: %s\n", optarg);
iAction = -1;
if (g_dwFlags & AF_CENTRAL_CONFIG)
{
- if (g_debugLevel > 0)
+ if (s_debugLevel > 0)
_tprintf(_T("Downloading configuration from %s...\n"), g_szConfigServer);
if (DownloadConfig(g_szConfigServer))
{
- if (g_debugLevel > 0)
+ if (s_debugLevel > 0)
_tprintf(_T("Configuration downloaded successfully\n"));
}
else
{
- if (g_debugLevel > 0)
+ if (s_debugLevel > 0)
_tprintf(_T("Configuration download failed\n"));
}
}
#endif
;
-void DebugPrintfCallback(int level, const TCHAR *pszFormat, va_list args);
-
void BuildFullPath(TCHAR *pszFileName, TCHAR *pszFullPath);
BOOL DownloadConfig(TCHAR *pszServer);
extern UINT32 g_dwMaxSessions;
extern UINT32 g_dwExecTimeout;
extern UINT32 g_dwSNMPTimeout;
-extern UINT32 g_debugLevel;
extern UINT32 g_dwSNMPTrapPort;
extern UINT16 g_sessionAgentPort;
continue; // Bad packet, wait for next
}
- if (g_debugLevel >= 8)
+ if (nxlog_get_debug_level() >= 8)
{
String msgDump = NXCPMessage::dump(rawMsg, NXCP_VERSION);
DebugPrintf(INVALID_INDEX, 8, _T("SA-%d: Message dump:\n%s"), m_id, (const TCHAR *)msgDump);
// Update activity timestamp
m_ts = time(NULL);
- if (g_debugLevel >= 8)
+ if (nxlog_get_debug_level() >= 8)
{
String msgDump = NXCPMessage::dump(receiver.getRawMessageBuffer(), NXCP_VERSION);
DebugPrintf(m_dwIndex, 8, _T("Message dump:\n%s"), (const TCHAR *)msgDump);
*/
void DebugPrintf(UINT32 dwSessionId, int level, const TCHAR *pszFormat, ...)
{
- if (level <= (int)g_debugLevel)
+ if (level <= nxlog_get_debug_level())
{
va_list args;
TCHAR szBuffer[4096];
}
}
-/**
- * Print debug messages - callback for libraries
- */
-void DebugPrintfCallback(int level, const TCHAR *pszFormat, va_list args)
-{
- if (level <= (int)g_debugLevel)
- {
- TCHAR szBuffer[4096];
- _vsntprintf(szBuffer, 4096, pszFormat, args);
- nxlog_write(MSG_DEBUG, EVENTLOG_DEBUG_TYPE, "s", szBuffer);
- }
-}
-
/**
* Build full path for file in file store
*/
(g_dwFlags & AF_CENTRAL_CONFIG) ? _T("-M ") : _T(""),
(g_dwFlags & AF_CENTRAL_CONFIG) ? g_szConfigServer : _T(""),
(g_dwFlags & AF_CENTRAL_CONFIG) ? _T(" ") : _T(""),
- g_debugLevel, szPlatformSuffixOption,
+ nxlog_get_debug_level(), szPlatformSuffixOption,
(g_dwFlags & AF_DAEMON) ? 0 : GetCurrentProcessId());
DebugPrintf(INVALID_INDEX, 1, _T("Starting agent watchdog with command line '%s'"), szCmdLine);
(g_dwFlags & AF_CENTRAL_CONFIG) ? _T("-M ") : _T(""),
(g_dwFlags & AF_CENTRAL_CONFIG) ? g_szConfigServer : _T(""),
(g_dwFlags & AF_CENTRAL_CONFIG) ? _T(" ") : _T(""),
- g_debugLevel, szPlatformSuffixOption,
+ nxlog_get_debug_level(), szPlatformSuffixOption,
(unsigned long)getpid());
if (ExecuteCommand(szCmdLine, NULL, &m_pidWatchdogProcess) == ERR_SUCCESS)
{
(g_dwFlags & AF_CENTRAL_CONFIG) ? _T("-M ") : _T(""),
(g_dwFlags & AF_CENTRAL_CONFIG) ? g_szConfigServer : _T(""),
(g_dwFlags & AF_CENTRAL_CONFIG) ? _T(" ") : _T(""),
- g_debugLevel, szPlatformSuffixOption);
+ nxlog_get_debug_level(), szPlatformSuffixOption);
#ifdef UNICODE
syslog(LOG_INFO, "command line: %ls", cmdLine);
#else
s_debugCallback(buffer);
}
-/**
- * Debug callback for crypto lib
- */
-static void CryptoLibDebugCallback(int level, const TCHAR *format, va_list args)
-{
- if (s_debugCallback == NULL)
- return;
-
- TCHAR buffer[4096];
- _vsntprintf(buffer, 4096, format, args);
- s_debugCallback(buffer);
-}
-
/**
* Initialization function
*/
bool LIBNXCLIENT_EXPORTABLE NXCInitialize()
{
- return InitCryptoLib(0xFFFF, CryptoLibDebugCallback);
+ return InitCryptoLib(0xFFFF);
}
/**
/**
* Initialize driver
*/
-extern "C" bool EXPORT DrvInit(const char *cmdLine, void (*dbgPrintCb)(int, const TCHAR *, va_list))
+extern "C" bool EXPORT DrvInit(const char *cmdLine)
{
return true;
}
/**
* Initialize driver
*/
-extern "C" bool EXPORT DrvInit(const char *cmdLine, void (*dbgPrintCb)(int, const TCHAR *, va_list))
+extern "C" bool EXPORT DrvInit(const char *cmdLine)
{
return true;
}
/**
* Initialize driver
*/
-extern "C" bool EXPORT DrvInit(const char *cmdLine, void (*dbgPrintCb)(int, const TCHAR *, va_list))
+extern "C" bool EXPORT DrvInit(const char *cmdLine)
{
// Allocate environment
SQLHENV sqlEnv;
/**
* Initialize driver
*/
-extern "C" bool EXPORT DrvInit(const char *cmdLine, void (*dbgPrintCb)(int, const TCHAR *, va_list))
+extern "C" bool EXPORT DrvInit(const char *cmdLine)
{
return mysql_library_init(0, NULL, NULL) == 0;
}
/**
* Initialize driver
*/
-extern "C" bool EXPORT DrvInit(const char *cmdLine, void (*dbgPrintCb)(int, const TCHAR *, va_list))
+extern "C" bool EXPORT DrvInit(const char *cmdLine)
{
m_useUnicode = ExtractNamedOptionValueAsBoolA(cmdLine, "unicode", true);
return true;
/**
* Initialize driver
*/
-extern "C" bool EXPORT DrvInit(const char *cmdLine, void (*dbgPrintCb)(int, const TCHAR *, va_list))
+extern "C" bool EXPORT DrvInit(const char *cmdLine)
{
return true;
}
// Setup session
DrvQueryInternal(pConn, L"ALTER SESSION SET NLS_LANGUAGE='AMERICAN' NLS_NUMERIC_CHARACTERS='.,'", NULL);
+
+ UCS2CHAR version[1024];
+ if (OCIServerVersion(pConn->handleService, pConn->handleError, (OraText *)version, sizeof(version), OCI_HTYPE_SVCCTX) == OCI_SUCCESS)
+ {
+#if UNICODE_UCS4
+ WCHAR *wver = UCS4StringFromUCS2String(version);
+ nxlog_debug(5, _T("ORACLE: connected to %s"), wver);
+ free(wver);
+#else
+ nxlog_debug(5, _T("ORACLE: connected to %s"), version);
+#endif
+ }
}
else
{
/*
** PostgreSQL Database Driver
-** Copyright (C) 2003 - 2014 Victor Kirhenshtein and Alex Kirhenshtein
+** Copyright (C) 2003 - 2016 Victor Kirhenshtein and Alex Kirhenshtein
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
#define PGRES_SINGLE_TUPLE 9
#endif
-/**
- * Debug log callback
- */
-static void (*s_dbgPrintCb)(int, const TCHAR *, va_list) = NULL;
-
-/**
- * Debug output
- */
-static void __DbgPrintf(int level, const TCHAR *format, ...)
-{
- if (s_dbgPrintCb != NULL)
- {
- va_list args;
- va_start(args, format);
- s_dbgPrintCb(level, format, args);
- va_end(args);
- }
-}
-
/**
* Statement ID
*/
/**
* Initialize driver
*/
-extern "C" bool EXPORT DrvInit(const char *cmdLine, void (*dbgPrintCb)(int, const TCHAR *, va_list))
+extern "C" bool EXPORT DrvInit(const char *cmdLine)
{
- s_dbgPrintCb = dbgPrintCb;
#ifndef _WIN32
s_libpq = dlopen("libpq.so.5", RTLD_NOW);
if (s_libpq != NULL)
s_PQsetSingleRowMode = (int (*)(PGconn *))dlsym(s_libpq, "PQsetSingleRowMode");
- __DbgPrintf(2, _T("PostgreSQL driver: single row mode %s"), (s_PQsetSingleRowMode != NULL) ? _T("enabled") : _T("disabled"));
+ nxlog_debug(2, _T("PostgreSQL driver: single row mode %s"), (s_PQsetSingleRowMode != NULL) ? _T("enabled") : _T("disabled"));
#endif
return true;
}
/*
** SQLite Database Driver
-** Copyright (C) 2005-2014 Victor Kirhenshtein
+** Copyright (C) 2005-2016 Victor Kirhenshtein
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
/**
* Initialize driver
*/
-extern "C" bool EXPORT DrvInit(const char *cmdLine, void (*dbgPrintCb)(int, const TCHAR *, va_list))
+extern "C" bool EXPORT DrvInit(const char *cmdLine)
{
if (!sqlite3_threadsafe() || // Fail if SQLite compiled without threading support
(sqlite3_initialize() != SQLITE_OK))
return false;
sqlite3_enable_shared_cache(1);
+ nxlog_debug(1, _T("SQLite version %hs"), sqlite3_libversion());
return true;
}
}
else
{
- __DBDbgPrintf(3, _T("Database Connection Pool: cannot create DB connection %d (%s)"), i, errorText);
+ nxlog_debug(3, _T("Database Connection Pool: cannot create DB connection %d (%s)"), i, errorText);
delete conn;
}
}
conn->lastAccessTime = now;
conn->usageCount = 0;
- __DBDbgPrintf(3, _T("Database Connection Pool: connection %p reconnected"), conn->handle);
+ nxlog_debug(3, _T("Database Connection Pool: connection %p reconnected"), conn->handle);
return true;
}
else
{
- __DBDbgPrintf(3, _T("Database Connection Pool: connection %p reconnect failure (%s)"), conn->handle, errorText);
+ nxlog_debug(3, _T("Database Connection Pool: connection %p reconnect failure (%s)"), conn->handle, errorText);
return false;
}
}
*/
static THREAD_RESULT THREAD_CALL MaintenanceThread(void *arg)
{
- __DBDbgPrintf(1, _T("Database Connection Pool maintenance thread started"));
+ nxlog_debug(1, _T("Database Connection Pool maintenance thread started"));
while(!ConditionWait(m_condShutdown, (m_connectionTTL > 0) ? m_connectionTTL * 750 : 300000))
{
}
}
- __DBDbgPrintf(1, _T("Database Connection Pool maintenance thread stopped"));
+ nxlog_debug(1, _T("Database Connection Pool maintenance thread stopped"));
return THREAD_OK;
}
m_maintThread = ThreadCreateEx(MaintenanceThread, 0, NULL);
s_initialized = true;
- __DBDbgPrintf(1, _T("Database Connection Pool initialized"));
+ nxlog_debug(1, _T("Database Connection Pool initialized"));
return true;
}
m_connections.clear();
s_initialized = false;
- __DBDbgPrintf(1, _T("Database Connection Pool terminated"));
+ nxlog_debug(1, _T("Database Connection Pool terminated"));
}
}
else
{
- __DBDbgPrintf(3, _T("Database Connection Pool: cannot create additional DB connection (%s)"), errorText);
+ nxlog_debug(3, _T("Database Connection Pool: cannot create additional DB connection (%s)"), errorText);
delete conn;
}
}
if (handle == NULL)
{
- __DBDbgPrintf(1, _T("Database Connection Pool exhausted (call from %hs:%d)"), srcFile, srcLine);
+ nxlog_debug(1, _T("Database Connection Pool exhausted (call from %hs:%d)"), srcFile, srcLine);
ConditionWait(m_condRelease, 10000);
- __DBDbgPrintf(5, _T("Database Connection Pool: retry acquire connection (call from %hs:%d)"), srcFile, srcLine);
+ nxlog_debug(5, _T("Database Connection Pool: retry acquire connection (call from %hs:%d)"), srcFile, srcLine);
goto retry;
}
- __DBDbgPrintf(7, _T("Database Connection Pool: handle %p acquired (call from %hs:%d)"), handle, srcFile, srcLine);
+ nxlog_debug(7, _T("Database Connection Pool: handle %p acquired (call from %hs:%d)"), handle, srcFile, srcLine);
return handle;
}
MutexUnlock(m_poolAccessMutex);
- __DBDbgPrintf(7, _T("Database Connection Pool: handle %p released"), handle);
+ nxlog_debug(7, _T("Database Connection Pool: handle %p released"), handle);
ConditionPulse(m_condRelease);
}
void *userArg)
{
static DWORD dwVersionZero = 0;
- bool (* fpDrvInit)(const char *, void (*)(int, const TCHAR *, va_list));
+ bool (* fpDrvInit)(const char *);
DWORD *pdwAPIVersion;
TCHAR szErrorText[256];
const char *driverName;
}
// Import symbols
- fpDrvInit = (bool (*)(const char *, void (*)(int, const TCHAR *, va_list)))DLGetSymbolAddrEx(driver->m_handle, "DrvInit");
+ fpDrvInit = (bool (*)(const char *))DLGetSymbolAddrEx(driver->m_handle, "DrvInit");
driver->m_fpDrvConnect = (DBDRV_CONNECTION (*)(const char *, const char *, const char *, const char *, const char *, WCHAR *))DLGetSymbolAddrEx(driver->m_handle, "DrvConnect");
driver->m_fpDrvDisconnect = (void (*)(DBDRV_CONNECTION))DLGetSymbolAddrEx(driver->m_handle, "DrvDisconnect");
driver->m_fpDrvSetPrefetchLimit = (bool (*)(DBDRV_CONNECTION, int))DLGetSymbolAddrEx(driver->m_handle, "DrvSetPrefetchLimit", false);
{
mbInitParameters[0] = 0;
}
- if (!fpDrvInit(mbInitParameters, (void (*)(int, const TCHAR *, va_list))__DBGetDebugPrintCallback()))
+ if (!fpDrvInit(mbInitParameters))
#else
- if (!fpDrvInit(CHECK_NULL_EX(initParameters), (void (*)(int, const TCHAR *, va_list))__DBGetDebugPrintCallback()))
+ if (!fpDrvInit(CHECK_NULL_EX(initParameters)))
#endif
{
if (s_writeLog)
* Internal functions
*/
void __DBWriteLog(WORD level, const TCHAR *format, ...);
-void __DBDbgPrintf(int level, const TCHAR *format, ...);
-void *__DBGetDebugPrintCallback();
/**
* Global variables
/*
** NetXMS - Network Management System
** Database Abstraction Library
-** Copyright (C) 2003-2010 Victor Kirhenshtein
+** Copyright (C) 2003-2016 Victor Kirhenshtein
**
** 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
#include "libnxdb.h"
-/**
- * Debug log callback
- */
-static void (*s_dbgPrintCb)(int, const TCHAR *, va_list) = NULL;
-
/**
* Write log
*/
nxlog_write(g_logMsgCode, level, "s", buffer);
}
-/**
- * Debug output
- */
-void __DBDbgPrintf(int level, const TCHAR *format, ...)
-{
- if (s_dbgPrintCb != NULL)
- {
- va_list args;
-
- va_start(args, format);
- s_dbgPrintCb(level, format, args);
- va_end(args);
- }
-}
-
-/**
- * Set debug print callback
- */
-void LIBNXDB_EXPORTABLE DBSetDebugPrintCallback(void (*cb)(int, const TCHAR *, va_list))
-{
- s_dbgPrintCb = cb;
- __DBDbgPrintf(1, _T("Debug callback set for DB library"));
-}
-
-/**
- * Set debug print callback
- */
-void *__DBGetDebugPrintCallback()
-{
- return (void *)s_dbgPrintCb;
-}
-
/**
* Set long running query threshold (milliseconds)
*/
void LIBNXDB_EXPORTABLE DBSetLongRunningThreshold(UINT32 threshold)
{
g_sqlQueryExecTimeThreshold = threshold;
- __DBDbgPrintf(3, _T("DB Library: long running query threshold set to %u"), threshold);
+ nxlog_debug(3, _T("DB Library: long running query threshold set to %u"), threshold);
}
#ifdef _WIN32
/*
** NetXMS - Network Management System
** Database Abstraction Library
-** Copyright (C) 2003-2015 Victor Kirhenshtein
+** Copyright (C) 2003-2016 Victor Kirhenshtein
**
** 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
DBDRV_CONNECTION hDrvConn;
DB_HANDLE hConn = NULL;
- __DBDbgPrintf(8, _T("DBConnect: server=%s db=%s login=%s schema=%s"), CHECK_NULL(server), CHECK_NULL(dbName), CHECK_NULL(login), CHECK_NULL(schema));
+ nxlog_debug(8, _T("DBConnect: server=%s db=%s login=%s schema=%s"), CHECK_NULL(server), CHECK_NULL(dbName), CHECK_NULL(login), CHECK_NULL(schema));
#ifdef UNICODE
char *mbServer = (server == NULL) ? NULL : MBStringFromWideString(server);
char *mbDatabase = (dbName == NULL) ? NULL : MBStringFromWideString(dbName);
#endif
if (driver->m_fpDrvSetPrefetchLimit != NULL)
driver->m_fpDrvSetPrefetchLimit(hDrvConn, driver->m_defaultPrefetchLimit);
- __DBDbgPrintf(4, _T("New DB connection opened: handle=%p"), hConn);
+ nxlog_debug(4, _T("New DB connection opened: handle=%p"), hConn);
if (s_sessionInitCb != NULL)
s_sessionInitCb(hConn);
}
if (hConn == NULL)
return;
- __DBDbgPrintf(4, _T("DB connection %p closed"), hConn);
+ nxlog_debug(4, _T("DB connection %p closed"), hConn);
InvalidatePreparedStatements(hConn);
int nCount;
WCHAR errorText[DBDRV_MAX_ERROR_TEXT];
- __DBDbgPrintf(4, _T("DB reconnect: handle=%p"), hConn);
+ nxlog_debug(4, _T("DB reconnect: handle=%p"), hConn);
InvalidatePreparedStatements(hConn);
hConn->m_driver->m_fpDrvDisconnect(hConn->m_connection);
ms = GetCurrentTimeMs() - ms;
if (hConn->m_driver->m_dumpSql)
{
- __DBDbgPrintf(9, _T("%s sync query: \"%s\" [%d ms]"), (dwResult == DBERR_SUCCESS) ? _T("Successful") : _T("Failed"), szQuery, ms);
+ nxlog_debug(9, _T("%s sync query: \"%s\" [%d ms]"), (dwResult == DBERR_SUCCESS) ? _T("Successful") : _T("Failed"), szQuery, ms);
}
if ((dwResult == DBERR_SUCCESS) && ((UINT32)ms > g_sqlQueryExecTimeThreshold))
{
- __DBDbgPrintf(3, _T("Long running query: \"%s\" [%d ms]"), szQuery, (int)ms);
+ nxlog_debug(3, _T("Long running query: \"%s\" [%d ms]"), szQuery, (int)ms);
s_perfLongRunningQueries++;
}
ms = GetCurrentTimeMs() - ms;
if (hConn->m_driver->m_dumpSql)
{
- __DBDbgPrintf(9, _T("%s sync query: \"%s\" [%d ms]"), (hResult != NULL) ? _T("Successful") : _T("Failed"), szQuery, (int)ms);
+ nxlog_debug(9, _T("%s sync query: \"%s\" [%d ms]"), (hResult != NULL) ? _T("Successful") : _T("Failed"), szQuery, (int)ms);
}
if ((hResult != NULL) && ((UINT32)ms > g_sqlQueryExecTimeThreshold))
{
- __DBDbgPrintf(3, _T("Long running query: \"%s\" [%d ms]"), szQuery, (int)ms);
+ nxlog_debug(3, _T("Long running query: \"%s\" [%d ms]"), szQuery, (int)ms);
s_perfLongRunningQueries++;
}
MutexUnlock(hConn->m_mutexTransLock);
ms = GetCurrentTimeMs() - ms;
if (hConn->m_driver->m_dumpSql)
{
- __DBDbgPrintf(9, _T("%s unbuffered query: \"%s\" [%d ms]"), (hResult != NULL) ? _T("Successful") : _T("Failed"), szQuery, (int)ms);
+ nxlog_debug(9, _T("%s unbuffered query: \"%s\" [%d ms]"), (hResult != NULL) ? _T("Successful") : _T("Failed"), szQuery, (int)ms);
}
if ((hResult != NULL) && ((UINT32)ms > g_sqlQueryExecTimeThreshold))
{
- __DBDbgPrintf(3, _T("Long running query: \"%s\" [%d ms]"), szQuery, (int)ms);
+ nxlog_debug(3, _T("Long running query: \"%s\" [%d ms]"), szQuery, (int)ms);
s_perfLongRunningQueries++;
}
if (hResult == NULL)
if (hConn->m_driver->m_dumpSql)
{
ms = GetCurrentTimeMs() - ms;
- __DBDbgPrintf(9, _T("{%p} %s prepare: \"%s\" [%d ms]"), result, (result != NULL) ? _T("Successful") : _T("Failed"), query, ms);
+ nxlog_debug(9, _T("{%p} %s prepare: \"%s\" [%d ms]"), result, (result != NULL) ? _T("Successful") : _T("Failed"), query, ms);
}
#ifndef UNICODE
{
if (cType == DB_CTYPE_STRING)
{
- __DBDbgPrintf(9, _T("{%p} bind at pos %d: \"%s\""), hStmt, pos, buffer);
+ nxlog_debug(9, _T("{%p} bind at pos %d: \"%s\""), hStmt, pos, buffer);
}
else
{
_sntprintf(text, 64, _T("%f"), *((double *)buffer));
break;
}
- __DBDbgPrintf(9, _T("{%p} bind at pos %d: \"%s\""), hStmt, pos, text);
+ nxlog_debug(9, _T("{%p} bind at pos %d: \"%s\""), hStmt, pos, text);
}
}
ms = GetCurrentTimeMs() - ms;
if (hConn->m_driver->m_dumpSql)
{
- __DBDbgPrintf(9, _T("%s prepared sync query: \"%s\" [%d ms]"), (dwResult == DBERR_SUCCESS) ? _T("Successful") : _T("Failed"), hStmt->m_query, (int)ms);
+ nxlog_debug(9, _T("%s prepared sync query: \"%s\" [%d ms]"), (dwResult == DBERR_SUCCESS) ? _T("Successful") : _T("Failed"), hStmt->m_query, (int)ms);
}
if ((dwResult == DBERR_SUCCESS) && ((UINT32)ms > g_sqlQueryExecTimeThreshold))
{
- __DBDbgPrintf(3, _T("Long running query: \"%s\" [%d ms]"), hStmt->m_query, (int)ms);
+ nxlog_debug(3, _T("Long running query: \"%s\" [%d ms]"), hStmt->m_query, (int)ms);
s_perfLongRunningQueries++;
}
ms = GetCurrentTimeMs() - ms;
if (hConn->m_driver->m_dumpSql)
{
- __DBDbgPrintf(9, _T("%s prepared sync query: \"%s\" [%d ms]"),
+ nxlog_debug(9, _T("%s prepared sync query: \"%s\" [%d ms]"),
(hResult != NULL) ? _T("Successful") : _T("Failed"), hStmt->m_query, (int)ms);
}
if ((hResult != NULL) && ((UINT32)ms > g_sqlQueryExecTimeThreshold))
{
- __DBDbgPrintf(3, _T("Long running query: \"%s\" [%d ms]"), hStmt->m_query, (int)ms);
+ nxlog_debug(3, _T("Long running query: \"%s\" [%d ms]"), hStmt->m_query, (int)ms);
s_perfLongRunningQueries++;
}
ms = GetCurrentTimeMs() - ms;
if (hConn->m_driver->m_dumpSql)
{
- __DBDbgPrintf(9, _T("%s prepared sync query: \"%s\" [%d ms]"),
+ nxlog_debug(9, _T("%s prepared sync query: \"%s\" [%d ms]"),
(hResult != NULL) ? _T("Successful") : _T("Failed"), hStmt->m_query, (int)ms);
}
if ((hResult != NULL) && ((UINT32)ms > g_sqlQueryExecTimeThreshold))
{
- __DBDbgPrintf(3, _T("Long running query: \"%s\" [%d ms]"), hStmt->m_query, (int)ms);
+ nxlog_debug(3, _T("Long running query: \"%s\" [%d ms]"), hStmt->m_query, (int)ms);
s_perfLongRunningQueries++;
}
{
hConn->m_transactionLevel++;
bRet = true;
- __DBDbgPrintf(9, _T("BEGIN TRANSACTION successful (level %d)"), hConn->m_transactionLevel);
+ nxlog_debug(9, _T("BEGIN TRANSACTION successful (level %d)"), hConn->m_transactionLevel);
}
else
{
MutexUnlock(hConn->m_mutexTransLock);
- __DBDbgPrintf(9, _T("BEGIN TRANSACTION failed"), hConn->m_transactionLevel);
+ nxlog_debug(9, _T("BEGIN TRANSACTION failed"), hConn->m_transactionLevel);
}
}
else
{
hConn->m_transactionLevel++;
bRet = true;
- __DBDbgPrintf(9, _T("BEGIN TRANSACTION successful (level %d)"), hConn->m_transactionLevel);
+ nxlog_debug(9, _T("BEGIN TRANSACTION successful (level %d)"), hConn->m_transactionLevel);
}
return bRet;
}
bRet = (hConn->m_driver->m_fpDrvCommit(hConn->m_connection) == DBERR_SUCCESS);
else
bRet = true;
- __DBDbgPrintf(9, _T("COMMIT TRANSACTION %s (level %d)"), bRet ? _T("successful") : _T("failed"), hConn->m_transactionLevel);
+ nxlog_debug(9, _T("COMMIT TRANSACTION %s (level %d)"), bRet ? _T("successful") : _T("failed"), hConn->m_transactionLevel);
MutexUnlock(hConn->m_mutexTransLock);
}
MutexUnlock(hConn->m_mutexTransLock);
bRet = (hConn->m_driver->m_fpDrvRollback(hConn->m_connection) == DBERR_SUCCESS);
else
bRet = true;
- __DBDbgPrintf(9, _T("ROLLBACK TRANSACTION %s (level %d)"), bRet ? _T("successful") : _T("failed"), hConn->m_transactionLevel);
+ nxlog_debug(9, _T("ROLLBACK TRANSACTION %s (level %d)"), bRet ? _T("successful") : _T("failed"), hConn->m_transactionLevel);
MutexUnlock(hConn->m_mutexTransLock);
}
MutexUnlock(hConn->m_mutexTransLock);
/**
* Static data
*/
-static void (*s_debugCallback)(int, const TCHAR *, va_list args) = NULL;
static WORD s_noEncryptionFlag = 0;
#ifdef _WITH_ENCRYPTION
#endif /* _WITH_ENCRYPTION */
-/**
- * Debug output
- */
-static void CryptoDbgPrintf(int level, const TCHAR *format, ...)
-{
- if (s_debugCallback == NULL)
- return;
-
- va_list args;
- va_start(args, format);
- s_debugCallback(level, format, args);
- va_end(args);
-}
-
/**
* Initialize OpenSSL library
*/
-bool LIBNETXMS_EXPORTABLE InitCryptoLib(UINT32 dwEnabledCiphers, void (*debugCallback)(int, const TCHAR *, va_list args))
+bool LIBNETXMS_EXPORTABLE InitCryptoLib(UINT32 dwEnabledCiphers)
{
- s_debugCallback = debugCallback;
s_noEncryptionFlag = htons(MF_DONT_ENCRYPT);
#ifdef _WITH_ENCRYPTION
#endif /* _WIN32 */
// validate supported ciphers
- CryptoDbgPrintf(1, _T("Validating ciphers"));
+ nxlog_debug(1, _T("Validating ciphers"));
s_supportedCiphers &= dwEnabledCiphers;
UINT32 cipherBit = 1;
for(i = 0; i < NETXMS_MAX_CIPHERS; i++, cipherBit = cipherBit << 1)
{
if ((s_supportedCiphers & cipherBit) == 0)
{
- CryptoDbgPrintf(1, _T(" %s disabled (config)"), s_cipherNames[i]);
+ nxlog_debug(1, _T(" %s disabled (config)"), s_cipherNames[i]);
continue;
}
NXCPEncryptionContext *ctx = NXCPEncryptionContext::create(cipherBit);
if (ctx != NULL)
{
delete ctx;
- CryptoDbgPrintf(1, _T(" %s enabled"), s_cipherNames[i]);
+ nxlog_debug(1, _T(" %s enabled"), s_cipherNames[i]);
}
else
{
s_supportedCiphers &= ~cipherBit;
- CryptoDbgPrintf(1, _T(" %s disabled (validation failed)"), s_cipherNames[i]);
+ nxlog_debug(1, _T(" %s disabled (validation failed)"), s_cipherNames[i]);
}
}
- CryptoDbgPrintf(1, _T("Crypto library initialized"));
+ nxlog_debug(1, _T("Crypto library initialized"));
#else
- CryptoDbgPrintf(1, _T("Crypto library will not be initialized because libnetxms was built without encryption support"));
+ nxlog_debug(1, _T("Crypto library will not be initialized because libnetxms was built without encryption support"));
#endif /* _WITH_ENCRYPTION */
return true;
}
}
else
{
- CryptoDbgPrintf(6, _T("NXCPEncryptionContext::create: IV decryption failed"));
+ nxlog_debug(6, _T("NXCPEncryptionContext::create: IV decryption failed"));
delete_and_null(ctx);
}
}
else
{
- CryptoDbgPrintf(6, _T("NXCPEncryptionContext::create: session key decryption failed"));
+ nxlog_debug(6, _T("NXCPEncryptionContext::create: session key decryption failed"));
delete_and_null(ctx);
}
}
else
{
- CryptoDbgPrintf(6, _T("NXCPEncryptionContext::create: key length mismatch (remote: %d local: %d)"), (int)msg->getFieldAsUInt16(VID_KEY_LENGTH), ctx->m_keyLength);
+ nxlog_debug(6, _T("NXCPEncryptionContext::create: key length mismatch (remote: %d local: %d)"), (int)msg->getFieldAsUInt16(VID_KEY_LENGTH), ctx->m_keyLength);
delete_and_null(ctx);
}
}
else
{
- CryptoDbgPrintf(6, _T("NXCPEncryptionContext::create: initCipher(%d) call failed"), cipher);
+ nxlog_debug(6, _T("NXCPEncryptionContext::create: initCipher(%d) call failed"), cipher);
delete_and_null(ctx);
}
return ctx;
/*
** NetXMS - Network Management System
** Utility Library
-** Copyright (C) 2003-2014 Victor Kirhenshtein
+** Copyright (C) 2003-2016 Victor Kirhenshtein
**
** 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
static FILE *m_logFileHandle = NULL;
static MUTEX m_mutexLogAccess = INVALID_MUTEX_HANDLE;
static UINT32 m_flags = 0;
+static int s_debugLevel = 0;
+static DWORD s_debugMsg = 0;
static int m_rotationMode = NXLOG_ROTATION_BY_SIZE;
static int m_maxLogSize = 4096 * 1024; // 4 MB
static int m_logHistorySize = 4; // Keep up 4 previous log files
static THREAD s_writerThread = INVALID_THREAD_HANDLE;
static CONDITION s_writerStopCondition = INVALID_CONDITION_HANDLE;
+/**
+ * Set debug level
+ */
+void LIBNETXMS_EXPORTABLE nxlog_set_debug_level(int level)
+{
+ s_debugLevel = level;
+}
+
+/**
+ * Get current debug level
+ */
+int LIBNETXMS_EXPORTABLE nxlog_get_debug_level()
+{
+ return s_debugLevel;
+}
+
/**
* Format current time for output
*/
* Set log rotation policy
* Setting log size to 0 or mode to NXLOG_ROTATION_DISABLED disables log rotation
*/
-BOOL LIBNETXMS_EXPORTABLE nxlog_set_rotation_policy(int rotationMode, int maxLogSize, int historySize, const TCHAR *dailySuffix)
+bool LIBNETXMS_EXPORTABLE nxlog_set_rotation_policy(int rotationMode, int maxLogSize, int historySize, const TCHAR *dailySuffix)
{
- BOOL isValid = TRUE;
+ bool isValid = true;
if ((rotationMode >= 0) || (rotationMode <= 2))
{
else
{
m_maxLogSize = 1024;
- isValid = FALSE;
+ isValid = false;
}
if ((historySize >= 0) && (historySize <= MAX_LOG_HISTORY_SIZE))
{
if (historySize > MAX_LOG_HISTORY_SIZE)
m_logHistorySize = MAX_LOG_HISTORY_SIZE;
- isValid = FALSE;
+ isValid = false;
}
}
else if (rotationMode == NXLOG_ROTATION_DAILY)
}
else
{
- isValid = FALSE;
+ isValid = false;
}
return isValid;
/**
* Rotate log
*/
-static BOOL RotateLog(BOOL needLock)
+static bool RotateLog(bool needLock)
{
int i;
TCHAR oldName[MAX_PATH], newName[MAX_PATH];
if (needLock)
MutexUnlock(m_mutexLogAccess);
- return (m_flags & NXLOG_IS_OPEN) ? TRUE : FALSE;
+ return (m_flags & NXLOG_IS_OPEN) ? true : false;
}
/**
* API for application to force log rotation
*/
-BOOL LIBNETXMS_EXPORTABLE nxlog_rotate()
+bool LIBNETXMS_EXPORTABLE nxlog_rotate()
{
- return RotateLog(TRUE);
+ return RotateLog(true);
}
/**
/**
* Initialize log
*/
-BOOL LIBNETXMS_EXPORTABLE nxlog_open(const TCHAR *logName, UINT32 flags,
- const TCHAR *msgModule, unsigned int msgCount, const TCHAR **messages)
+bool LIBNETXMS_EXPORTABLE nxlog_open(const TCHAR *logName, UINT32 flags,
+ const TCHAR *msgModule, unsigned int msgCount, const TCHAR **messages, DWORD debugMsg)
{
m_flags = flags & 0x7FFFFFFF;
#ifdef _WIN32
m_numMessages = msgCount;
m_messages = messages;
#endif
+ s_debugMsg = debugMsg;
if (m_flags & NXLOG_USE_SYSLOG)
{
m_mutexLogAccess = MutexCreate();
SetDayStart();
}
- return (m_flags & NXLOG_IS_OPEN) ? TRUE : FALSE;
+ return (m_flags & NXLOG_IS_OPEN) ? true : false;
}
/**
while(--numStrings >= 0)
free(strings[numStrings]);
}
+
+/**
+ * Write debug message
+ */
+void LIBNETXMS_EXPORTABLE nxlog_debug(int level, const TCHAR *format, ...)
+{
+ if (level > s_debugLevel)
+ return;
+
+ va_list args;
+ va_start(args, format);
+ TCHAR buffer[8192];
+ _vsntprintf(buffer, 8192, format, args);
+ va_end(args);
+ nxlog_write(s_debugMsg, NXLOG_DEBUG, "s", buffer);
+}
+
+/**
+ * Write debug message
+ */
+void LIBNETXMS_EXPORTABLE nxlog_debug2(int level, const TCHAR *format, va_list args)
+{
+ if (level > s_debugLevel)
+ return;
+
+ TCHAR buffer[8192];
+ _vsntprintf(buffer, 8192, format, args);
+ nxlog_write(s_debugMsg, NXLOG_DEBUG, "s", buffer);
+}
bool inactivityStop;
};
-/**
- * Debug callback
- */
-static void (*s_debugCallback)(int, const TCHAR *, va_list) = NULL;
-
-/**
- * Debug print
- */
-inline void dprint(int level, const TCHAR *format, ...)
-{
- if (s_debugCallback == NULL)
- return;
-
- va_list args;
- va_start(args, format);
- s_debugCallback(level, format, args);
- va_end(args);
-}
-
-/**
- * Set debug callback
- */
-void LIBNETXMS_EXPORTABLE ThreadPoolSetDebugCallback(void (*cb)(int, const TCHAR *, va_list))
-{
- s_debugCallback = cb;
-}
-
/**
* Worker function to join stopped thread
*/
p->threads->remove(CAST_FROM_POINTER(arg, UINT64));
MutexUnlock(p->mutex);
- dprint(3, _T("Stopping worker thread in thread pool %s due to inactivity"), p->name);
+ nxlog_debug(3, _T("Stopping worker thread in thread pool %s due to inactivity"), p->name);
free(rq);
rq = (WorkRequest *)malloc(sizeof(WorkRequest));
count = 0;
}
}
- dprint(3, _T("Maintenance thread for thread pool %s stopped"), p->name);
+ nxlog_debug(3, _T("Maintenance thread for thread pool %s stopped"), p->name);
return THREAD_OK;
}
s_registry.set(p->name, p);
MutexUnlock(s_registryLock);
- dprint(1, _T("Thread pool %s initialized (min=%d, max=%d)"), p->name, p->minThreads, p->maxThreads);
+ nxlog_debug(1, _T("Thread pool %s initialized (min=%d, max=%d)"), p->name, p->minThreads, p->maxThreads);
return p;
}
*/
void LIBNETXMS_EXPORTABLE ThreadPoolDestroy(ThreadPool *p)
{
- dprint(3, _T("Stopping threads in thread pool %s"), p->name);
+ nxlog_debug(3, _T("Stopping threads in thread pool %s"), p->name);
MutexLock(s_registryLock);
s_registry.remove(p->name);
p->queue->put(&rq);
p->threads->forEach(ThreadPoolDestroyCallback, NULL);
- dprint(1, _T("Thread pool %s destroyed"), p->name);
+ nxlog_debug(1, _T("Thread pool %s destroyed"), p->name);
p->threads->setOwner(true);
delete p->threads;
delete p->queue;
}
MutexUnlock(p->mutex);
if (started)
- dprint(3, _T("New thread started in thread pool %s"), p->name);
+ nxlog_debug(3, _T("New thread started in thread pool %s"), p->name);
}
WorkRequest *rq = (WorkRequest *)malloc(sizeof(WorkRequest));
/*
** NetXMS - Network Management System
** Log Parsing Library
-** Copyright (C) 2003-2014 Victor Kirhenshtein
+** Copyright (C) 2003-2016 Victor Kirhenshtein
**
** 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
/*
** NetXMS - Network Management System
-** Copyright (C) 2003-2012 Victor Kirhenshtein
+** Copyright (C) 2003-2016 Victor Kirhenshtein
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
void AgentConnectionEx::printMsg(const TCHAR *format, ...)
{
va_list args;
-
va_start(args, format);
- DbgPrintf2(6, format, args);
+ nxlog_debug2(6, format, args);
va_end(args);
}
TCHAR g_szDbName[MAX_DB_NAME] = _T("netxms_db");
TCHAR g_szDbSchema[MAX_DB_NAME] = _T("");
+/**
+ * Debug level from config
+ */
+static UINT32 s_debugLevel = (UINT32)NXCONFIG_UNINITIALIZED_VALUE;
+
/**
* Config file template
*/
{ _T("DBEncryptedPassword"), CT_STRING, 0, 0, MAX_PASSWORD, 0, g_szDbPassword, NULL },
{ _T("DBSchema"), CT_STRING, 0, 0, MAX_DB_NAME, 0, g_szDbSchema, NULL },
{ _T("DBServer"), CT_STRING, 0, 0, MAX_PATH, 0, g_szDbServer, NULL },
- { _T("DebugLevel"), CT_LONG, 0, 0, 0, 0, &g_debugLevel, &g_debugLevel },
+ { _T("DebugLevel"), CT_LONG, 0, 0, 0, 0, &s_debugLevel, &s_debugLevel },
{ _T("DumpDirectory"), CT_STRING, 0, 0, MAX_PATH, 0, g_szDumpDir, NULL },
{ _T("FullCrashDumps"), CT_BOOLEAN64, 0, 0, AF_WRITE_FULL_DUMP, 0, &g_flags, NULL },
{ _T("LibraryDirectory"), CT_STRING, 0, 0, MAX_PATH, 0, g_netxmsdLibDir, NULL },
* Load and parse configuration file
* Returns TRUE on success and FALSE on failure
*/
-bool NXCORE_EXPORTABLE LoadConfig()
+bool NXCORE_EXPORTABLE LoadConfig(int *debugLevel)
{
bool bSuccess = false;
bSuccess = true;
}
+ if (*debugLevel == NXCONFIG_UNINITIALIZED_VALUE)
+ *debugLevel = (int)s_debugLevel;
+
// Decrypt password
DecryptPassword(g_szDbLogin, g_szDbPassword, g_szDbPassword, MAX_PASSWORD);
return bSuccess;
/*
** NetXMS - Network Management System
-** Copyright (C) 2003-2015 Victor Kirhenshtein
+** Copyright (C) 2003-2016 Victor Kirhenshtein
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
EnumerateClientSessions(BroadcastEvent, pEvent);
// Write event information to debug
- if (g_debugLevel >= 5)
+ if (nxlog_get_debug_level() >= 5)
{
NetObj *pObject = FindObjectById(pEvent->getSourceId());
if (pObject == NULL)
pObject = g_pEntireNet;
- DbgPrintf(5, _T("EVENT %s [%d] (ID:") UINT64_FMT _T(" F:0x%04X S:%d TAG:\"%s\"%s) FROM %s: %s"),
- pEvent->getName(), pEvent->getCode(), pEvent->getId(), pEvent->getFlags(), pEvent->getSeverity(),
- CHECK_NULL_EX(pEvent->getUserTag()),
- (pEvent->getRootId() == 0) ? _T("") : _T(" CORRELATED"),
- pObject->getName(), pEvent->getMessage());
+ nxlog_debug(5, _T("EVENT %s [%d] (ID:") UINT64_FMT _T(" F:0x%04X S:%d TAG:\"%s\"%s) FROM %s: %s"),
+ pEvent->getName(), pEvent->getCode(), pEvent->getId(), pEvent->getFlags(), pEvent->getSeverity(),
+ CHECK_NULL_EX(pEvent->getUserTag()),
+ (pEvent->getRootId() == 0) ? _T("") : _T(" CORRELATED"),
+ pObject->getName(), pEvent->getMessage());
}
// Pass event through event processing policy if it is not correlated
#endif
g_pEventPolicy->processEvent(pEvent);
- DbgPrintf(7, _T("Event ") UINT64_FMT _T(" with code %d passed event processing policy"), pEvent->getId(), pEvent->getCode());
+ nxlog_debug(7, _T("Event ") UINT64_FMT _T(" with code %d passed event processing policy"), pEvent->getId(), pEvent->getCode());
}
// Write event to log if required, otherwise destroy it
UINT32 dwLen;
BYTE *pBufPos, *pKeyBuffer, hash[SHA1_DIGEST_SIZE];
- if (!InitCryptoLib(ConfigReadULong(_T("AllowedCiphers"), 0x7F), DbgPrintf2))
+ if (!InitCryptoLib(ConfigReadULong(_T("AllowedCiphers"), 0x7F)))
return FALSE;
- DbgPrintf(4, _T("Supported ciphers: %s"), (const TCHAR *)NXCPGetSupportedCiphersAsText());
+ nxlog_debug(4, _T("Supported ciphers: %s"), (const TCHAR *)NXCPGetSupportedCiphersAsText());
SSL_library_init();
SSL_load_error_strings();
g_pServerKey = LoadRSAKeys(szKeyFile);
if (g_pServerKey == NULL)
{
- DbgPrintf(1, _T("Generating RSA key pair..."));
+ nxlog_debug(1, _T("Generating RSA key pair..."));
g_pServerKey = RSA_generate_key(NETXMS_RSA_KEYLEN, 17, NULL, 0);
if (g_pServerKey != NULL)
{
free(pKeyBuffer);
bResult = TRUE;
}
+ else
+ {
+ nxlog_debug(0, _T("Failed to open %s for writing"), szKeyFile);
+ }
+ }
else
{
- DbgPrintf(0, _T("Failed to open %s for writing"), szKeyFile);
+ nxlog_debug(0, _T("Failed to generate RSA key"));
}
- }
- else
- {
- DbgPrintf(0, _T("Failed to generate RSA key"));
- }
}
else
{
g_serverStartTime = time(NULL);
srand((unsigned int)g_serverStartTime);
- if (g_netxmsdLibDir[0] == 0)
- {
- GetNetXMSDirectory(nxDirLib, g_netxmsdLibDir);
- DbgPrintf(1, _T("Lib directory set to %s"), g_netxmsdLibDir);
- }
-
if (!(g_flags & AF_USE_SYSLOG))
{
if (!nxlog_set_rotation_policy((int)g_dwLogRotationMode, (int)g_dwMaxLogSize, (int)g_dwLogHistorySize, g_szDailyLogFileSuffix))
((g_flags & AF_DAEMON) ? 0 : NXLOG_PRINT_TO_STDOUT),
_T("LIBNXSRV.DLL"),
#ifdef _WIN32
- 0, NULL))
+ 0, NULL, MSG_DEBUG))
#else
- g_dwNumMessages, g_szMessages))
+ g_dwNumMessages, g_szMessages, MSG_DEBUG))
#endif
{
_ftprintf(stderr, _T("FATAL ERROR: Cannot open log file\n"));
}
nxlog_set_console_writer(LogConsoleWriter);
+ if (g_netxmsdLibDir[0] == 0)
+ {
+ GetNetXMSDirectory(nxDirLib, g_netxmsdLibDir);
+ nxlog_debug(1, _T("LIB directory set to %s"), g_netxmsdLibDir);
+ }
+
// Set code page
#ifndef _WIN32
if (SetDefaultCodepage(g_szCodePage))
{
#ifdef _WIN32
if (SetProcessAffinityMask(GetCurrentProcess(), g_processAffinityMask))
- DbgPrintf(1, _T("Process affinity mask set to 0x%08X"), g_processAffinityMask);
+ nxlog_debug(1, _T("Process affinity mask set to 0x%08X"), g_processAffinityMask);
#else
nxlog_write(MSG_SET_PROCESS_AFFINITY_NOT_SUPPORTED, EVENTLOG_WARNING_TYPE, NULL);
#endif
g_dciRawDataWriterQueue = new Queue(1024, 1024);
// Initialize database driver and connect to database
- DBSetDebugPrintCallback(DbgPrintf2);
if (!DBInit(MSG_OTHER, (g_flags & AF_LOG_SQL_ERRORS) ? MSG_SQL_ERROR : 0))
return FALSE;
- g_dbDriver = DBLoadDriver(g_szDbDriver, g_szDbDrvParams, (g_debugLevel >= 9), DBEventHandler, NULL);
+ g_dbDriver = DBLoadDriver(g_szDbDriver, g_szDbDrvParams, (nxlog_get_debug_level() >= 9), DBEventHandler, NULL);
if (g_dbDriver == NULL)
return FALSE;
nxlog_write(MSG_DB_CONNFAIL, EVENTLOG_ERROR_TYPE, "s", errorText);
return FALSE;
}
- DbgPrintf(1, _T("Successfully connected to database %s@%s"), g_szDbName, g_szDbServer);
+ nxlog_debug(1, _T("Successfully connected to database %s@%s"), g_szDbName, g_szDbServer);
// Check database version
iDBVersion = DBGetSchemaVersion(hdbBootstrap);
_sntprintf(szInfo, 256, UINT64X_FMT(_T("016")), g_serverId);
MetaDataWriteStr(_T("ServerID"), szInfo);
}
- DbgPrintf(1, _T("Server ID ") UINT64X_FMT(_T("016")), g_serverId);
+ nxlog_debug(1, _T("Server ID ") UINT64X_FMT(_T("016")), g_serverId);
// Initialize locks
retry_db_lock:
// Load global configuration parameters
LoadGlobalConfig();
CASReadSettings();
- DbgPrintf(1, _T("Global configuration loaded"));
+ nxlog_debug(1, _T("Global configuration loaded"));
// Check data directory
if (!CheckDataDir())
m_condShutdown = ConditionCreate(TRUE);
// Create thread pools
- DbgPrintf(2, _T("Creating thread pools"));
- ThreadPoolSetDebugCallback(DbgPrintf2);
+ nxlog_debug(2, _T("Creating thread pools"));
g_mainThreadPool = ThreadPoolCreate(8, 256, _T("MAIN"));
g_agentConnectionThreadPool = ThreadPoolCreate(4, 256, _T("AGENT"));
// Setup unique identifiers table
if (!InitIdTable())
return FALSE;
- DbgPrintf(2, _T("ID table created"));
+ nxlog_debug(2, _T("ID table created"));
// Update status for unfinished jobs in job history
DB_HANDLE hdb = DBConnectionPoolAcquireConnection();
nxlog_write(MSG_ERROR_LOADING_USERS, EVENTLOG_ERROR_TYPE, NULL);
return FALSE;
}
- DbgPrintf(2, _T("User accounts loaded"));
+ nxlog_debug(2, _T("User accounts loaded"));
// Initialize audit
InitAuditLog();
ObjectsInit();
if (!LoadObjects())
return FALSE;
- DbgPrintf(1, _T("Objects loaded and initialized"));
+ nxlog_debug(1, _T("Objects loaded and initialized"));
// Initialize situations
if (!SituationsInit())
return FALSE;
- DbgPrintf(1, _T("Situations loaded and initialized"));
+ nxlog_debug(1, _T("Situations loaded and initialized"));
// Initialize and load event actions
if (!InitActions())
// Start uptime calculator for SLM
ThreadCreate(UptimeCalculator, 0, NULL);
- DbgPrintf(2, _T("LIBDIR: %s"), g_netxmsdLibDir);
+ nxlog_debug(2, _T("LIBDIR: %s"), g_netxmsdLibDir);
// Call startup functions for the modules
CALL_ALL_MODULES(pfServerStarted, ());
#endif
g_flags |= AF_SERVER_INITIALIZED;
- DbgPrintf(1, _T("Server initialization completed"));
+ nxlog_debug(1, _T("Server initialization completed"));
return TRUE;
}
ShutdownSMSSender();
ThreadSleep(1); // Give other threads a chance to terminate in a safe way
- DbgPrintf(2, _T("All threads was notified, continue with shutdown"));
+ nxlog_debug(2, _T("All threads was notified, continue with shutdown"));
StopSyslogServer();
StopHouseKeeper();
DB_HANDLE hdb = DBConnectionPoolAcquireConnection();
SaveObjects(hdb);
- DbgPrintf(2, _T("All objects saved to database"));
+ nxlog_debug(2, _T("All objects saved to database"));
SaveUsers(hdb);
- DbgPrintf(2, _T("All users saved to database"));
+ nxlog_debug(2, _T("All users saved to database"));
DBConnectionPoolReleaseConnection(hdb);
StopDBWriter();
- DbgPrintf(1, _T("Database writer stopped"));
+ nxlog_debug(1, _T("Database writer stopped"));
CleanupUsers();
DBConnectionPoolShutdown();
DBUnloadDriver(g_dbDriver);
- DbgPrintf(1, _T("Database driver unloaded"));
+ nxlog_debug(1, _T("Database driver unloaded"));
CleanupActions();
ShutdownEventSubsystem();
ShutdownAlarmManager();
- DbgPrintf(1, _T("Event processing stopped"));
+ nxlog_debug(1, _T("Event processing stopped"));
ThreadPoolDestroy(g_agentConnectionThreadPool);
ThreadPoolDestroy(g_mainThreadPool);
delete g_pScriptLibrary;
- DbgPrintf(1, _T("Server shutdown complete"));
+ nxlog_debug(1, _T("Server shutdown complete"));
nxlog_close();
// Remove PID file
int level = (int)_tcstol(szBuffer, &eptr, 0);
if ((*eptr == 0) && (level >= 0) && (level <= 9))
{
- g_debugLevel = (UINT32)level;
+ nxlog_set_debug_level(level);
ConsolePrintf(pCtx, (level == 0) ? _T("Debug mode turned off\n") : _T("Debug level set to %d\n"), level);
}
else if (IsCommand(_T("OFF"), szBuffer, 2))
{
- g_debugLevel = 0;
+ nxlog_set_debug_level(0);
ConsoleWrite(pCtx, _T("Debug mode turned off\n"));
}
else
/*
** NetXMS - Network Management System
-** Copyright (C) 2003-2012 Victor Kirhenshtein
+** Copyright (C) 2003-2016 Victor Kirhenshtein
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
*/
void MobileDeviceSession::debugPrintf(int level, const TCHAR *format, ...)
{
- if (level <= (int)g_debugLevel)
+ if (level <= nxlog_get_debug_level())
{
va_list args;
TCHAR buffer[4096];
break;
}
- if (g_debugLevel >= 8)
+ if (nxlog_get_debug_level() >= 8)
{
String msgDump = NXCPMessage::dump(receiver.getRawMessageBuffer(), NXCP_VERSION);
debugPrintf(8, _T("Message dump:\n%s"), (const TCHAR *)msgDump);
debugPrintf(6, _T("Sending message %s"), NXCPMessageCodeName(msg->getCode(), szBuffer));
NXCP_MESSAGE *pRawMsg = msg->createMessage();
- if (g_debugLevel >= 8)
+ if (nxlog_get_debug_level() >= 8)
{
String msgDump = NXCPMessage::dump(pRawMsg, NXCP_VERSION);
debugPrintf(8, _T("Message dump:\n%s"), (const TCHAR *)msgDump);
/*
** NetXMS - Network Management System
-** Copyright (C) 2003-2015 Raden Solutions
+** Copyright (C) 2003-2016 Raden Solutions
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
{
va_list args;
va_start(args, format);
- DbgPrintf2(7, format, args);
+ nxlog_debug2(7, format, args);
va_end(args);
}
};
*/
void ClientSession::debugPrintf(int level, const TCHAR *format, ...)
{
- if (level <= (int)g_debugLevel)
+ if (level <= nxlog_get_debug_level())
{
va_list args;
TCHAR buffer[8192];
break;
}
- if (g_debugLevel >= 8)
+ if (nxlog_get_debug_level() >= 8)
{
String msgDump = NXCPMessage::dump(receiver.getRawMessageBuffer(), NXCP_VERSION);
debugPrintf(8, _T("Message dump:\n%s"), (const TCHAR *)msgDump);
}
NXCP_MESSAGE *rawMsg = msg->createMessage();
- if ((g_debugLevel >= 8) && (msg->getCode() != CMD_ADM_MESSAGE))
+ if ((nxlog_get_debug_level() >= 8) && (msg->getCode() != CMD_ADM_MESSAGE))
{
String msgDump = NXCPMessage::dump(rawMsg, NXCP_VERSION);
debugPrintf(8, _T("Message dump:\n%s"), (const TCHAR *)msgDump);
debugPrintf(6, _T("Sending message %s"), NXCPMessageCodeName(ntohs(msg->code), buffer));
}
- if ((g_debugLevel >= 8) && (code != CMD_ADM_MESSAGE))
+ if ((code != CMD_ADM_MESSAGE) && (nxlog_get_debug_level() >= 8))
{
String msgDump = NXCPMessage::dump(msg, NXCP_VERSION);
debugPrintf(8, _T("Message dump:\n%s"), (const TCHAR *)msgDump);
/*
** NetXMS - Network Management System
-** Copyright (C) 2003-2015 Victor Kirhenshtein
+** Copyright (C) 2003-2016 Victor Kirhenshtein
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
nxlog_write(MSG_LISTENING_FOR_SYSLOG, EVENTLOG_INFORMATION_TYPE, "Hd", servAddr6.sin6_addr.s6_addr, port);
#endif
- SetLogParserTraceCallback(DbgPrintf2);
+ SetLogParserTraceCallback(nxlog_debug2);
InitLogParserLibrary();
// Create message parser
INT32 NXCORE_EXPORTABLE MetaDataReadInt(const TCHAR *var, UINT32 defaultValue);
bool NXCORE_EXPORTABLE MetaDataWriteStr(const TCHAR *varName, const TCHAR *value);
-bool NXCORE_EXPORTABLE LoadConfig();
+bool NXCORE_EXPORTABLE LoadConfig(int *debugLevel);
void NXCORE_EXPORTABLE Shutdown();
void NXCORE_EXPORTABLE FastShutdown();
#endif
;
-void LIBNXSRV_EXPORTABLE DbgPrintf(int level, const TCHAR *format, ...)
-#if !defined(UNICODE) && (defined(__GNUC__) || defined(__clang__))
- __attribute__ ((format(printf, 2, 3)))
-#endif
-;
-
-void LIBNXSRV_EXPORTABLE DbgPrintf2(int level, const TCHAR *format, va_list args);
+// for compatibility - new code should use nxlog_debug
+#define DbgPrintf nxlog_debug
void LIBNXSRV_EXPORTABLE SetAgentDEP(int iPolicy);
* Variables
*/
extern UINT64 LIBNXSRV_EXPORTABLE g_flags;
-extern UINT32 LIBNXSRV_EXPORTABLE g_debugLevel;
extern ThreadPool LIBNXSRV_EXPORTABLE *g_agentConnectionThreadPool;
/**
/*
** NetXMS - Network Management System
** Server Library
-** Copyright (C) 2003-2013 Victor Kirhenshtein
+** Copyright (C) 2003-2016 Victor Kirhenshtein
**
** 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
* Global variables
*/
UINT64 LIBNXSRV_EXPORTABLE g_flags = AF_USE_SYSLOG | AF_CATCH_EXCEPTIONS | AF_LOG_SQL_ERRORS;
-UINT32 LIBNXSRV_EXPORTABLE g_debugLevel = (UINT32)NXCONFIG_UNINITIALIZED_VALUE;
/**
* Agent error codes
qsort(pRT->pRoutes, pRT->iNumEntries, sizeof(ROUTE), CompareRoutes);
}
-/**
- * Debug printf - write debug record to log if level is less or equal current debug level
- */
-void LIBNXSRV_EXPORTABLE DbgPrintf2(int level, const TCHAR *format, va_list args)
-{
- TCHAR buffer[4096];
-
- if (level > (int)g_debugLevel)
- return; // Required application flag(s) not set
-
- _vsntprintf(buffer, 4096, format, args);
- nxlog_write(MSG_DEBUG, EVENTLOG_DEBUG_TYPE, "s", buffer);
-}
-
-/**
- * Debug printf - write debug record to log if level is less or equal current debug level
- */
-void LIBNXSRV_EXPORTABLE DbgPrintf(int level, const TCHAR *format, ...)
-{
- va_list args;
- TCHAR buffer[8192];
-
- if (level > (int)g_debugLevel)
- return; // Required application flag(s) not set
-
- va_start(args, format);
- _vsntprintf(buffer, 8192, format, args);
- va_end(args);
- nxlog_write(MSG_DEBUG, EVENTLOG_DEBUG_TYPE, "s", buffer);
-}
-
/**
* Log custom message (mostly used by modules)
*/
*/
BOOL g_bCheckDB = FALSE;
+/**
+ * Debug level
+ */
+static int s_debugLevel = NXCONFIG_UNINITIALIZED_VALUE;
+
/**
* Help text
*/
case 'C': // Check config
g_flags &= ~AF_DAEMON;
_tprintf(_T("Checking configuration file (%s):\n\n"), g_szConfigFile);
- LoadConfig();
+ LoadConfig(&s_debugLevel);
return FALSE;
case 'd':
g_flags |= AF_DAEMON;
break;
case 'D': // Debug level
- g_debugLevel = strtoul(optarg, &eptr, 0);
- if ((*eptr != 0) || (g_debugLevel > 9))
+ s_debugLevel = strtoul(optarg, &eptr, 0);
+ if ((*eptr != 0) || (s_debugLevel > 9))
{
_tprintf(_T("Invalid debug level \"%hs\" - should be in range 0..9\n"), optarg);
- g_debugLevel = 0;
+ s_debugLevel = 0;
}
break;
case 'q': // disable interactive console
if (!ParseCommandLine(argc, argv))
return 1;
- if (!LoadConfig())
+ if (!LoadConfig(&s_debugLevel))
{
if (IsStandalone())
_tprintf(_T("Error loading configuration file\n"));
return 1;
}
- if (g_debugLevel == NXCONFIG_UNINITIALIZED_VALUE)
- g_debugLevel = 0;
+ if (s_debugLevel == NXCONFIG_UNINITIALIZED_VALUE)
+ s_debugLevel = 0;
+ nxlog_set_debug_level(s_debugLevel);
// Set exception handler
#ifdef _WIN32
#ifdef _WITH_ENCRYPTION
if ((iEncryptionPolicy != ENCRYPTION_DISABLED) && bStart)
{
- if (InitCryptoLib(0xFFFF, NULL))
+ if (InitCryptoLib(0xFFFF))
{
pServerKey = LoadRSAKeys(szKeyFile);
if (pServerKey == NULL)
#ifdef _WITH_ENCRYPTION
if ((iEncryptionPolicy != ENCRYPTION_DISABLED) && bStart)
{
- if (InitCryptoLib(0xFFFF, NULL))
+ if (InitCryptoLib(0xFFFF))
{
pServerKey = LoadRSAKeys(szKeyFile);
if (pServerKey == NULL)
#ifdef _WITH_ENCRYPTION
if ((iEncryptionPolicy != ENCRYPTION_DISABLED) && start)
{
- if (InitCryptoLib(0xFFFF, NULL))
+ if (InitCryptoLib(0xFFFF))
{
pServerKey = LoadRSAKeys(keyFile);
if (pServerKey == NULL)
#ifdef _WITH_ENCRYPTION
if ((iEncryptionPolicy != ENCRYPTION_DISABLED) && bStart)
{
- if (InitCryptoLib(0xFFFF, NULL))
+ if (InitCryptoLib(0xFFFF))
{
pServerKey = LoadRSAKeys(szKeyFile);
if (pServerKey == NULL)