{"id":13809582,"url":"https://github.com/moteus/lua-log","last_synced_at":"2026-03-27T02:59:14.835Z","repository":{"id":4374146,"uuid":"5510793","full_name":"moteus/lua-log","owner":"moteus","description":"Asynchronous logging library for Lua","archived":false,"fork":false,"pushed_at":"2018-09-19T21:15:01.000Z","size":168,"stargazers_count":110,"open_issues_count":2,"forks_count":19,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-15T06:13:42.565Z","etag":null,"topics":["logging","lua"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/moteus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-08-22T14:45:56.000Z","updated_at":"2024-12-04T03:11:27.000Z","dependencies_parsed_at":"2022-09-23T21:32:12.024Z","dependency_job_id":null,"html_url":"https://github.com/moteus/lua-log","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moteus%2Flua-log","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moteus%2Flua-log/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moteus%2Flua-log/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moteus%2Flua-log/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moteus","download_url":"https://codeload.github.com/moteus/lua-log/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249016638,"owners_count":21198833,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["logging","lua"],"created_at":"2024-08-04T02:00:31.614Z","updated_at":"2026-03-27T02:59:14.729Z","avatar_url":"https://github.com/moteus.png","language":"Lua","readme":"# Logging library for Lua 5.1/5.2\r\n\r\n[![Build Status](https://buildhive.cloudbees.com/job/moteus/job/lua-log/badge/icon)](https://buildhive.cloudbees.com/job/moteus/job/lua-log/)\r\n[![Build Status](https://travis-ci.org/moteus/lua-log.svg?branch=master)](https://travis-ci.org/moteus/lua-log)\r\n[![Licence](http://img.shields.io/badge/Licence-MIT-brightgreen.svg)](LICENCE.txt)\r\n\r\n***\r\n\r\n## Usage ##\r\n\r\n### Write to roll file and to console ###\r\n\r\n```lua\r\nlocal LOG = require \"log\".new(\r\n  -- maximum log level\r\n  \"trace\",\r\n\r\n  -- Writer\r\n  require 'log.writer.list'.new(               -- multi writers:\r\n    require 'log.writer.console.color'.new(),  -- * console color\r\n    require 'log.writer.file.roll'.new(        -- * roll files\r\n      './logs',                                --   log dir\r\n      'events.log',                            --   current log name\r\n      10,                                      --   count files\r\n      10*1024*1024                             --   max file size in bytes\r\n    )\r\n  ),\r\n\r\n  -- Formatter\r\n  require \"log.formatter.concat\".new()\r\n)\r\n\r\nLOG.error(\"some\", \"error\")\r\n```\r\n\r\n### Write to file from separate thread ###\r\n\r\n```lua\r\nlocal LOG = require \"log\".new(\r\n  require \"log.writer.async.zmq\".new(\r\n    'inproc://async.logger',\r\n    function() -- calls from separate thread/Lua state\r\n      return require 'log.writer.file.by_day'.new(\r\n        './logs', 'events.log', 5000\r\n      )\r\n    end\r\n  )\r\n)\r\n\r\nLOG.error(\"some error\")\r\n```\r\n\r\n### More complex example ###\r\n\r\n```lua\r\nlocal host = arg[1] or '127.0.0.1'\r\nlocal port = arg[2] or 514\r\n\r\n-- this code run in separate thread.\r\nlocal InitWriter = [[\r\n  return require 'log.writer.list'.new(                  -- multi writers:\r\n    require 'log.writer.console.color'.new(),            -- * console color\r\n    require 'log.writer.net.zmq'.new('%{zmq_cnn_host}'), -- * zmq pub socket\r\n    require \"log.writer.format\".new(                     -- * syslog over udp\r\n      require \"log.logformat.syslog\".new(\"user\"),\r\n      require 'log.writer.net.udp'.new('%{udp_cnn_host}', %{udp_cnn_port})\r\n    )\r\n  )\r\n]]\r\n\r\n-- create async writer and run new work thread.\r\n-- communicate with work thread using zmq library\r\nlocal writer = require \"log.writer.async.zmq\".new(\r\n  'inproc://async.logger', \r\n  InitWriter:gsub('%%{(.-)}', {\r\n    zmq_cnn_host = 'tcp://' .. host .. ':' .. port;\r\n    udp_cnn_host = host;\r\n    udp_cnn_port = port;\r\n  })\r\n)\r\n\r\n-- create new logger\r\nlocal LOG = require\"log\".new(writer)\r\n\r\nrequire \"socket\".sleep(0.5) -- net.zmq need time to connect\r\n\r\nLOG.fatal(\"can not allocate memory\")\r\nLOG.error(\"file not found\")\r\nLOG.warning(\"cache server is not started\")\r\nLOG.info(\"new message is received\")\r\nLOG.notice(\"message has 2 file\")\r\n\r\nprint(\"Press enter ...\") io.flush() io.read()\r\n```\r\n\r\n### Sendout logs to separate process/host\r\n\r\nThis example show how to send logs in 2 separate destination\r\nwith 2 formats. Write to stdout as whell as to remote syslog\r\nserver. In fact here no async on Lua side. Application write\r\nto network directly from main thread. But it is possible use\r\none or more work threads that will do this.\r\n\r\n```Lua\r\n-- Buld writer with 2 destinations\r\nlocal writer = require \"log.writer.list\".new(\r\n  require \"log.writer.format\".new(\r\n    -- explicit set logformat to stdout writer\r\n    require \"log.logformat.default\".new(), \r\n    require \"log.writer.stdout\".new()\r\n  ),\r\n  -- define network writer.\r\n  -- This writer has no explicit format so it will\r\n  -- use one defined for logger.\r\n  require \"log.writer.net.udp\".new('127.0.0.1', 514)\r\n)\r\n\r\nlocal function SYSLOG_NEW(level, ...)\r\n  return require \"log\".new(level, writer,\r\n    require \"log.formatter.mix\".new(),\r\n    require \"log.logformat.syslog\".new(...)\r\n  )\r\nend\r\n\r\nlocal SYSLOG = {\r\n  -- Define first syslog logger with some settings\r\n  KERN = SYSLOG_NEW('trace', 'kern'),\r\n  \r\n  -- Define second syslog logger with other settings\r\n  USER = SYSLOG_NEW('trace', 'USER'),\r\n}\r\n\r\nSYSLOG.KERN.emerg ('emergency message')\r\nSYSLOG.USER.alert ('alert message')\r\n```\r\n\r\n## Dependences ##\r\n\r\n### core ###\r\n* [LuaDate](https://github.com/Tieske/date)\r\n\r\n### writer.async.udp ###\r\n* [llthreads2](http://github.com/moteus/lua-llthreads2)\r\n* or [llthreads](http://github.com/Neopallium/lua-llthreads)\r\n* writer.net.udp\r\n\r\n### writer.async.zmq ###\r\n* [llthreads2](http://github.com/moteus/lua-llthreads2)\r\n* or [llthreads](http://github.com/Neopallium/lua-llthreads)\r\n* writer.net.zmq\r\n\r\n### writer.async.lane ###\r\n* [LuaLanes](https://github.com/LuaLanes/lanes) - This is experemental writer\r\n\r\n### writer.console.color ###\r\n* ansicolors\r\n* or lua-conio\r\n* or cio (Windows only)\r\n\r\n### writer.file.by_day ###\r\n* [lfs](http://keplerproject.github.com/luafilesystem)\r\n\r\n### writer.net.udp ###\r\n* [LuaSocket](http://www.impa.br/~diego/software/luasocket)\r\n\r\n### writer.net.zmq ###\r\n* [lzmq](http://github.com/moteus/lzmq)\r\n* or [lua-zmq](http://github.com/Neopallium/lua-zmq)\r\n\r\n### writer.net.smtp ###\r\n* [LuaSocket](http://www.impa.br/~diego/software/luasocket)\r\n* [lua-sendmail](http://github.com/moteus/lua-sendmail)\r\n","funding_links":[],"categories":["Logging","Resources","Lua"],"sub_categories":["Logging"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoteus%2Flua-log","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoteus%2Flua-log","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoteus%2Flua-log/lists"}