log

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

README

log SDK

找到日志模块

为了更好地提供日志功能。 为了区分环境,我们引入加入DEV(开发环境) UAT(测试环境) PRO(开发环境)

使用方式

1 日志环境变量,具体见env模块

1 对于不同的服务器环境,日志会选择不同的handle:
  例如:
      对于开发环境,会把日志打印到控制台
      对于线上,测试环境,日志会打印到远程日志中心。
    export UDP_LOG_ADDR=118.178.140.41
    export UDP_LOG_PORT=1223
    export SYSLOG_ADDR=118.178.140.41
    export SYSLOG_PORT=1224
名称 说明
UDP_LOG_ADDR UDP远程日志中心IP地址
UDP_LOG_PORT UDP远程日志中心port
SYSLOG_ADDR syslog远程日志中心IP地址
SYSLOG_PORT syslog远程日志中心port
配置

具体见Config结构体,通过Init函数实现初始化

example
import (
	"github.com/zdao-pro/sky_blue/pkg/log"
)
// main.go
func main() {
    log.Init(nil)
	log.Info("%s", "222322")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Access

func Access(format string, args ...interface{})

Access ...

func Accessc added in v1.2.8

func Accessc(ctx context.Context, format string, args ...interface{})

Accessc ...

func Debug

func Debug(format string, args ...interface{})

Debug ...

func Debugc added in v1.2.8

func Debugc(ctx context.Context, format string, args ...interface{})

Debugc ...

func Debugv added in v1.3.6

func Debugv(ctx context.Context, args ...D)

Debugv logs a message at the debug log level.

func Error

func Error(format string, args ...interface{})

Error ...

func Errorc added in v1.2.8

func Errorc(ctx context.Context, format string, args ...interface{})

Errorc ...

func Errorv added in v1.3.6

func Errorv(ctx context.Context, args ...D)

Errorv logs a message at the error log level.

func Fatalv added in v1.3.6

func Fatalv(ctx context.Context, args ...D)

Fatalv logs a message at the error log level.

func Fetal

func Fetal(format string, args ...interface{})

Fetal ...

func Fetalc added in v1.2.8

func Fetalc(ctx context.Context, format string, args ...interface{})

Fetalc ...

func Info

func Info(format string, args ...interface{})

Info ...

func Infoc added in v1.2.8

func Infoc(ctx context.Context, format string, args ...interface{})

Infoc ...

func Infov added in v1.3.6

func Infov(ctx context.Context, args ...D)

Infov logs a message at the info log level.

func Init

func Init(conf *Config)

Init ...

func Warn

func Warn(format string, args ...interface{})

Warn ...

func Warnc added in v1.2.8

func Warnc(ctx context.Context, format string, args ...interface{})

Warnc ...

func Warnv added in v1.3.6

func Warnv(ctx context.Context, args ...D)

Warnv logs a message at the warning log level.

Types

type Config

type Config struct {

	// Filter tell log handler which field are sensitive message, use * instead.
	Filter []string
	// file
	Dir string
	// stdout
	Stdout bool
	Nlog   bool
	Source bool
	// contains filtered or unexported fields
}

Config ...

type D

type D Field

D ...

func KV

func KV(key string, value interface{}) D

KV return a log kv for logging field. NOTE: use KV{type name} can avoid object alloc and get better performance. []~( ̄▽ ̄)~*干杯

func KVDuration

func KVDuration(key string, value time.Duration) D

KVDuration construct Field with Duration value.

func KVFloat32

func KVFloat32(key string, value float32) D

KVFloat32 construct Field with float32 value.

func KVFloat64

func KVFloat64(key string, value float64) D

KVFloat64 construct Field with float64 value.

func KVInt added in v1.3.6

func KVInt(key string, value int) D

KVInt construct D with int value.

func KVInt64

func KVInt64(key string, value int64) D

KVInt64 construct D with int64 value.

func KVString

func KVString(k, v string) D

KVString ...

func KVUint

func KVUint(key string, value uint) D

KVUint construct Field with uint value.

func KVUint64

func KVUint64(key string, value uint64) D

KVUint64 construct Field with uint64 value.

type Field

type Field struct {
	Key   string
	Value interface{}
	Type  FieldType
}

Field is for encoder

type FieldType

type FieldType int32

FieldType represent D value type

const (
	UnknownType FieldType = iota
	StringType
	IntTpye
	Int64Type
	UintType
	Uint64Type
	Float32Type
	Float64Type
	DurationType
)

DType enum

type Handle

type Handle interface {
	Log(context.Context, Level, ...D)
	Close() error
}

Handle ...

type Handles

type Handles struct {
	// contains filtered or unexported fields
}

Handles ...

func (Handles) Close

func (hs Handles) Close() error

Close ...

func (Handles) Log

func (hs Handles) Log(ctx context.Context, l Level, d ...D)

Log ...

type Level

type Level int

Level log level

func (Level) String

func (l Level) String() string

type Render

type Render interface {
	Render(io.Writer, ...D) error
}

Render render the string

Jump to

Keyboard shortcuts

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