Open matthieumarrast opened 1 year ago
I think in syslog.py
we must catch the TypeError:
class SyslogLoggerJSONFormatter(object):
def format(self, record):
try:
return json.dumps(record.msg)
except TypeError as te:
# WHAT TO RETURN HERE
and also the "fat" stack trace is not logged anymore but what to return in order to have an mflog sent to mfadmin anyway... !?
note: we cannot return anything otherwise we'll face an error in vector.log
related to lua function fix_mflog_json
:
Feb 01 14:21:54.275 ERROR transform{component_kind="transform" component_name=fix_mflog_json component_type=lua}: vector::internal_events::lua: Error in lua script; discarding event. error=RuntimeErrorHooksProcess { source: RuntimeError("[string \"?\"]:5: attempt to perform arithmetic on a nil value (local \'k\')\nstack traceback:\n\t[C]: in metamethod \'__sub\'\n\t[string \"?\"]:5: in function <[string \"?\"]:1>") } internal_log_rate_secs=30
function definition:
[transforms.fix_mflog_json]
type = "lua"
inputs = ["syslog_mflog"]
version = "2"
hooks.process = '''
function (event, emit)
local i, j = event.log.message:find("{")
local k, l = event.log.message:reverse():find("}")
local length = event.log.message:len()
event.log.message = event.log.message:sub(i, length - k + 1)
emit(event)
end
'''
When mflog is not able to json serialize a provided log message (for example if we pass it an object), we face a "fat" stack trace in our plugin log:
This stack trace is produced with below code: