logger

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2018 License: MIT Imports: 7 Imported by: 0

README

Logger: custom logger package for Go.

Logger package help you easier write log to io.Writer. All methods fully support standard log package, but have extra features.

Install

For install logger, just run go get -u github.com/neliseev/logger or glide get github.com/neliseev/logger

Usage

Simple in main file you should initialise logger.

package main

import "github.com/neliseev/logger"

var log *logger.Log // Using log subsystem

func init() {
	// Initialization log system
	var err error

	if log, err = logger.NewFileLogger("/var/log/example/main.log", 8); err != nil {
		panic(err)
	}
}

func main() {
    log.Info("Starting main packge")
...
}

Logger automatically create all subfolder by defined path.

For re-use current initialised logger, just define var log *logger.Log, example:

package example

import "github.com/neliseev/logger"

var log *logger.Log // Using log subsystem

func Some() {
    log.Debug("Hello, Wold!")
}
License

Copyright (C) 2017 Nikita Eliseev

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DebugPtr *log.Logger
View Source
var TracePtr *log.Logger

Functions

This section is empty.

Types

type Log

type Log struct{}

func NewFileLogger

func NewFileLogger(logFile string, logLevel int) (*Log, error)

NewFileLogger func - creating new file logger.

Fields:

LogFile  - path to log file
LogLevel - log level, possible levels:
  0 - Emergency, with panic exit.
  1 - Alert, with exit 2.
  2 - Critical, with ext 1.
  3 - Errors.
  4 - Warnings.
  5 - Notice.
  6 - Info.
  7 - Debug.
  8 - Trace.

Example, for reusing current pointer to this logger, just define in package var log *logger.Log: var log *logger.Log // Using log subsystem

func init() {
  // Initialization log system
  var err error

  if log, err = logger.NewFileLogger(environment.GetLogFile(), environment.GetLogLevel()); err != nil {
    panic(err)
  }
}

func (*Log) Alert

func (*Log) Alert(a ...interface{})

Alert logging a message using Alert (1) as log level and call os.Exit(1).

func (*Log) AlertOnErr added in v1.0.2

func (l *Log) AlertOnErr(fn func() error, a ...interface{})

func (*Log) Alertf

func (*Log) Alertf(format string, a ...interface{})

Alertf logging a message using Alert (1) as log level and call os.Exit(1).

func (*Log) AlertfOnErr added in v1.0.2

func (l *Log) AlertfOnErr(fn func() error, format string, a ...interface{})

func (*Log) Crit

func (*Log) Crit(a ...interface{})

Crit logging a message using Crit (2) as log level and call os.Exit(1).

func (*Log) CritOnErr added in v1.0.2

func (l *Log) CritOnErr(fn func() error, a ...interface{})

func (*Log) Critf

func (*Log) Critf(format string, a ...interface{})

Critf logging a message using Crit (2) as log level and call os.Exit(1).

func (*Log) CritfOnErr added in v1.0.2

func (l *Log) CritfOnErr(fn func() error, format string, a ...interface{})

func (*Log) Debug

func (l *Log) Debug(a ...interface{})

Debug logging a message using DEBUG as log level.

func (*Log) Debugf

func (l *Log) Debugf(format string, a ...interface{})

Debugf logging a message using DEBUG as log level.

func (*Log) Emerg

func (*Log) Emerg(a ...interface{})

Emerg logging a message using Emerg (0) as log level and call panic(fmt string).

func (*Log) EmergOnErr added in v1.0.2

func (l *Log) EmergOnErr(fn func() error, a ...interface{})

func (*Log) Emergf

func (*Log) Emergf(format string, a ...interface{})

Emergf logging a message using Emerg (0) as log level and call panic(fmt string).

func (*Log) EmergfOnErr added in v1.0.2

func (l *Log) EmergfOnErr(fn func() error, format string, a ...interface{})

func (*Log) Err

func (*Log) Err(a ...interface{})

Err logging a message using Error (3) as log level.

func (*Log) ErrOnErr added in v1.0.2

func (l *Log) ErrOnErr(fn func() error, a ...interface{})

func (*Log) Errf

func (*Log) Errf(format string, a ...interface{})

Errf logging a message using Error (3) as log level.

func (*Log) ErrfOnErr added in v1.0.2

func (l *Log) ErrfOnErr(fn func() error, format string, a ...interface{})

func (*Log) Info

func (*Log) Info(a ...interface{})

Info logging a message using Info (6) as log level.

func (*Log) Infof

func (*Log) Infof(format string, a ...interface{})

Infof logging a message using Info (6) as log level.

func (*Log) Notice

func (*Log) Notice(a ...interface{})

Notice logging a message using Notice (5) as log level.

func (*Log) Noticef

func (*Log) Noticef(format string, a ...interface{})

Noticef logging a message using Notice (5) as log level.

func (*Log) Trace

func (l *Log) Trace(msg string) func()

Trace logging a performance each function, usage defer trace("Message")()

func (*Log) Warn

func (*Log) Warn(a ...interface{})

Warn logging a message using Warn (4) as log level.

func (*Log) WarnOnErr added in v1.0.2

func (l *Log) WarnOnErr(fn func() error, a ...interface{})

func (*Log) Warnf

func (*Log) Warnf(format string, a ...interface{})

Warnf logging a message using Warn (4) as log level.

func (*Log) WarnfOnErr added in v1.0.2

func (l *Log) WarnfOnErr(fn func() error, format string, a ...interface{})

Jump to

Keyboard shortcuts

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