Merge pull request #12 from crowdsecurity/handle_log_level

Handle log level
This commit is contained in:
he2ss 2021-09-09 15:01:45 +02:00 committed by GitHub
commit 3e8c308bce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 4 deletions

View file

@ -51,7 +51,8 @@ The configuration is located by default in `/usr/local/lua/crowdsec/crowdsec.con
```
API_URL=http://localhost:8080 <-- the API url
API_KEY= <-- the API Key generated with `cscli bouncers add -n <bouncer_name>`
LOG_FILE=/tmp/lua_mod.log <-- path to log file
LOG_FILE=/var/log/crowdsec_lua_bouncer.log <-- path to log file
LOG_LEVEL=INFO <-- log level (INFO, WARN, DEBUG, ERROR, FATAL)
CACHE_EXPIRATION=1 <-- in seconds
CACHE_SIZE=1000 <-- cache size
REQUEST_TIMEOUT=0.2 <-- Maximum duration in seconds for a request to LAPI

View file

@ -25,6 +25,27 @@ end
local csmod = {}
function getLogLevel( level )
if level and type(level)=="string" then
if level:upper() == "INFO" then
return logging.INFO
end
if level:upper() == "WARN" then
return logging.WARN
end
if level:upper() == "DEBUG" then
return logging.DEBUG
end
if level:upper() == "ERROR" then
return logging.ERROR
end
if level:upper() == "FATAL" then
return logging.FATAL
end
end
return logging.INFO
end
-- init function
function csmod.init(configFile, userAgent)
local conf, err = config.loadConfig(configFile)
@ -34,6 +55,7 @@ function csmod.init(configFile, userAgent)
runtime.conf = conf
local logger = log_file(conf["LOG_FILE"])
logger:setLevel (getLogLevel(conf["LOG_LEVEL"]))
runtime.logger = logger
runtime.userAgent = userAgent
local c, err = lrucache.new(conf["CACHE_SIZE"])

View file

@ -35,10 +35,12 @@ function config.loadConfig(file)
return nil, "File ".. file .." doesn't exist"
end
local conf = {}
local valid_params = {'API_URL', 'API_KEY', 'LOG_FILE'}
local valid_params = {'API_URL', 'API_KEY', 'LOG_FILE', 'LOG_LEVEL'}
local valid_int_params = {'CACHE_EXPIRATION', 'CACHE_SIZE', 'REQUEST_TIMEOUT'}
local default_values = {
['REQUEST_TIMEOUT'] = 0.2
['REQUEST_TIMEOUT'] = 0.2,
['LOG_FILE'] = "/var/log/crowdsec_lua_bouncer.log",
['LOG_LEVEL'] = "INFO"
}
for line in io.lines(file) do
local isOk = false

View file

@ -1,5 +1,6 @@
API_URL=http://127.0.0.1:8080
API_KEY= ${API_KEY}
LOG_FILE=/tmp/lua_mod.log
LOG_FILE=/var/log/crowdsec_lua_bouncer.log
LOG_LEVEL=INFO
CACHE_EXPIRATION=1
CACHE_SIZE=1000