Skip to content

cj2a7t/lua-ffi-logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lua FFI Logger

A high-performance logging library for Lua using Rust's tracing framework via FFI.

Features

  • High Performance: Built with Rust for optimal performance
  • Flexible Logging Levels: Support for trace, debug, info, warn, and error levels
  • Log Rotation: Configurable time-based and size-based log rotation
  • Cross Platform: Works on macOS, Linux, and Windows
  • Easy Integration: Simple Lua FFI interface

Quick Start

Build

./build.sh

Usage

local logger_module = require "lua.loggger"

-- Create a logger with hourly rotation
local logger = logger_module.create_logger("logs/app.log", "info", 3600, 24, -1)

-- Log messages
logger:info("Application started")
logger:debug("Debug information")
logger:warn("Warning message")
logger:error("Error occurred")

Example

Run the example:

luajit example/example.lua

API

Logger Creation

local logger = logger_module.create_logger(log_path, log_level, interval, max_kept, max_size)

Parameters:

  • log_path: Log file path (default: "logs/app.log")
  • log_level: Logging level - "trace", "debug", "info", "warn", "error" (default: "info")
  • interval: Rotation interval in seconds (0 = no time rotation)
  • max_kept: Maximum number of log files to keep
  • max_size: Maximum file size in bytes (-1 = no size rotation)

Logging Methods

logger:trace("message")
logger:debug("message")
logger:info("message")
logger:warn("message")
logger:error("message")
logger:log(level, "message")  -- Generic logging

Requirements

  • Rust (for building)
  • LuaJIT with FFI support
  • Cargo

About

A high-performance logging library for Nginx/Lua using Rust FFI, designed for high-concurrency business logging scenarios.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors