Home

The union of all files from all check-ins in the top-level directory


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)

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 "%e" == true then enironment is checked for:

LOG_FORMAT_MESSAGE
LOG_FORMAT_DATE
and LOG_LEVEL (LOG_err, LOG_file, ..)

example

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/mdkmde/flog_lua/ - 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.