ProductPromotion
Logo

Lua

made by https://0x3d.site

GitHub - moteus/lua-log: Asynchronous logging library for Lua
Asynchronous logging library for Lua. Contribute to moteus/lua-log development by creating an account on GitHub.
Visit Site

GitHub - moteus/lua-log: Asynchronous logging library for Lua

GitHub - moteus/lua-log: Asynchronous logging library for Lua

Logging library for Lua 5.1/5.2

Build Status Build Status Licence


Usage

Write to roll file and to console

local LOG = require "log".new(
  -- maximum log level
  "trace",

  -- Writer
  require 'log.writer.list'.new(               -- multi writers:
    require 'log.writer.console.color'.new(),  -- * console color
    require 'log.writer.file.roll'.new(        -- * roll files
      './logs',                                --   log dir
      'events.log',                            --   current log name
      10,                                      --   count files
      10*1024*1024                             --   max file size in bytes
    )
  ),

  -- Formatter
  require "log.formatter.concat".new()
)

LOG.error("some", "error")

Write to file from separate thread

local LOG = require "log".new(
  require "log.writer.async.zmq".new(
    'inproc://async.logger',
    function() -- calls from separate thread/Lua state
      return require 'log.writer.file.by_day'.new(
        './logs', 'events.log', 5000
      )
    end
  )
)

LOG.error("some error")

More complex example

local host = arg[1] or '127.0.0.1'
local port = arg[2] or 514

-- this code run in separate thread.
local InitWriter = [[
  return require 'log.writer.list'.new(                  -- multi writers:
    require 'log.writer.console.color'.new(),            -- * console color
    require 'log.writer.net.zmq'.new('%{zmq_cnn_host}'), -- * zmq pub socket
    require "log.writer.format".new(                     -- * syslog over udp
      require "log.logformat.syslog".new("user"),
      require 'log.writer.net.udp'.new('%{udp_cnn_host}', %{udp_cnn_port})
    )
  )
]]

-- create async writer and run new work thread.
-- communicate with work thread using zmq library
local writer = require "log.writer.async.zmq".new(
  'inproc://async.logger', 
  InitWriter:gsub('%%{(.-)}', {
    zmq_cnn_host = 'tcp://' .. host .. ':' .. port;
    udp_cnn_host = host;
    udp_cnn_port = port;
  })
)

-- create new logger
local LOG = require"log".new(writer)

require "socket".sleep(0.5) -- net.zmq need time to connect

LOG.fatal("can not allocate memory")
LOG.error("file not found")
LOG.warning("cache server is not started")
LOG.info("new message is received")
LOG.notice("message has 2 file")

print("Press enter ...") io.flush() io.read()

Sendout logs to separate process/host

This example show how to send logs in 2 separate destination with 2 formats. Write to stdout as whell as to remote syslog server. In fact here no async on Lua side. Application write to network directly from main thread. But it is possible use one or more work threads that will do this.

-- Buld writer with 2 destinations
local writer = require "log.writer.list".new(
  require "log.writer.format".new(
    -- explicit set logformat to stdout writer
    require "log.logformat.default".new(), 
    require "log.writer.stdout".new()
  ),
  -- define network writer.
  -- This writer has no explicit format so it will
  -- use one defined for logger.
  require "log.writer.net.udp".new('127.0.0.1', 514)
)

local function SYSLOG_NEW(level, ...)
  return require "log".new(level, writer,
    require "log.formatter.mix".new(),
    require "log.logformat.syslog".new(...)
  )
end

local SYSLOG = {
  -- Define first syslog logger with some settings
  KERN = SYSLOG_NEW('trace', 'kern'),
  
  -- Define second syslog logger with other settings
  USER = SYSLOG_NEW('trace', 'USER'),
}

SYSLOG.KERN.emerg ('emergency message')
SYSLOG.USER.alert ('alert message')

Dependences

core

writer.async.udp

writer.async.zmq

writer.async.lane

  • LuaLanes - This is experemental writer

writer.console.color

  • ansicolors
  • or lua-conio
  • or cio (Windows only)

writer.file.by_day

writer.net.udp

writer.net.zmq

writer.net.smtp

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory