logger

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2022 License: Apache-2.0 Imports: 16 Imported by: 7

README

logger

The isc-gobase's logger package provides a fast and simple logger dedicated to format output.

logger API is designed to provide both a great developer experience and stunning performance. Its unique chaining API allows zerolog to write JSON (or CBOR) log events by avoiding allocations and reflection.

Uber's zap library pioneered this approach.

To keep the code base and the API simple, zerolog focuses on efficient structured logging only. Pretty logging on the console is made possible using the provided (but inefficient) zerolog.ConsoleWriter.

Installation

go get github.com/isyscore/isc-gobase

Getting started

simple Logging Example
package main

import (
	"github.com/isyscore/isc-gobase/logger"
)

func main() {
    logger.Info("my test info %s","i am info")
	logger.Warn("my test warn %s","i am warn")
	logger.Error("my test error %s","i am error")
}
base:
  logger:
    # 日志root级别:trace/debug/info/warn/error/fatal/panic,默认:info
    level: info
    # 日志打印的文件路径:full:全路径,short:半路径。默认:short
    path: full/short
    time:
      # 时间格式,time包中的内容
      format: time.RFC3339
    # 日志颜色
    color:
      # 启用:true/false,默认:false
      enable: false
    split:
      # 日志是否启用切分:true/false,默认false
      enable: false
      # 日志拆分的单位:MB
      size: 300
    max:
      ## 日志文件最大保留天数
      history: 7
    ## 日志文件目录,默认工程目录的logs文件夹
    dir: ./logs/
    ## 是否将console信息打印到文件app-console.log,默认false
    console:
      writeFile: false

线上日志级别动态修改

支持线上动态的日志修改

curl -X PUT http://localhost:xxx/{api-prefix}/{api-module}/config/update -d '{"key":"base.logger.level", "value":"debug"}'

提示:
目前日志级别粒度比较粗,比如修改了级别为debug后,则大于等于debug的级别都会打印,粒度还是比较粗,建议后续增加日志分组概念

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Assert

func Assert(format string, v ...any)

func ConfigChangeListener added in v1.1.1

func ConfigChangeListener(event listener.BaseEvent)

func Debug

func Debug(format string, v ...any)

func Error

func Error(format string, v ...any)

func Fatal added in v1.0.13

func Fatal(format string, v ...any)

func Info

func Info(format string, v ...any)

func InitLog added in v0.7.0

func InitLog(appName string)

InitLog create a root logger. it will write to console and multiple file by level. note: default set root logger level is info it provides custom log with CustomizeFiles,if it matches any caller's name ,log's level will be setting debug and output

func Panic added in v1.0.13

func Panic(format string, v ...any)

func SetGlobalLevel added in v0.7.0

func SetGlobalLevel(strLevel string)

SetGlobalLevel sets the global override for log level. If this values is raised, all Loggers will use at least this value.

To globally disable logs, set zerolog.GlobalLevel to be Disabled.

func Warn

func Warn(format string, v ...any)

Types

type FileLevelWriter added in v0.9.0

type FileLevelWriter struct {
	*os.File
	// contains filtered or unexported fields
}

func (*FileLevelWriter) WriteLevel added in v0.9.0

func (lw *FileLevelWriter) WriteLevel(level zerolog.Level, p []byte) (n int, err error)

type Handler added in v1.0.13

type Handler interface {
	//Dup2 THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
	Dup2(newfd *FileLevelWriter, oldfd *os.File) (err error)
}

type Strategy added in v1.0.13

type Strategy struct {
}

func (Strategy) Dup2 added in v1.0.13

func (s Strategy) Dup2(newfd *FileLevelWriter, oldfd *os.File) (err error)

Jump to

Keyboard shortcuts

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