Demonstrates usage of Stumpless through the C++ bindings.
Demonstrates usage of Stumpless through the C++ bindings.
#include <cstddef>
#include <cstdlib>
#include <stumpless.hpp>
#include <iostream>
using namespace stumpless;
int
main( int argc, char **argv ) {
FileTarget file_logger( "cpp_example.log" );
file_logger.Log( "she just made ANOTHER u-turn" );
file_logger.Log( Facility::NEWS, Severity::EMERGENCY,
"Helen's lost again!!!" );
file_logger.Log( "she's gotten lost %d times in the last %d days", 25, 3 );
Entry up_to_code( Facility::USER,
Severity::INFO,
"cpp-demo-app",
"up-to-code",
"is it up to code?" );
Element item( "subject" );
up_to_code.AddElement( item );
Param name( "name", "baked alaska" );
Param result( "result", "not-up-to-code" );
item.AddParam( name ).AddParam( result );
file_logger.Log( up_to_code );
try {
file_logger.SetDefaultAppName( NULL );
} catch( StumplessException *e ) {
if( e->GetErrorId() == ErrorId::ARGUMENT_EMPTY ) {
std::cout << "the app name was NULL!" << std::endl;
}
}
#ifdef STUMPLESS_SOCKET_TARGETS_SUPPORTED
std::cout << "logging to " << SocketTarget::DEFAULT_SOCKET << " by default" << std::endl;
#else
std::cout << "socket targets aren't supported by this build" << std::endl;
#endif
return EXIT_SUCCESS;
}
The main header file for the stumpless logging library.