• Stars
    star
    107
  • Rank 311,942 (Top 7 %)
  • Language
    Lua
  • License
    MIT License
  • Created over 11 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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 Repositories

1

lua-llthreads2

`llthreads` library rewritten without `LuaNativeObjects` code generator
Lua
73
star
2

lua-path

File system path manipulation library
Lua
72
star
3

lua-lluv

Lua binding to libuv
C
66
star
4

lua-travis-example

For experiments with travis-ci
Shell
54
star
5

luacov-coveralls

LuaCov reporter for coveralls.io service
Lua
48
star
6

lua-sendmail

Simple wrapper around luasoket smtp.send
CMake
30
star
7

lua-windows-environment

Windows Lua binaries with LuaRocks and some external dependencies
C
29
star
8

lua-vararg

Library for manipulation of variable arguements of functions
Lua
25
star
9

lua-lluv-curl

Make asyncronus requests using libuv and libcurl
Lua
20
star
10

lua-lluv-websocket

Websocket for lluv library
Lua
19
star
11

ZipWriter

Library for creating ZIP archive for Lua
Lua
18
star
12

lua-odbc

ODBC Library for lua
C
18
star
13

lua-AesFileEncrypt

A simple file encryption library
C
17
star
14

lua-socket-async

Asyncronus wrapper around LuaSocket library
Lua
17
star
15

vscode-mobdebug

MobDebug Debug Adapter for Visual Studio Code
Lua
16
star
16

lua-pop3

POP3 client library for Lua
Lua
15
star
17

lua-split

Implement functions to split strings
Lua
14
star
18

lzmq-zguide

Examples from ZeroMQ Guide
Lua
13
star
19

lua-lluv-gsmmodem

Control GSM modem connected to serial port using AT commands
Lua
12
star
20

lua-spylog

Execute actions based on log records
Lua
12
star
21

lua-sqlite3

fork from http://www.nessie.de/mroth/lua-sqlite3/index.html
Lua
11
star
22

lua-lluv-pegasus

Simple server based on pegasus.lua library
Lua
9
star
23

lua-winreg

Lua binary module to Access Microsoft(R) Windows(R) Registry
C
8
star
24

lua-EventEmitter

Implement EventEmitter on Lua
Lua
8
star
25

lua-voip

Lua
8
star
26

lua-lluv-rs232

Serial port communication library for lluv library
Lua
8
star
27

lua-pegasus-router

Router plugin for Pegasus server
Lua
8
star
28

lua-environ

Manipulate with environment variables
Lua
7
star
29

NginxWinService

Service wrappers for `nginx` and `php-cgi` for Windows
Lua
7
star
30

lua-tpdu

SMS TPDU encoder/decoder
Lua
6
star
31

lua-MultiRequests

Make multiple requests from different coroutines in parallel
Lua
6
star
32

lua-lluv-ssl

SSL/TLS sockets for lluv library
Lua
6
star
33

lua-lluv-ftp

FTP client for lluv library
Lua
6
star
34

lua-ftp

Simple wrapper around LuaSocket ftp
Lua
6
star
35

lua-null

Provide special value `null` for Lua
C
6
star
36

zbs-package

Packages for ZeroBraneStudio
Lua
6
star
37

lua-Parallel

Lua
5
star
38

lua-lluv-esl

FreeSWITCH ESL implementation for lluv library
Lua
5
star
39

lua-lluv-redis

Redis client for lua-lluv library
Lua
5
star
40

luasqlite3

fork from http://lua.sqlite.org
C
5
star
41

lua-lluv-pg

PostgreSQL client based on lluv library
Lua
5
star
42

lua-lzmq-zmq

Wrapper around lzmq library to be compatiable with lua-zmq library
Lua
4
star
43

lua-pdh

Lua binding to Microsoft Performance Data Helper (PDH) library.
C
4
star
44

lzmq-pool

ZMQ socket pool
Lua
4
star
45

lua-pegasus-websocket

WebSocket plugin for Pegasus http server
Lua
4
star
46

lzmq-auth

Implementaion of czmq zauth class
Lua
4
star
47

lua-try

Simple exception support based on LuaSocket
Lua
4
star
48

lua-bgcrypto-sha

C
4
star
49

lua-luq

Light userdata queue
CMake
4
star
50

lua-prefix_tree

Lua
4
star
51

lua-websockets-permessage-deflate

Implement permessage-deflate extension
Lua
3
star
52

lua-OpenHardwareMonitor

Access to OpenHardwareMonitor WMI interface
Lua
3
star
53

lua-lluv-poll-zmq

ZMQ poller for lluv library
Lua
3
star
54

lua-WindowsFirewall

Windows Firewall configuration library
Lua
3
star
55

libmemcached-win32

Fork of https://code.launchpad.net/~mattn/libmemcached/libmemcached-win32
C
3
star
56

lua-avro

Lua
3
star
57

lua-lluv-memcached

Memcached client for lua-lluv library
Lua
3
star
58

lua-lluv-qless

Lua binding for qless - queue / pipeline management system
Lua
3
star
59

luarocks-external

External deps to be able install some binary rocks on Windows.
C
2
star
60

lua-gntp

Implementation of Growl Notify Transport Protocol (GNTP) for Lua
Lua
2
star
61

lua-odbc-pool

ODBC connections pool
Lua
2
star
62

lzmq-monitor

Implementaion of czmq zsock_monitor class
Lua
2
star
63

lbase64

Unofficial repositary of lbase64
Shell
2
star
64

lua-bgcrypto-aes

C
2
star
65

lakefiles

my lakefile for some projects
Lua
1
star
66

moteus.github.com

HTML
1
star
67

lua-lluv-busted

Support async tests for busted with lluv library
Lua
1
star
68

lua-env

Lua library to manipulate environment variables
Lua
1
star
69

lua-odbc-dbi

ODBC Driver for Lua-DBI library
Lua
1
star
70

fusionpbx-app-messenger

Application for FusionPBX to send/receive SMS messages
PHP
1
star
71

lua-websockets-extensions

WebSocket extensions manager
Lua
1
star
72

mod_h323_deps

Build deps for FreeSWITCH mod_h323 on Windows
C++
1
star