logging

package
v0.1.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(cfg Config) error

Init 初始化全域 slog.Default logger,同時輸出 JSON 格式到檔案與 text 格式到 stderr。 環境變數 FOURX_LOG_LEVEL 會覆蓋 cfg.Level。若無法建立 log 目錄或檔案, 不阻擋程式啟動,改為僅輸出到 stderr。

func Middleware

func Middleware(next http.Handler) http.Handler

Middleware 回傳 HTTP request logging 的中介層。 每個 request 記錄 method、path、status code 與處理時間(毫秒)。 2xx/3xx 用 slog.Info、4xx 用 slog.Warn、5xx 用 slog.Error。

func ParseLevel

func ParseLevel(s string) slog.Level

ParseLevel 將字串轉為對應的 slog.Level。 支援 debug、info、warn、error(不分大小寫),無法辨識時回傳 slog.LevelInfo。

func Shutdown

func Shutdown()

Shutdown 關閉 log 檔案,釋放資源。應在程式結束前呼叫。

Types

type Config

type Config struct {
	Level      string
	LogDir     string
	RetainDays int
}

Config 定義 logging 初始化所需的設定參數。 Level 接受 debug/info/warn/error(預設 info),LogDir 為 log 檔目錄(預設 ~/.4x/logs/), RetainDays 為保留天數(預設 7)。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL