logfly

    Logging for MoonBit: plain text and JSONL appenders with timestamps, and size-triggered log rotation

    log
    logging
    jsonl
    rotate
    append
    Download zip
    Author
    Version
    0.1.0
    License
    MIT
    Last updated
    6 hours ago
    Downloads
    1

    #chensuiyi/logfly

    Logging · 日志

    日志库:纯文本 / JSONL 两种行格式,自动 ISO 时间戳,按大小触发轮转(rename 与 copytruncate 双模式)。

    • plain:一行时间戳前缀文本——崩溃记录、人读日志
    • event:JSONL 管理事件,值传已编码片段——调用方省略的字段就不会出现在线上
    • maybe_rotate:超限轮转;文件不存在不算错
    • 依赖:chensuiyi/fsx + chensuiyi/dateku + chensuiyi/fndash

    Logging: plain text and JSONL line formats with automatic ISO timestamps, plus size-triggered rotation in rename or copytruncate mode.

    • plain: one timestamp-prefixed text line — crash records, human-read logs
    • event: a JSONL management event; values arrive as pre-encoded fragments, so fields the caller omits never appear on the wire
    • maybe_rotate: rotate past a size limit; a missing file is not an error
    • Depends on chensuiyi/fsx + chensuiyi/dateku + chensuiyi/fndash

    #API

    接口 Interface说明 Description
    plain(path, text)ts text 文本行;Timestamp-prefixed text line
    event(path, event, fields)JSONL 事件行;JSONL event line
    maybe_rotate(path, max, copytruncate?)超限轮转,返回是否轮转;Rotate past limit, returns rotated

    License: MIT

    event

    fn event(path : String, event : String, fields : Array[(String, String)]) -> Unit raise
    FileError

    Append one JSONL management event: {"ts":"...","event":"...","<key>":<value>...}. Keys are quoted by the library; values must arrive as already-encoded JSON fragments — pass @fndash.jstr(text) for strings and raw digits for numbers, so a field the caller omits simply does not appear on the wire.

    maybe_rotate

    fn maybe_rotate(path : String, max_bytes : Int64, copytruncate? : Bool) -> Bool raise
    FileError

    Rotate path once it exceeds max_bytes: copytruncate for logs held open by app processes (they keep writing to the old inode), rename for logs written by the caller itself. Returns true when a rotation ran. Raises FileError when a needed rotation failed; a missing file is not an error (nothing to rotate).

    plain

    fn plain(path : String, text : String) -> Unit raise
    FileError

    Append one plain text line, prefixed with the current ISO timestamp: 2026-10-03T08:15:30.123Z <text>. Failures raise so the caller stays in charge of best-effort handling.

    Source Files