Help us shape the future of Go! Take the 2026 Go Developer Survey

sllog

package module
v0.0.0-...-79d7460 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2018 License: Apache-2.0 Imports: 12 Imported by: 3

README

sllog

一个基于logrus 的json 格式日志库,支持gorm 日志接入,支持日志滚动、日志删除、打印文件名、行号等功能。

使用试例

1、下载包

go get github.com/snaplingo-org/sllog

2、导入包,引用

package main

import "github.com/snaplingo-org/sllog"

func main() {
	sllog.Init(sllog.FileLogConfig{
		Path:     "./loggers",
		Filename: "./loggers/apps.log",
		MaxLines: 10000000000000,
		Maxsize:  10000000000000,
		Daily:    true,
		MaxDays:  3,
		Rotate:   true,
		Level:    sllog.DebugLevel,
	})

	logs := sllog.GetLogger()
  
        // 添加json字段
	testMap := make(map[string]interface{})
	testMap["a"] = "a"
	testMap["b"] = "b"

	logs.Info("hello")
	logs.InfoWithF(&testMap, "hello")
	logs.Infof("%s", "hello world!")
	logs.InfofWithF(&testMap, "%s", "hello ryan!")
        …
}

Documentation

Index

Constants

View Source
const (
	// PanicLevel level, highest level of severity. Logs and then calls panic with the
	// message passed to Debug, Info, ...
	PanicLevel = iota
	// FatalLevel level. Logs and then calls `os.Exit(1)`. It will exit even if the
	// logging level is set to Panic.
	FatalLevel
	// ErrorLevel level. Logs. Used for errors that should definitely be noted.
	// Commonly used for hooks to send errors to an error tracking service.
	ErrorLevel
	// WarnLevel level. Non-critical entries that deserve eyes.
	WarnLevel
	// InfoLevel level. General operational entries about what's going on inside the
	// application.
	InfoLevel
	// DebugLevel level. Usually only enabled when debugging. Very verbose logging.
	DebugLevel
)

RFC5424 log message levels.

Variables

This section is empty.

Functions

func GetLogrusLogger

func GetLogrusLogger() *logrus.Logger

GetLogrusLogger get logrus logger

func Init

func Init(config FileLogConfig)

example:

FileLogConfig{
        Path:     "./log"
		Filename: "./log/app.log",
		MaxLines: 10000000000000,
		Maxsize:  10000000000000,
		Daily:    true,
		MaxDays:  3,
		Rotate:   true,
		Level:    LevelDebug,
}

Types

type FileLogConfig

type FileLogConfig struct {
	Path     string
	Filename string
	MaxLines int
	Maxsize  int
	Daily    bool
	MaxDays  int64
	Rotate   bool
	Level    int
}

init needed config

type GormLogger

type GormLogger struct{}

func GetGormLogger

func GetGormLogger() *GormLogger

GetGormLogger get gorm logger

func (*GormLogger) Print

func (*GormLogger) Print(v ...interface{})

type Sllogger

type Sllogger struct{}

func GetLogger

func GetLogger() *Sllogger

GetLogger get sllog logger

func (*Sllogger) Debug

func (sllog *Sllogger) Debug(msg interface{})

Debug logs a message with debug log level.

func (*Sllogger) DebugWithF

func (sllog *Sllogger) DebugWithF(json *map[string]interface{}, msg interface{})

DebugWithF logs a message with Debug log level.

func (*Sllogger) Debugf

func (sllog *Sllogger) Debugf(msg string, args ...interface{})

Debugf logs a formatted message with debug log level.

func (*Sllogger) DebugfWithF

func (sllog *Sllogger) DebugfWithF(json *map[string]interface{}, msg string, args ...interface{})

DebugfWithF logs a message with Debug log level.

func (*Sllogger) Error

func (sllog *Sllogger) Error(msg interface{})

Error logs a message with error log level.

func (*Sllogger) ErrorWithF

func (sllog *Sllogger) ErrorWithF(json *map[string]interface{}, msg interface{})

ErrorWithF logs a message with error log level.

func (*Sllogger) Errorf

func (sllog *Sllogger) Errorf(msg string, args ...interface{})

Errorf logs a formatted message with error log level.

func (*Sllogger) ErrorfWithF

func (sllog *Sllogger) ErrorfWithF(json *map[string]interface{}, msg string, args ...interface{})

ErrorfWithF logs a message with error log level.

func (*Sllogger) Fatal

func (sllog *Sllogger) Fatal(msg interface{})

Fatal logs a message with fatal log level.

func (*Sllogger) FatalWithF

func (sllog *Sllogger) FatalWithF(json *map[string]interface{}, msg interface{})

FatalWithF logs a message with fatal log level.

func (*Sllogger) Fatalf

func (sllog *Sllogger) Fatalf(msg string, args ...interface{})

Fatalf logs a formatted message with fatal log level.

func (*Sllogger) FatalfWithF

func (sllog *Sllogger) FatalfWithF(json *map[string]interface{}, msg string, args ...interface{})

FatalfWithF logs a message with fatal log level.

func (*Sllogger) Info

func (sllog *Sllogger) Info(msg interface{})

Info logs a message with info log level.

func (*Sllogger) InfoWithF

func (sllog *Sllogger) InfoWithF(json *map[string]interface{}, msg interface{})

InfoWithF logs a message with info log level.

func (*Sllogger) Infof

func (sllog *Sllogger) Infof(msg string, args ...interface{})

Infof logs a formatted message with info log level.

func (*Sllogger) InfofWithF

func (sllog *Sllogger) InfofWithF(json *map[string]interface{}, msg string, args ...interface{})

InfofWithF logs a message with info log level.

func (*Sllogger) Warn

func (sllog *Sllogger) Warn(msg interface{})

Warn logs a message with warn log level.

func (*Sllogger) WarnWithF

func (sllog *Sllogger) WarnWithF(json *map[string]interface{}, msg interface{})

WarnWithF logs a message with info log level.

func (*Sllogger) Warnf

func (sllog *Sllogger) Warnf(msg string, args ...interface{})

Warnf logs a formatted message with warn log level.

func (*Sllogger) WarnfWithF

func (sllog *Sllogger) WarnfWithF(json *map[string]interface{}, msg string, args ...interface{})

WarnfWithF logs a message with warn log level.

Jump to

Keyboard shortcuts

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