Documentation
¶
Overview ¶
* Copyright (C) 2024 aberstone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* Copyright (C) 2024 aberstone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* Copyright (C) 2024 aberstone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Index ¶
- func InitGlobal(cfg *ZeroLoggerConfig) error
- type AccessLog
- type FakeLogger
- type ILogger
- type ZeroLogger
- func (l *ZeroLogger) Debug(msg string)
- func (l *ZeroLogger) Error(msg string, err error)
- func (l *ZeroLogger) Info(msg string)
- func (l *ZeroLogger) LogAccess(log AccessLog)
- func (l *ZeroLogger) Warn(msg string)
- func (l *ZeroLogger) WithContext(ctx context.Context) *ZeroLogger
- func (l *ZeroLogger) WithError(err error) *ZeroLogger
- func (l *ZeroLogger) WithField(key string, value interface{}) *ZeroLogger
- func (l *ZeroLogger) WithFields(fields map[string]interface{}) *ZeroLogger
- type ZeroLoggerConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AccessLog ¶
type AccessLog struct {
Protocol string // 协议
Method string // HTTP方法
URL string // 请求URL
StatusCode int // 状态码
Duration time.Duration // 处理时间
BytesSent int64 // 发送字节数
BytesRecv int64 // 接收字节数
RemoteAddr string // 远程地址
UserAgent string // User-Agent
Error error // 错误信息
}
访问日志结构
type FakeLogger ¶
type FakeLogger struct{}
func NewFakeLogger ¶
func NewFakeLogger() *FakeLogger
func (*FakeLogger) Debug ¶
func (f *FakeLogger) Debug(msg string)
func (*FakeLogger) Error ¶
func (f *FakeLogger) Error(msg string, err error)
func (*FakeLogger) Info ¶
func (f *FakeLogger) Info(msg string)
func (*FakeLogger) Warn ¶
func (f *FakeLogger) Warn(msg string)
type ZeroLogger ¶
type ZeroLogger struct {
// contains filtered or unexported fields
}
Logger 封装日志记录器
var Global *ZeroLogger
Global 全局日志实例
func NewZeroLogger ¶
func NewZeroLogger(cfg *ZeroLoggerConfig) (*ZeroLogger, error)
NewZeroLogger 创建新的日志记录器
func (*ZeroLogger) WithContext ¶
func (l *ZeroLogger) WithContext(ctx context.Context) *ZeroLogger
WithContext 创建带有上下文值的新记录器
func (*ZeroLogger) WithError ¶
func (l *ZeroLogger) WithError(err error) *ZeroLogger
WithError 记录带有错误的日志
func (*ZeroLogger) WithField ¶
func (l *ZeroLogger) WithField(key string, value interface{}) *ZeroLogger
WithField 添加字段
func (*ZeroLogger) WithFields ¶
func (l *ZeroLogger) WithFields(fields map[string]interface{}) *ZeroLogger
WithFields 添加多个字段