refactor: use nginx -s reload instead of systemd
- doc: add comment
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
// Package logging 提供结构化文本日志的创建,同时写入控制台与本地文件。
|
||||
package logging
|
||||
|
||||
import (
|
||||
@@ -11,11 +12,13 @@ import (
|
||||
|
||||
// New 创建同时写入 stdout 和本地文件的结构化文本日志。
|
||||
// stdout 由 systemd/journald 收集,本地文件用于现场诊断和受控远程读取。
|
||||
// 返回的 closer 用于在退出前同步并关闭日志文件。
|
||||
func New(filePath string) (*slog.Logger, io.Closer, error) {
|
||||
return NewWithConsole(os.Stdout, filePath)
|
||||
}
|
||||
|
||||
// NewWithConsole 允许调用方指定控制台 writer,主要用于测试和嵌入运行。
|
||||
// console 与 filePath 均不能为空;日志级别固定为 Info。
|
||||
func NewWithConsole(console io.Writer, filePath string) (*slog.Logger, io.Closer, error) {
|
||||
if console == nil {
|
||||
return nil, nil, errors.New("console writer is required")
|
||||
@@ -38,10 +41,12 @@ func NewWithConsole(console io.Writer, filePath string) (*slog.Logger, io.Closer
|
||||
return slog.New(handler), &syncFileCloser{file: file}, nil
|
||||
}
|
||||
|
||||
// syncFileCloser 负责在关闭时先同步再关闭日志文件。
|
||||
type syncFileCloser struct {
|
||||
file *os.File
|
||||
}
|
||||
|
||||
// Close 同步并关闭日志文件,重复调用是安全的。
|
||||
func (c *syncFileCloser) Close() error {
|
||||
if c == nil || c.file == nil {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user