mintmousse.addGlobalLogSink
Used to add a custom sink to direct log messages from across all threads in a single place. This function can only be used on the main thread.
I recommend checking out the logging sinks that the library implements to fully understand how you can implement your own.
Thread behaviour
This function can only be called on the main thread. If you can architect it, it's recommended to use the pre-thread sinks added via mintmousse.addLogSink. So, then your log isn't having to wait to be processed on the main thread.
Synopsis
Parameters
sinkfunction- A function, with the signature
(level, logger, time, debugInfo, message...). See below for details flushFuncfunction- A function, with the signature
(forced). Seemintmousse.flushLogsfor details
Sink Function Signature
levellevel- A string indicating the level of the log,
"info","warning","error","fatal","debug". loggerlogger-
The logger that created the log.
You shouldn't try to use any other function of the logger when it is in a sink other than
(Logger):getAncestryand(Logger).inspect. timenumber- UNIX time in seconds, with microseconds. By default, this value is obtained by
socket.gettimeto get an accurate system time. debugInfostring or nil- Depending on the level, and the config -- TODO link, a simple traceback string is passed along the lines of
funcName@fileName#lineNumber, this format isn't guaranteed, for example code in the file scope will befileName#lineNumberas they aren't contained within a named function. message...ANY- The varargs of the message passed from the log function.
Returns
Nothing.
Examples
Not necessarily working code, but an idea.
local http = require("socket.http")
local logs = { }
mintmousse.addGlobalLogSink(
function(level, logger, time, debugInfo, ...) -- Sink function
if (level == "error" or info == "fatal") then
table.insert(logs, table.concat({ ... }, " "))
end
end,
function(forced) -- Flush function
http.request({
url = "http://example.com/endpoint/?logs=" .. table.concat(logs, "&"),
method = "POST",
})
end
)