log

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2020 License: MIT Imports: 6 Imported by: 0

README

log

介绍

{以下是码云平台说明,您可以替换此简介 码云是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台 无论是个人、团队、或是企业,都能够用码云实现代码托管、项目管理、协作开发。企业项目请看 https://gitee.com/enterprises}

软件架构

软件架构说明

安装教程
  1. xxxx
  2. xxxx
  3. xxxx
使用说明
  1. xxxx
  2. xxxx
  3. xxxx
参与贡献
  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request
码云特技
  1. 使用 Readme_XXX.md 来支持不同的语言,例如 Readme_en.md, Readme_zh.md
  2. 码云官方博客 blog.gitee.com
  3. 你可以 https://gitee.com/explore 这个地址来了解码云上的优秀开源项目
  4. GVP 全称是码云最有价值开源项目,是码云综合评定出的优秀开源项目
  5. 码云官方提供的使用手册 https://gitee.com/help
  6. 码云封面人物是一档用来展示码云会员风采的栏目 https://gitee.com/gitee-stars/

Documentation

Overview

Package log 用于滚动将日志写入文件

示例: import gitee.com/golangx/log

logOpt := &log.Option{
		MaxSize:       128,
		MaxBackups:    7,
		MaxAge:        1,
		Debug:         debug,
		ServiceName:   serviceName,
		TimeKey:       "time",
		LevelKey:      "level",
		NameKey:       "logger",
		CallerKey:     "caller",
		MessageKey:    "msg",
		StacktraceKey: "stacktrace",
	}

logOpt.Start("/log") log.Debug("Hello, Debug!!!")

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(msg string, fields ...interface{})

Debug 记录一个debug日志

func Error

func Error(msg string, fields ...interface{})

Error 记录一个debug日志

func Info

func Info(msg string, fields ...interface{})

Info 记录一个info日志

func NewLogger

func NewLogger(filePath string, level zapcore.Level) *zap.Logger

NewLogger 新建logger

  • filePath 日志文件路径
  • level 日志级别
  • maxSize 每个日志文件保存的最大尺寸 单位:M
  • maxBackups 日志文件最多保存多少个备份
  • maxAge 文件最多保存多少天
  • compress 是否压缩
  • serviceName 服务名

func Warn

func Warn(msg string, fields ...interface{})

Warn 记录一个warn日志

Types

type LoggerImp

type LoggerImp struct {
	Base map[string]string
}

LoggerImp LoggerImp

func NewWebLogger

func NewWebLogger() *LoggerImp

NewWebLogger NewLogger

func (*LoggerImp) Debug

func (l *LoggerImp) Debug(msg string, fields ...interface{})

Debug debug日志实现

func (*LoggerImp) Error

func (l *LoggerImp) Error(msg string, fields ...interface{})

Error error日志实现

func (*LoggerImp) Info

func (l *LoggerImp) Info(msg string, fields ...interface{})

Info info日志实现

func (*LoggerImp) SetBase

func (l *LoggerImp) SetBase(base map[string]string)

SetBase 获取基础参数

func (*LoggerImp) Warn

func (l *LoggerImp) Warn(msg string, fields ...interface{})

Warn warn日志实现

type LoggerObj

type LoggerObj struct {
	*zap.Logger
}

LoggerObj zap日志

var (
	// InfoLogger info级别日志
	InfoLogger LoggerObj
	// DebugLogger debug级别日志
	DebugLogger LoggerObj
	// WarnLogger warn级别日志
	WarnLogger LoggerObj
	// ErrorLogger error级别日志
	ErrorLogger LoggerObj
)

type Option

type Option struct {
	MaxSize       int    // 每个日志文件保存的最大尺寸 单位:M
	MaxBackups    int    // 日志文件最多保存多少个备份
	MaxAge        int    // 文件最多保存多少天
	Compress      bool   // 是否压缩
	ServiceName   string // 服务名
	Debug         bool
	TimeKey       string
	LevelKey      string // 日志级别的key
	CallerKey     string // 文件和行号的key
	MessageKey    string // Message的key
	NameKey       string
	StacktraceKey string
	BaseParams    interface{} // 请求基本参数
}

Option 日志配置项

func (*Option) Start

func (o *Option) Start(dir string)

Start 使用配置项初始化日志

Jump to

Keyboard shortcuts

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