/* Copyright (C) 2008 Andreas Baumann 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 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 General Public License along with this program. If not, see . */ #include "log/log.h" /* for logging */ #include "log/messages.h" /* for i18n */ #include "port/string.h" /* for strerror_r */ #include "errors.h" #include /* for exit, EXIT_SUCCESS, free */ #include /* for errno */ #ifdef _WIN32 #define WIND32_LEAN_AND_MEAN #include #endif #define WOLF_CATEGORY_TEST_LOG WOLF_LAST_INTERNAL_CATEGORY+1 #define WOLF_MSG_TEST_LOG_BASE ( WOLF_CATEGORY_TEST_LOG ) * 1000 #define WOLF_MSG_TEST_LOG_MSG1 WOLF_MSG_TEST_LOG_BASE+1 #define WOLF_MSG_TEST_LOG_MSG2 WOLF_MSG_TEST_LOG_BASE+2 #define WOLF_MSG_TEST_LOG_MSG3 WOLF_MSG_TEST_LOG_BASE+3 #define WOLF_MSG_TEST_LOG_MSG4 WOLF_MSG_TEST_LOG_BASE+4 #define WOLF_MSG_TEST_LOG_MSG5 WOLF_MSG_TEST_LOG_BASE+5 #define WOLF_MSG_TEST_LOG_MSG6 WOLF_MSG_TEST_LOG_BASE+6 #define WOLF_MSG_TEST_LOG_MSG7 WOLF_MSG_TEST_LOG_BASE+7 #define WOLF_MSG_TEST_LOG_MSG8 WOLF_MSG_TEST_LOG_BASE+8 #define WOLF_MSG_TEST_LOG_MSG9 WOLF_MSG_TEST_LOG_BASE+9 int main( void ) { char errbuf[512]; #ifdef _WIN32 DWORD last_error; #endif wolf_log_openlogtostderr( WOLF_LOG_NOTICE ); wolf_log_openlogtofile( "test.log", WOLF_LOG_NOTICE ); #if defined WOLF_LOG_HAVE_SYSLOG wolf_log_openlogtosyslog( "test", WOLF_LOG_DAEMON, WOLF_LOG_NOTICE, WOLF_LOG_SYSLOG_DEFAULT_OPTIONS ); #endif #if defined WOLF_LOG_HAVE_EVENTLOG wolf_log_openlogtoeventlog( NULL, "Application", "wolf_log_test", "C:\\Temp\\testmsg.dll", WOLF_LAST_INTERNAL_CATEGORY+1, WOLF_LOG_NOTICE ); #endif /* parameters and levels */ wolf_log( WOLF_LOG_ERR, WOLF_CATEGORY_TEST_LOG, WOLF_MSG_TEST_LOG_MSG1, "This is error %d", 5 ); wolf_log( WOLF_LOG_WARNING, WOLF_CATEGORY_TEST_LOG, WOLF_MSG_TEST_LOG_MSG2, "Warning, this is just a test" ); wolf_log( WOLF_LOG_NOTICE, WOLF_CATEGORY_TEST_LOG, WOLF_MSG_TEST_LOG_MSG3, "Started the logger" ); wolf_log( WOLF_LOG_DEBUG, WOLF_CATEGORY_TEST_LOG, WOLF_MSG_TEST_LOG_MSG4, "This will not appear" ); wolf_log( WOLF_LOG_NOTICE, WOLF_CATEGORY_TEST_LOG, WOLF_MSG_TEST_LOG_MSG5, "Closed the logger" ); wolf_log( WOLF_LOG_ERR, WOLF_CATEGORY_TEST_LOG, WOLF_MSG_TEST_LOG_MSG6, "This is error %d with %s", 5, "foobar" ); /* different ways of handling system errors (errno, GetLastError) */ errno = 5; (void)wolf_system_error_msg( errbuf, 512 ); wolf_log( WOLF_LOG_ERR, WOLF_CATEGORY_TEST_LOG, WOLF_MSG_TEST_LOG_MSG7, "A Unix system error occured during %s phase: %s (%d)", "fla", errbuf, errno ); #ifdef _WIN32 SetLastError( 18 ); (void)wolf_system_error_msg( errbuf, 512 ); wolf_log( WOLF_LOG_ERR, WOLF_CATEGORY_TEST_LOG, WOLF_MSG_TEST_LOG_MSG8, "A Windows error occured during %s phase: %s (%d)", "fla", errbuf, GetLastError( ) ); #endif /* HTTP link to a knowledge base or feedback form, this results in a * HTTP GET request to the address: * * http://wolfbones.andreasbaumann.cc/?EvtSrc=wolf_log_test&EvtCat=Test%20Category%20&EvtID=3009 * * Really good thinking here! */ wolf_log( WOLF_LOG_ERR, WOLF_CATEGORY_TEST_LOG, WOLF_MSG_TEST_LOG_MSG9, "Error %d, see more on http://wolfbones.andreasbaumann.cc", 66 ); #if defined WOLF_LOG_HAVE_EVENTLOG wolf_log_closelogtoeventlog( ); #endif #if defined WOLF_LOG_HAVE_SYSLOG wolf_log_closelogtosyslog( ); #endif wolf_log_closelogtofile( ); wolf_log_closelogtostderr( ); return EXIT_SUCCESS; }