From aa82dc64b397b6ca0d336d91638d4f4b849e3667 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 26 Jun 2007 05:10:58 +0000 Subject: Fixed a minor bug in FString, and added the Logger and a test...it's cool, and a decent replacement for multilog now that we use runit. --- src/tests/logger.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/tests/logger.cpp (limited to 'src/tests/logger.cpp') diff --git a/src/tests/logger.cpp b/src/tests/logger.cpp new file mode 100644 index 0000000..a271443 --- /dev/null +++ b/src/tests/logger.cpp @@ -0,0 +1,28 @@ +#include "bu/logger.h" +#include +#include + +class Thing +{ + public: + Thing() + { + lineLog( 2, "Want a thing?"); + } + + void go( int i ) + { + lineLog( 1, "GO!!!!"); + } +}; + +int main() +{ + setLogLevel( 4 ); + setLogFormat("%L: %y-%m-%d %h:%M:%s %f:%l:%F: %t"); + lineLog( 5, "Hey, error: %s", strerror( errno ) ); + + Thing gh; + gh.go( 6); +} + -- cgit v1.2.3 From 60bac0c9f558ab34c70f099db923204a84d51ffc Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 29 Jun 2007 01:59:26 +0000 Subject: The plugger was dying on a HashException it should have caught, and the Logger now allows you to include extra printf formatting in your fields just like the docs say you can. --- src/logger.cpp | 32 ++++++++++++++++++++------------ src/plugger.h | 8 +++++--- src/tests/logger.cpp | 2 +- 3 files changed, 26 insertions(+), 16 deletions(-) (limited to 'src/tests/logger.cpp') diff --git a/src/logger.cpp b/src/logger.cpp index 848dfb1..1fc2262 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -71,22 +71,30 @@ void Bu::Logger::setFormat( const Bu::FString &str ) if( *s == '%' ) { sLogFormat += '%'; - s++; - for( int l = 0;; l++ ) + Bu::FString sBuf; + for(;;) { - if( fmts[l][0] == '\0' ) + s++; + int l; + for( l = 0;; l++ ) { - sLogFormat += *s; - break; + if( fmts[l][0] == '\0' ) + { + sBuf += *s; + break; + } + else if( *s == fmts[l][0] ) + { + sLogFormat += fmts[l][2]; + sLogFormat += fmts[l][3]; + sLogFormat += '$'; + sLogFormat += sBuf; + sLogFormat += fmts[l][1]; + break; + } } - else if( *s == fmts[l][0] ) - { - sLogFormat += fmts[l][2]; - sLogFormat += fmts[l][3]; - sLogFormat += '$'; - sLogFormat += fmts[l][1]; + if( fmts[l][0] != '\0' ) break; - } } } else diff --git a/src/plugger.h b/src/plugger.h index 615a662..2124b7a 100644 --- a/src/plugger.h +++ b/src/plugger.h @@ -116,13 +116,15 @@ namespace Bu void registerExternalPlugin( const char *sFName, const char *sPluginName ) { - PluginReg *pReg = (PluginReg *)hPlugin[sPluginName]; - if( pReg != NULL ) - { + PluginReg *pReg; + try { + pReg = (PluginReg *)hPlugin[sPluginName]; hPlugin.erase( sPluginName ); dlclose( pReg->dlHandle ); delete pReg; pReg = NULL; + } catch( Bu::HashException &e ) + { } pReg = new PluginReg; diff --git a/src/tests/logger.cpp b/src/tests/logger.cpp index a271443..290f479 100644 --- a/src/tests/logger.cpp +++ b/src/tests/logger.cpp @@ -19,7 +19,7 @@ class Thing int main() { setLogLevel( 4 ); - setLogFormat("%L: %y-%m-%d %h:%M:%s %f:%l:%F: %t"); + setLogFormat("%L: %y-%02m-%02d %h:%02M:%02s %f:%l:%F: %t"); lineLog( 5, "Hey, error: %s", strerror( errno ) ); Thing gh; -- cgit v1.2.3