logger

package module
Version: v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2021 License: MIT Imports: 12 Imported by: 0

README

logger v1.3.0

Go Logger module

This logger is a simple module to write a log file, and it allows multiple instances, concurrency write, rotation by file size (MB), backup files and log level (debug, informative, warning, error and critical)

You can load module with:

go get "github.com/jpengineer/logger"

The default implementation way is:

package main

import ("github.com/jpengineer/logger")
 
func main() {
    var logName = "MyLogName.log"
    var path = "/my/log/path"
    var level = logger.Level.DEBUG

    _log, _ := logger.Start(logName, path, level)
    _log.TimestampFormat(_logger.TS.Special)
    
    _log.Critical("This is a Critical message")
    _log.Info("This is a Informational message")
    _log.Warn("This is a Warning message")
    _log.Error("This is a Error message")
    _log.Debug("This is a Debug message")
}

If you don't specify the rotation settings, by default it will be set to 40 MB maximum size per file and 4 backup files. To change default rotation you should be considerate the next:

    var maxSizeMB = 80
    var maxBackup = 5
    
    _log.Rotation(maxSizeMB, maxBackup)

The output format is:

Logger Version: 1.2.A SourceFile: main.go Hash: XDNRdfeWUJa4BJ4gaiDWTIQJxxgW1NhxfXaK0qDnKBU=
Aug 3, 2020 12:41:25.946521 -04 [CRITICAL] This is a Critical message
Aug 3, 2020 12:41:25.946526 -04 [INFO] This is an Informational message
Aug 3, 2020 12:41:25.946557 -04 [WARN] This is a Warning message
Aug 3, 2020 12:41:25.946562 -04 [ERROR] This is an Error message
Aug 3, 2020 12:41:25.946575 -04 [DEBUG] This is a Debug message

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Level = getLevel{

	DEBUG:    "DEBUG",
	INFO:     "INFO",
	WARN:     "WARN",
	ERROR:    "ERROR",
	CRITICAL: "CRITICAL",
}
View Source
var TS = tsFormat{
	ANSIC:       "Mon Jan _2 15:04:05 2006",
	UnixDate:    "Mon Jan _2 15:04:05 MST 2006",
	RubyDate:    "Mon Jan 02 15:04:05 -0700 2006",
	RFC822:      "02 Jan 06 15:04 MST",
	RFC822Z:     "02 Jan 06 15:04 -0700",
	RFC850:      "Monday, 02-Jan-06 15:04:05 MST",
	RFC1123:     "Mon, 02 Jan 2006 15:04:05 MST",
	RFC1123Z:    "Mon, 02 Jan 2006 15:04:05 -0700",
	RFC3339:     "2006-01-02T15:04:05Z07:00",
	RFC3339Nano: "2006-01-02T15:04:05.999999999Z07:00",
	Kitchen:     "3:04PM",
	Special:     "Jan 2, 2006 15:04:05.000000 MST",
	Stamp:       "Jan _2 15:04:05",
	StampMilli:  "Jan _2 15:04:05.000",
	StampMicro:  "Jan _2 15:04:05.000000",
	StampNano:   "Jan _2 15:04:05.000000000",
}

Functions

func Test

func Test()

Types

type Log

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

func Start

func Start(logName string, logPath string, logLevel string) (Log, error)

func (Log) Close

func (_log Log) Close()

func (Log) Critical

func (_log Log) Critical(data string)

func (Log) Debug

func (_log Log) Debug(data string)

func (Log) Error

func (_log Log) Error(data string)

func (Log) Info

func (_log Log) Info(data string)

func (*Log) Rotation

func (_log *Log) Rotation(SizeMB float64, Backup int)

func (*Log) Statistics

func (_log *Log) Statistics(state bool)

func (Log) Status

func (_log Log) Status() bool

func (Log) TimestampFormat added in v1.3.0

func (_log Log) TimestampFormat(format string)

func (Log) Warn

func (_log Log) Warn(data string)

Source Files

Jump to

Keyboard shortcuts

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