Artifact Content

Artifact 46100f2cb6afb5399b719def1f21f01761950a7776770674dd269ffdb541bc37:


flog = [[ a simple, fast/functional log module for lua ]]

-- usage
local log_config = {
  err=string.format("%d:identifier", syslog.err),
  file="/var/log/file.log",
  pipe="|cat",
  stdout="(m(=d= =m=)m)(d(%s)d)=stdout",

-- table can contain optional fields for env and global format setup:
  ["%e"] = false,
  ["%d"] = "!%Y/%m/%d-%H:%M:%S",
  ["%m"] = "=d= =l= =m=\n",
  ["%s"] = syslog,
}

-- secure implementation, that works without config, or flog missing - log_config is the optional configured log table
local islog, flog = pcall(require, "flog")
local nolog = function() end
local log = islog and flog.init(log_config or {}) or setmetatable({}, {__index = function() return nolog end})

log.err("Hello World!")
local name = "World"
log.file("Hello %s!", name)
log.notdefined("Hello") -- no output / no error (-> log = flog.init() no logging is done)


format_options = [[
syslog just gets the message, no format else options can be (in mixed order) before file name

file modes - writer default: open, write, close
  n: syslog.[emerg|alert|crit|err|warning|notice|info|debug]
  | file -> pipe (|logger)
  > new file (default append)
  - only once open, continuous write
  = only once open, continuous write, flush
  (d( date format )d)
  (m( message format )m) -> =d= date, =l= level, =m= message
]]


if log_config["%e"] == true then
  enironment_is_checked_for = {
    ["%m"] = LOG_FORMAT_MESSAGE,
    ["%d"] = LOG_FORMAT_DATE,
    LEVEL = LOG_LEVEL,
    err = LOG_err,
    file = LOG_file,
  }
end


example_shell_call = [[
LOG_c="stdout" lua -e 'flog=require("flog"); log=flog.init({a="stdout", b="|(m(=d= (=m=)\n)m)(d(%s)d)=cat", ["%e"] = true}); for _, x in pairs({"a", "b", "c", "d"}) do log[x]("test"); end;'
]]

license = [[
https://chiselapp.com/user/mdiener/repository/flog/ - matthias (at) koerpermagie.de

Copyright (c) ISC License

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
]]