logging

package
v0.3.1-alpha.hotfix1 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2025 License: LGPL-3.0 Imports: 7 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitGlobal

func InitGlobal(cfg *ZeroLoggerConfig) error

InitGlobal 初始化全局日志实例

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 ILogger

type ILogger interface {
	Debug(msg string)
	Info(msg string)
	Warn(msg string)
	Error(msg string, err error)
}

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) Debug

func (l *ZeroLogger) Debug(msg string)

Debug 记录调试级别日志

func (*ZeroLogger) Error

func (l *ZeroLogger) Error(msg string, err error)

Error 记录错误级别日志

func (*ZeroLogger) Info

func (l *ZeroLogger) Info(msg string)

Info 记录信息级别日志

func (*ZeroLogger) LogAccess

func (l *ZeroLogger) LogAccess(log AccessLog)

LogAccess 记录访问日志

func (*ZeroLogger) Warn

func (l *ZeroLogger) Warn(msg string)

Warn 记录警告级别日志

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 添加多个字段

type ZeroLoggerConfig

type ZeroLoggerConfig struct {
	Level   string `mapstructure:"level" json:"level"`
	Format  string `mapstructure:"format" json:"format"`
	Output  string `mapstructure:"output" json:"output"`
	Verbose bool   `mapstructure:"verbose" json:"verbose"`
}

Jump to

Keyboard shortcuts

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