logs

package
v0.0.0-...-6667eb6 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2020 License: MIT Imports: 2 Imported by: 0

README

logs

package main

import (
    "context"

    "skylar-lib/logs/configor"
    "skylar-lib/logs/store/logs"
)

type Config struct {
    Logs    logs.Config
}

var (
    conf Config
)

func init() {
    if err := configor.Load("./configs/conf.toml", &conf); err != nil {
        panic(err)
    }

    logs.Init(conf.Logs)
}

func main() {
    logs.Info("hello world")
    logs.Infof("hello %s", "world")
}
#conf.toml - file
[logs]
    writer = "file"
    level  = "info"
    [logs.file_config]
        path        = "/tmp/logs/service.log"
        compress    = false
        max_size    = 1024            # 1G
        max_age     = 30              # 30 days
        max_backups = 1               # 1 copy

#conf.toml - console
[logs]
    writer = "console"
    level  = "info"

#conf.toml - file & console
[logs]
    writer = "file,console"
    level  = "info"
    [logs.file_config]
        path        = "/tmp/logs/service.log"
        compress    = false
        max_size    = 1024            # 1G
        max_age     = 30              # 30 days
        max_backups = 1               # 1 copy

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dataf

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

Dataf 打印数据日志

func Debug

func Debug(v ...interface{})

Debug 打印Debug日志

func Debugf

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

Debugf 打印Debug日志

func Error

func Error(v ...interface{})

Error 打印Error日志

func Errorf

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

Errorf 打印Error日志

func Fatal

func Fatal(v ...interface{})

Fatal 打印Fatal日志

func Fatalf

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

Fatalf 打印Fatal日志

func Info

func Info(v ...interface{})

Info 打印Info日志

func Infof

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

Infof 打印Info日志

func Init

func Init(conf *Config)

Init Log全局初始化函数 调用方保证全局调用一次

func InitData

func InitData(conf *Config)

InitData 数据Log全局初始化函数 调用方保证全局调用一次

func Warn

func Warn(v ...interface{})

Warn 打印Warn日志

func Warnf

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

Warnf 打印Warn日志

Types

type Config

type Config struct {
	Writer     string     `toml:"writer"`
	Level      string     `toml:"level"`
	FileConfig FileConfig `toml:"file_config"`
}

Config 日志配置项 Writer 可配置为 file; console; file,console

type FileConfig

type FileConfig struct {
	Path       string `toml:"path"`
	Compress   bool   `toml:"compress"`
	MaxSize    int    `toml:"max_size"`
	MaxAge     int    `toml:"max_age"`
	MaxBackups int    `toml:"max_backups"`
}

FileConfig 日志配置项 文件类型时需要配置

type Logger

type Logger interface {
	Debug(v ...interface{})
	Info(v ...interface{})
	Warn(v ...interface{})
	Error(v ...interface{})
	Fatal(v ...interface{})

	Debugf(format string, v ...interface{})
	Infof(format string, v ...interface{})
	Warnf(format string, v ...interface{})
	Errorf(format string, v ...interface{})
	Fatalf(format string, v ...interface{})
}

Logger 日志接口

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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