logger

package
v1.5.5 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: Apache-2.0 Imports: 15 Imported by: 7

README

logger

基本用法

package main

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

func main() {
    logger.Debug("hello %v", "debug")
    logger.Info("hello %v", "info")
    logger.Warn("hello %v", "warn")
    logger.Error("hello %v", "error")
}

配置

base:
  logger:
    level: info
    # 日志文件目录,默认工程目录的logs文件夹
    home: ./logs/
    color:
      # 启用:true/false,默认:false
      enable: false
    # 日志滚动策略
    rotate:
      # 日志滚动size;默认300MB
      max-size: 300MB
      # 日志文件最大保留天数;默认60天
      max-history: 60d
      # 多久滚动一次;默认一天
      time: 1d
    path:
      # 日志展示格式:full-全路径;short-短路径;默认short
      type: short
    # 指定分组
    group:
      # 分组1
      group1:
        # 分组1的日志级别
        level: info
      # 分组2
      group2:
        # 分组2的日志级别
        level: debug

更多用法

1. 分组打印

对日志进行精细化管控,这里增加日志分组功能,其中默认分组为"root",我们可以指定我们自己的分组,在代码中不同的业务代码中使用不同的分组,这样在需要的情况下,我们可以对该模块的日志级别进行精细化控制

package main

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

func main() {
    logger.Group("group1").Info("hello", " ", "info")
    logger.Group("group1").Infof("hello %v", "info")
}
2. 线上日志级别动态修改

支持线上动态的日志修改,base.logger.level为默认分组的日志级别,如下修改为默认分组

2.1 root默认分组修改
curl -X PUT http://localhost:xxx/{api-prefix}/{api-module}/config/update -d '{"key":"base.logger.level", "value":"debug"}'
func main() {
    // 设置为debug后,如下的debug级别能够记录到日志中
    logger.Debug("hello %v", "debug1")
}
2.2 指定分组修改

如下为指定group名字为xxx的,设置日志级别为debug

curl -X PUT http://localhost:xxx/{api-prefix}/{api-module}/config/update -d '{"key":"base.logger.group.xxxx.level", "value":"debug"}'
func main() {
    // 如下的日志就会被打印出来,否则默认info级别是不打印的
    logger.Group("group1").Debugf("hello %v", "debug")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigChangeListener added in v1.1.1

func ConfigChangeListener(event listener.BaseEvent)

func Debug

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

func DebugDirect added in v1.5.2

func DebugDirect(v ...any)

func Error

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

func ErrorDirect added in v1.5.2

func ErrorDirect(v ...any)

func Fatal added in v1.0.13

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

func FatalDirect added in v1.5.2

func FatalDirect(v ...any)

func Group added in v1.5.0

func Group(groupNames ...string) *logrus.Logger

func Info

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

func InfoDirect added in v1.5.2

func InfoDirect(v ...any)

func InitLog added in v0.7.0

func InitLog()

func Panic added in v1.0.13

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

func PanicDirect added in v1.5.2

func PanicDirect(v ...any)

func Record added in v1.4.1

func Record(level, format string, v ...any)

func SetGlobalLevel added in v0.7.0

func SetGlobalLevel(strLevel string)

func Trace added in v1.5.2

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

func TraceDirect added in v1.5.2

func TraceDirect(v ...any)

func Warn

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

func WarnDirect added in v1.5.2

func WarnDirect(v ...any)

Types

type StandardFormatter added in v1.5.0

type StandardFormatter struct{}

func (*StandardFormatter) Format added in v1.5.0

func (m *StandardFormatter) Format(entry *logrus.Entry) ([]byte, error)

Jump to

Keyboard shortcuts

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