Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add log levels. #160

Merged
merged 1 commit into from
Dec 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions falco.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ json_output: false
log_stderr: true
log_syslog: true

# Minimum log level to include in logs. Note: these levels are
# separate from the priority field of rules. This refers only to the
# log level of falco's internal logging. Can be one of "emergency",
# "alert", "critical", "error", "warning", "notice", "info", "debug".
log_level: info


# Where security notifications should go.
# Multiple outputs can be enabled.
Expand Down
4 changes: 4 additions & 0 deletions userspace/falco/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ void falco_configuration::init(string conf_filename, list<string> &cmdline_optio
throw invalid_argument("Error reading config file (" + m_config_file + "): No outputs configured. Please configure at least one output file output enabled but no filename in configuration block");
}

string log_level = m_config->get_scalar<string>("log_level", "info");

falco_logger::set_level(log_level);

falco_logger::log_stderr = m_config->get_scalar<bool>("log_stderr", false);
falco_logger::log_syslog = m_config->get_scalar<bool>("log_syslog", true);
}
Expand Down
50 changes: 50 additions & 0 deletions userspace/falco/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,62 @@ along with falco. If not, see <http://www.gnu.org/licenses/>.
#include "logger.h"
#include "chisel_api.h"

#include "falco_common.h"

const static struct luaL_reg ll_falco [] =
{
{"syslog", &falco_logger::syslog},
{NULL,NULL}
};

int falco_logger::level = LOG_INFO;

void falco_logger::init(lua_State *ls)
{
luaL_openlib(ls, "falco", ll_falco, 0);
}

void falco_logger::set_level(string &level)
{
if(level == "emergency")
{
falco_logger::level = LOG_EMERG;
}
else if(level == "alert")
{
falco_logger::level = LOG_ALERT;
}
else if(level == "critical")
{
falco_logger::level = LOG_CRIT;
}
else if(level == "error")
{
falco_logger::level = LOG_ERR;
}
else if(level == "warning")
{
falco_logger::level = LOG_WARNING;
}
else if(level == "notice")
{
falco_logger::level = LOG_NOTICE;
}
else if(level == "info")
{
falco_logger::level = LOG_INFO;
}
else if(level == "debug")
{
falco_logger::level = LOG_DEBUG;
}
else
{
throw falco_exception("Unknown log level " + level);
}
}


int falco_logger::syslog(lua_State *ls) {
int priority = luaL_checknumber(ls, 1);

Expand All @@ -49,6 +93,12 @@ bool falco_logger::log_stderr = true;
bool falco_logger::log_syslog = true;

void falco_logger::log(int priority, const string msg) {

if(priority > falco_logger::level)
{
return;
}

if (falco_logger::log_syslog) {
::syslog(priority, "%s", msg.c_str());
}
Expand Down
4 changes: 4 additions & 0 deletions userspace/falco/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ class falco_logger
public:
static void init(lua_State *ls);

// Will throw exception if level is unknown.
static void set_level(string &level);

// value = falco.syslog(level, message)
static int syslog(lua_State *ls);

static void log(int priority, const string msg);

static int level;
static bool log_stderr;
static bool log_syslog;
};