logger

package module
v1.0.15 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2022 License: AGPL-3.0 Imports: 18 Imported by: 0

README

Logger

基于Zap整合的日志框架,可自由组合输出到Console、File、Loki

Demo

package main

import (
	"git.echol.cn/loser/logger"
	"git.echol.cn/loser/logger/log"
)

func main() {
	logger.InitLogger(logger.LogConfig{Mode: logger.Dev, LokiEnable: false, FileEnable: true})
	log.Debug("芜湖")
}

环境变量

export LOG_MODE=0 # development | production
export LOG_LOKI_ENABLE=1 # 是否启用Loki 0: disable, 1: enable
export LOG_FILE_ENABLE=0 # 是否启用输出到文件 0: disable, 1: enable
export LOG_LOKI_HOST=10.0.0.31 # Loki地址
export LOG_LOKI_PORT=3100 # Loki端口
export LOG_LOKI_SOURCE_NAME=tests # Loki Source 名称
export LOG_LOKI_JOB_NAME=testj # Loki Job 名称

Documentation

Index

Constants

View Source
const (
	Dev  mode = "development"
	Prod mode = "production"
)

Variables

This section is empty.

Functions

func DefaultGormLogger

func DefaultGormLogger() gl.Interface

DefaultGormLogger 默认的日志实现

func InitLogger

func InitLogger(c LogConfig)

InitLogger 初始化日志工具

func NewGormLoggerWithConfig

func NewGormLoggerWithConfig(config gl.Config) gl.Interface

NewGormLoggerWithConfig ...

Types

type CallerHook added in v1.0.15

type CallerHook struct{}

CallerHook is a hook designed for dealing with logs in test scenarios.

func NewCallerHook added in v1.0.15

func NewCallerHook(logger *logrus.Logger) *CallerHook

NewCallerHook installs a test hook for a given local logger.

func (*CallerHook) Fire added in v1.0.15

func (t *CallerHook) Fire(e *logrus.Entry) error

func (*CallerHook) Levels added in v1.0.15

func (t *CallerHook) Levels() []logrus.Level

type LogConfig

type LogConfig struct {
	Mode       mode   `env:"LOG_MODE" envDefault:"production"` // dev, prod
	LokiEnable bool   `env:"LOG_LOKI_ENABLE"`                  // 是否启用Loki
	FileEnable bool   `env:"LOG_FILE_ENABLE"`                  // 是否输出到文件
	LokiHost   string `env:"LOG_LOKI_HOST"`                    // Loki地址
	LokiPort   int    `env:"LOG_LOKI_PORT"`                    // Loki端口
	LokiSource string `env:"LOG_LOKI_SOURCE_NAME"`             // Loki的source名称
	LokiJob    string `env:"LOG_LOKI_JOB_NAME"`                // Loki的job名称
}

LogConfig 日志配置

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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