Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AsyncChannelWriter ¶
type AsyncChannelWriter struct {
// contains filtered or unexported fields
}
AsyncChannelWriter 实现异步写日志功能,实现 io.Writer 接口
func NewAsyncChannelWriter ¶
func NewAsyncChannelWriter(cfg appconfig.IAppConfig, filename string) *AsyncChannelWriter
NewAsyncChannelWriter 创建一个新的异步日志记录器
func (*AsyncChannelWriter) Close ¶
func (a *AsyncChannelWriter) Close() error
Close 关闭日志记录器,等待后台 goroutine 完成
type AsyncDiodeWriter ¶
type AsyncDiodeWriter struct {
// contains filtered or unexported fields
}
AsyncDiodeWriter 实现异步写日志功能,实现 io.Writer 接口
Example ¶
ExampleAsyncDiodeWriter 示例代码
// 创建Test配置
cfg := appconfig.NewAppConfig()
testConfig := map[string]interface{}{
"application.appLog.rollConf.maxSize": 10,
"application.appLog.rollConf.maxBackups": 3,
"application.appLog.rollConf.maxAge": 7,
"application.appLog.rollConf.compress": false,
"application.appLog.asyncConf.diodes.size": 1000000,
"application.appLog.asyncConf.diodes.bufferSize": 4096,
"application.appLog.asyncConf.diodes.flushInterval": 50,
}
cfg.LoadDefault(testConfig)
// 创建异步写入器
writer := NewAsyncDiodeWriter(cfg, "example.log")
defer func() {
if err := writer.Close(); err != nil {
// 处理关闭错误
}
}()
// 写入日志
if _, err := writer.Write([]byte("Hello, World!\n")); err != nil {
// 处理写入错误
}
if _, err := writer.Write([]byte("This is an example log message\n")); err != nil {
// 处理写入错误
}
// 等待写入完成
time.Sleep(100 * time.Millisecond) // 大于application.appLog.asyncConf.diodes.flushInterval配置项
func NewAsyncDiodeWriter ¶
func NewAsyncDiodeWriter(cfg appconfig.IAppConfig, filename string) *AsyncDiodeWriter
NewAsyncDiodeWriter 创建一个新的异步日志记录器
func (*AsyncDiodeWriter) Close ¶
func (a *AsyncDiodeWriter) Close() error
Close 关闭日志记录器,等待后台 goroutine 完成
type SyncLumberjackWriter ¶
type SyncLumberjackWriter struct {
// contains filtered or unexported fields
}
SyncLumberjackWriter 实现同步写日志功能,实现 io.Writer 接口
func NewSyncLumberjackWriter ¶
func NewSyncLumberjackWriter(cfg appconfig.IAppConfig, filename string) *SyncLumberjackWriter
func (*SyncLumberjackWriter) Close ¶
func (sw *SyncLumberjackWriter) Close() error
Click to show internal directories.
Click to hide internal directories.