Categorygithub.com/sinlovgo/log
modulepackage
1.0.0
Repository: https://github.com/sinlovgo/log.git
Documentation: pkg.go.dev

# README

Introduction

The log package refers to lexkong/log, and some convenience changes The function is exactly the same, because the original author is no longer maintained and does not support go mod

The log packages commonly used when develop by Go:

  • log
  • glog
  • logrus

log and glog are relatively simple and cannot meet production-level program development. logrus is powerful, but not support rotate. You need to rotate the log file by an external program yourself. This log package summarizes the requirements commonly used in enterprise development, and integrates these functions in a log package. After testing, the performance of the log package can fully meet the needs of enterprise-level production.

Instructions

Before using the log package, you need to initialize the log package. The initialization functions are:InitWithConfig(), InitWithFile()

A simple example:

package main

import (
	"fmt"

	"github.com/sinlovgo/log"
	"github.com/sinlovgo/log/lager"
)

func main() {
	_ := log.InitWithFile("log.yaml", "yaml")

	for i := 0; i < 1; i++ {
		log.Infof("Hi %s, system is starting up ...", "paas-bot")
		log.Info("check-info", lager.Data{
			"info": "something",
		})

		log.Debug("check-info", lager.Data{
			"info": "something",
		})

		log.Warn("failed-to-do-somthing", lager.Data{
			"info": "something",
		})

		err := fmt.Errorf("This is an error")
		log.Error("failed-to-do-somthing", err)

		log.Info("shutting-down")
	}
}

log.yaml file content:

log:
  writers: file,stdout
  logger_level: DEBUG
  logger_file: logs/log.log # if not set use FRAME_HOME env to replace or use default log/frame.log
  log_format_text: false
  rollingPolicy: size # size, daily
  log_rotate_date: 1
  log_rotate_size: 1
  log_backup_count: 7

Log parameters

  • writers: file,stdout。file will let logger_file to file,stdout will show at std, most of time use bose
  • logger_level: log level: DEBUG, INFO, WARN, ERROR, FATAL
  • logger_file: log file setting
  • log_format_text: format true will format json, false will show abs
  • rollingPolicy: rotate policy, can choose as: daily, size. daily store as daily,size will save as max
  • log_rotate_date: rotate date, coordinate rollingPolicy: daily
  • log_rotate_size: rotate size,coordinate rollingPolicy: size
  • log_backup_count: backup max count, log system will compress the log file when log reaches rotate set, this set is max file count

# Packages

No description provided by the author
No description provided by the author

# Functions

CopyFile copy file.
No description provided by the author
No description provided by the author
DefaultConfig is a function which retuns config object with default configuration.
No description provided by the author
No description provided by the author
No description provided by the author
EscapPath escape path.
No description provided by the author
No description provided by the author
FilterFileList function for filter file listpath : where the file will be filteredpat : regexp pattern to filter the matched file.
No description provided by the author
No description provided by the author
No description provided by the author
Initialize Build constructs a *Lager.Logger with the configured parameters.
No description provided by the author
readPassLagerConfigFile is unmarshal the paas lager configuration file(lager.yaml).
Init is a function which initializes all config struct variables.
LogRotate function for log rotate path: where log files need rollover MaxFileSize: MaxSize of a file before rotate.
NewLogger is a function.
NewLoggerExt is a function which is used to write new logs.
RegisterWriter is used to register a io writer.
No description provided by the author
No description provided by the author

# Constants

DEBUG is a constant of string type.
No description provided by the author
No description provided by the author
No description provided by the author
constant values for logrotate parameters.
constant values for logrotate parameters.
constant values for logrotate parameters.
constant values for logrotate parameters.
No description provided by the author

# Variables

Logger is the global variable for the object of lager.Logger.
PassLagerDefinition is having the information about loging.
Writers is a map.

# Structs

Config is a struct which stores details for maintaining logs.
Lager struct for logger parameters.
PassLagerCfg is the struct for lager information(passlager.yaml).