log

package
v0.0.0-...-04c1826 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2020 License: MIT Imports: 8 Imported by: 0

README

日志组件

对 go.uber.org/zap 的封装,按照时间和日志类型分割

feature

  • 设置日志级别
  • 集成 trace ID

usage

package main

import (
	"context"

	"github.com/strconv/valyria/log"
)

func init() {
	// info、debug、error
	log.Init("debug")
}

func main() {
	log.Debug("an debug log")
	log.For(context.Background(), "func", "log_test").Infof("an info log |msg:%s|", "have fun! ")
	log.Error("an error log")
}

todo

  • 打印频率 day、hour
  • 添加client-log
  • 添加gin-log

参考

https://www.liwenzhou.com/posts/Go/zap/ https://www.cnblogs.com/Me1onRind/p/10918863.html https://studygolang.com/articles/25044?fr=sidebar

Documentation

Index

Constants

View Source
const (
	TraceIDKey = "trace_id"
)

Variables

This section is empty.

Functions

func Debug

func Debug(v ...interface{})

func Debugf

func Debugf(format string, v ...interface{})

func Error

func Error(v ...interface{})

func Errorf

func Errorf(format string, v ...interface{})

func Fatal

func Fatal(v ...interface{})

func Fatalf

func Fatalf(format string, v ...interface{})

func For

func For(ctx context.Context, args ...interface{}) *zap.SugaredLogger

trace id

func GinLogger

func GinLogger() gin.HandlerFunc

func Info

func Info(v ...interface{})

func Infof

func Infof(format string, v ...interface{})

func Init

func Init(level string)

func Warn

func Warn(v ...interface{})

func Warnf

func Warnf(format string, v ...interface{})

Types

type OrmLogger

type OrmLogger struct {
}

func NewGormLogger

func NewGormLogger() *OrmLogger

func (*OrmLogger) Print

func (o *OrmLogger) Print(v ...interface{})

Jump to

Keyboard shortcuts

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