gzap

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

README

缓存组件(redis)

如何引用

代码配置
package main

import (
    "github.com/GuoxinL/gcomponent/gzap"
    "go.uber.org/zap"
)

func main() {
    gzap.New()
    zap.L().Info("zap.L().Info", zap.Int("balabala", 1))
    zap.S().Infof("zap.S().Infof %v", "balabala")
}
配置文件(application.yaml)
components:
  zap:
    addCallerSkip: 0
    console:
      enable: true
      level: debug
      encoder:
        messageKey: msg
        levelKey: level
        timeKey: time
        nameKey: logger
        callerKey: file
        stacktraceKey: stacktrace
        lineEnding: \n
        timeFormat: 2006-01-02T15:04:05.000
    files:
      - enable: true
        level: debug
        encoder:
          messageKey: msg
          levelKey: level
          timeKey: time
          nameKey: logger
          callerKey: file
          stacktraceKey: stacktrace
          lineEnding: \n
          timeFormat: 2006-01-02T15:04:05.000
        logger:
          filename: gcomponent_zap.log
          maxsize: 128
          maxage: 7
          maxbackups: 30
          localtime:
          compress: false

Documentation

Overview

Package gzap Created by guoxin in 2020/4/13 1:34 下午

Package gzap Create by guoxin 2020.12.15

Package core Create by guoxin 2021.07.02

Package gzap Create by guoxin 2020.12.15 TODO 这里考虑下之后是否需要实现

Index

Constants

View Source
const RequestIdKey = "request_id"

Variables

This section is empty.

Functions

func GetInstance

func GetInstance() *zap.Logger

func GetRequestIdFromLocal

func GetRequestIdFromLocal() string

func ISOTimeEncoder

func ISOTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)

func New

func New(params ...interface{})

New Make sure you only initialize it once

func SetRequestIdFromLocal

func SetRequestIdFromLocal(requestId string)

Types

type Configuration

type Configuration struct {
	core.InitializeLock
	Console       Console `mapstructure:"console"`
	Files         []File  `mapstructure:"files"`
	AddCallerSkip int     `mapstructure:"addCallerSkip"`
	RequestId     bool    `mapstructure:"requestId"`
}

func (*Configuration) Initialize

func (c *Configuration) Initialize(params ...interface{}) interface{}

type Console

type Console struct {
	core.InitializeLock
	core.BEnable `mapstructure:",squash"`
	Level        string        `mapstructure:"level"`
	Encoder      EncoderConfig `mapstructure:"encoder"`
}

type EncoderConfig

type EncoderConfig struct {
	// Set the keys used for each log entry. If any key is empty, that portion
	// of the entry is omitted.
	MessageKey    string `json:"messageKey" mapstructure:"messageKey"`
	LevelKey      string `json:"levelKey" mapstructure:"levelKey"`
	TimeKey       string `json:"timeKey" mapstructure:"timeKey"`
	NameKey       string `json:"nameKey" mapstructure:"nameKey"`
	CallerKey     string `json:"callerKey" mapstructure:"callerKey"`
	StacktraceKey string `json:"stacktraceKey" mapstructure:"stacktraceKey"`
	LineEnding    string `json:"lineEnding" mapstructure:"lineEnding"`
	// Configure the primitive representations of common complex types. For
	// example, some users may want all time.Times serialized as floating-point
	// seconds since epoch, while others may prefer ISO8601 strings.
	TimeFormat string `json:"timeFormat" mapstructure:"timeFormat"`
}

type File

type File struct {
	core.BEnable `mapstructure:",squash"`
	Level        string        `mapstructure:"level"`
	Encoder      EncoderConfig `mapstructure:"encoder"`
	Logger       Logger        `mapstructure:"logger"`
}

type Files

type Files struct {
	core.BEnable `mapstructure:",squash"`
	Files        []File `mapstructure:"console"`
}

type Logger

type Logger struct {
	Filename   string `json:"filename" mapstructure:"filename"`
	MaxSize    int    `json:"maxsize" mapstructure:"maxsize"`
	MaxAge     int    `json:"maxage" mapstructure:"maxage"`
	MaxBackups int    `json:"maxbackups" mapstructure:"maxbackups"`
	LocalTime  bool   `json:"localtime" mapstructure:"localtime"`
	Compress   bool   `json:"compress" mapstructure:"compress"`
}

Logger See lumberjack.Logger

Jump to

Keyboard shortcuts

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