logger

package module
v0.0.0-...-c73c2c1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2017 License: Apache-2.0 Imports: 6 Imported by: 0

README

logger

It's a tool for free log by golang.

How to use
  1. Run the order

    go get "github.com/Shadas/logger"
    
  2. Create a config object for drive the logger

    loggerConfig := logger.LoggerConfig{}
    
  3. The contents of LoggerConfig are as shown in config.sample.json

  4. Add the function InitLogger to finish the configure of logger.

    err := logger.InitLogger(loggerConfig)
    if err != nil {
       log.Println(err.Error())
    }
    
    ...(business code)
    
  5. Then you can use it by

    logger.Log(logger.DEBUG, "debug thing1")
    
      logger.Log(logger.DEBUG, "debug thing2")
    
    logger.Log(logger.ERROR, "error thing1")
    
    logger.Log(logger.INFO, "info thing1")
    
  6. Do not forget to close the logger in the end.

    ...
    defer logger.CloseLogger()
    
Features
  1. Log classify. There are 5 kinds of log can be chosen. They are DEBUG, INFO, WARNING, ERROR, FATAL low-to-high. If you print a high class log, it will be print in the lower logs at the same time.

    The different log message will be written in different files.

  2. Asynchronous write. The messages will be put in a channel first, one other thread will get it from the channel and write to the file.

  3. Full write. If there are still some messages in the channel while the main thread is over, the CloseLogger function will ensure the messages can be written to the file before the program exit.

  4. Separate file. Configure the config object, set SeparateFileByDate as true, the files will be separated by date like '2017-1-7_DEBUG.log, 2017-1-8_DEBUG.log' etc.w

Documentation

Index

Constants

View Source
const (
	DEBUG = iota
	INFO
	WARNING
	ERROR
	FATAL
)

Variables

This section is empty.

Functions

func CloseLogger

func CloseLogger()

func InitLogger

func InitLogger(config LoggerConfig) error

func Log

func Log(level int, infos ...interface{})

Types

type Level

type Level int

type LoggerConfig

type LoggerConfig struct {
	LogPath            string   `json:"log_path"`
	LogLevel           string   `json:"log_level"`
	LogRange           []string `json:"log_range"`
	LogBuffer          int      `json:"log_buffer"`
	SeparateFileByDate bool     `json:"separate_file_by_date"`
}

type WriteModel

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

Jump to

Keyboard shortcuts

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