← 全部工具

edimatt/log4u

热度 70 更新于 网络与系统管理

A lightweight POSIX shell logging library with configurable levels, console colors and independent file/console output.

githubauto-collected

安装

暂未验证可直接使用的安装命令,请查看项目官方文档或 Release。

LOG4U

Logging library for POSIX-compatible shell scripts. The purpose of this library is to provide a simple interface for logging in Unix scripts.

Why log4u?

echo and printf are ideal for individual messages, but a growing script quickly repeats timestamp formatting, level checks, stream selection, and file redirection. Log4u centralizes those concerns behind a small POSIX shell API, with independent console and file thresholds and no application runtime.

The system logger command is the right choice when messages belong in syslog or the platform journal. Log4u instead targets self-contained scripts that need predictable terminal output, a dedicated logfile, or both. It complements system logging rather than replacing it.

Architecture

Application script
        │
        ▼
    log4u API
        │
  ┌─────┴─────┐
  ▼           ▼
Console   File writer
stdout/   configured
stderr    logfile

Console and file outputs apply their own level threshold. ANSI colors are limited to the console path, while file entries remain plain text.

API quick reference

| Function | Purpose | | --- | --- | | log4udebug [message ...] | Write a debug message | | log4uinfo [message ...] | Write an informational message | | log4uwarn [message ...] | Write a warning to stderr | | log4uerror [message ...] | Write an error to stderr | | log4ufail [message ...] | Write a fatal-condition message to stderr | | log4uinit config | Validate and apply a configuration file | | log4ureset | Restore the default configuration | | log4ustatus | Display the active configuration | | log4usetconsolelevel level | Change the console threshold | | log4ugetconsolelevel | Display the console threshold | | log4usetfilelevel level | Change the file threshold | | log4ugetfilelevel | Display the file threshold |

Installation

All you need is the log4u module. Optionally, write your own configuration file.

Manual

The log4u(7) manual is the complete quick reference, including the API, configuration properties, return codes, output format, and copy-ready examples. View it locally with:

man ./man/log4u.7

Compatibility

Log4u targets the POSIX sh language and does not require Bash- or KornShell-specific features. It is tested with a POSIX shell; Bash and ksh can also source it in their POSIX-compatible modes.

Usage