Skip to content

Instantly share code, notes, and snippets.

@zmallen
Created October 21, 2013 19:22
Show Gist options
  • Save zmallen/7089400 to your computer and use it in GitHub Desktop.
Save zmallen/7089400 to your computer and use it in GitHub Desktop.
int logLua(lua_State *lua)
{
// enum Urgency {All=99999,NTLog=12345,Alert=LOG_ALERT, Critical=LOG_CRIT, Error=LOG_ERR, Warning=LOG_WARNING,
// Notice=LOG_NOTICE,Info=LOG_INFO, Debug=LOG_DEBUG, None=-1};
// 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