summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2014-10-17 09:16:26 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2014-10-17 09:16:26 +0200
commit46428f37d62672a3d17663d1d704a6ebc3f21073 (patch)
treee858e8dfca33c60d56f4ed7c70b0d96f1209c2d0
parent85c1980e88ef1a47313423bd13f7378247722260 (diff)
downloadcrawler-46428f37d62672a3d17663d1d704a6ebc3f21073.tar.gz
crawler-46428f37d62672a3d17663d1d704a6ebc3f21073.tar.bz2
replaced log( "LEVEL") Lua function with 'log.level' table of C functions for logging
-rw-r--r--src/crawl/crawl.conf12
-rwxr-xr-xsrc/crawl/crawl.cpp43
2 files changed, 44 insertions, 11 deletions
diff --git a/src/crawl/crawl.conf b/src/crawl/crawl.conf
index 29c3620..46599d6 100644
--- a/src/crawl/crawl.conf
+++ b/src/crawl/crawl.conf
@@ -81,24 +81,24 @@ filters = {
function init( )
- log( "NOTICE", "Init.." )
+ log.notice( "Init.." )
-- normalizer = urlnormalizers.create( "google_urlnormalizer" );
normalizer = GoogleURLNormalizer:new( )
-- normalizer2 = urlnormalizers.create( "simple_urlnormalizer" );
normalizer2 = SimpleURLNormalizer:new( )
base = tolua.cast( normalizer, "URLNormalizer" )
- log( "DEBUG", "type: " .. tolua.type( base ) )
+ log.debug( "type: " .. tolua.type( base ) )
end
function destroy( )
- log( "NOTICE", "Destroy.." )
+ log.notice( "Destroy.." )
normalizer:delete( )
end
function crawl( )
- log( "NOTICE", "Crawling.." )
+ log.notice( "Crawling.." )
local baseUrl = base:parseUrl( "http://www.base.com" )
- log( "DEBUG", "base URL is: " .. baseUrl:str( ) )
+ log.debug( "base URL is: " .. baseUrl:str( ) )
local url = base:normalize( baseUrl, "/relativedir/relativefile.html" )
- log( "DEBUG", "URL is: " .. url:str( ) )
+ log.debug( "URL is: " .. url:str( ) )
end
diff --git a/src/crawl/crawl.cpp b/src/crawl/crawl.cpp
index 0698b75..24d6427 100755
--- a/src/crawl/crawl.cpp
+++ b/src/crawl/crawl.cpp
@@ -90,16 +90,15 @@ static vector<string> searchModuleFiles( const vector<string> &modules, const ve
return moduleFiles;
}
-static int lua_log( lua_State *l )
+static int lua_log_level( const LogLevel logLevel, lua_State *l )
{
size_t nofParams = lua_gettop( l );
if( nofParams == 0 ) return 0;
- const char *logLevel = luaL_checkstring( l, 1 );
ostringstream ss;
- for( size_t i = 2; i <= nofParams; i++ ) {
+ for( size_t i = 1; i <= nofParams; i++ ) {
int type = lua_type( l, i );
switch( type ) {
@@ -124,13 +123,32 @@ static int lua_log( lua_State *l )
}
}
- LOG( Logger::fromString( logLevel ) ) << ss.str( );
+ LOG( logLevel ) << ss.str( );
lua_pop( l, (int)nofParams );
return 0;
}
+
+#define lua_log( level ) \
+static int lua_log_ ## level( lua_State *l ) \
+{ \
+ return lua_log_level( log ## level, l ); \
+}
+
+lua_log( FATAL )
+lua_log( CRITICAL )
+lua_log( ERROR )
+lua_log( WARNING )
+lua_log( NOTICE )
+lua_log( INFO )
+lua_log( DEBUG )
+lua_log( DEBUG1 )
+lua_log( DEBUG2 )
+lua_log( DEBUG3 )
+lua_log( DEBUG4 )
+
int main( int /* argc */, char *argv[] )
{
try {
@@ -144,7 +162,22 @@ int main( int /* argc */, char *argv[] )
luaVm.loadSource( argv[1] );
// register logging function
- lua_pushcclosure( luaVm.handle( ), &lua_log, 0 );
+ luaL_Reg reg[12] = {
+ { "fatal", lua_log_FATAL },
+ { "critical", lua_log_CRITICAL },
+ { "error", lua_log_ERROR },
+ { "warning", lua_log_WARNING },
+ { "notice", lua_log_NOTICE },
+ { "info", lua_log_INFO },
+ { "debug", lua_log_DEBUG },
+ { "debug1", lua_log_DEBUG1 },
+ { "debug2", lua_log_DEBUG2 },
+ { "debug3", lua_log_DEBUG3 },
+ { "debug4", lua_log_DEBUG4 },
+ { NULL, NULL }
+ };
+ lua_newtable( luaVm.handle( ) );
+ luaL_setfuncs( luaVm.handle( ), reg, 0 );
lua_setglobal( luaVm.handle( ), "log" );
// execute main (to get basic configuration in form