Created
October 21, 2013 19:22
-
-
Save zmallen/7089395 to your computer and use it in GitHub Desktop.
logLua function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int logLua(lua_State *lua) | |
{ | |
// get # of arguments from the pdnslog() lua stack | |
// if it is 1, then the old pdnslog(msg) is used, which we keep for posterity and to prevent lua scripts from breaking | |
// if it is 2, then we process it as pdnslog(msg, urgencylevel) for more granular logging | |
int argc = lua_gettop(lua); | |
if(argc == 1) { | |
string message=lua_tostring(lua, 1); | |
theL()<<Logger::Error<<"From Lua script: "<<message<<endl; | |
} else if(argc == 2) { | |
string message=lua_tostring(lua, 1); | |
string urgencylevel = lua_tostring(lua, 2); | |
if(urgencylevel == "alert") | |
theL()<<Logger::Alert<<"ALERT: "<<message<<endl; | |
else if(urgencylevel == "critical") | |
theL()<<Logger::Critical<<"CRITICAL: "<<message<<endl; | |
else if(urgencylevel == "error") | |
theL()<<Logger::Error<<"ERROR: "<<message<<endl; | |
else if(urgencylevel == "warning") | |
theL()<<Logger::Warning<<"WARNING: "<<message<<endl; | |
else if(urgencylevel=="notice") | |
theL()<<Logger::Notice<<"NOTICE: "<<message<<endl; | |
else if(urgencylevel=="info") | |
theL()<<Logger::Info<<"INFO: "<<message<<endl; | |
else if(urgencylevel=="debug") | |
theL()<<Logger::Debug<<"DEBUG: "<<message<<endl; | |
else if(urgencylevel=="all") | |
theL()<<Logger::All<<"ALL: "<<message<<endl; | |
else if(urgencylevel=="ntlog") | |
theL()<<Logger::NTLog<<"NTLog: "<<message<<endl; | |
else | |
theL()<<Logger::None<<"NONE: "<<message<<endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment