applogger

package module
v0.0.0-...-25d5662 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2019 License: MIT Imports: 11 Imported by: 0

README

applogger

applogger wraps Go's log library. A logger implementation that is very simple to use.

Usage

Get Started

Download and install it:

go get github.com/codingmechanics/applogger

Import it in your code:

import "github.com/codingmechanics/applogger"
Basic Example
package main

import (
    "fmt"
    "errors"

    "github.com/codingmechanics/applogger"
)

func main() {
    // initiate the loogger
    log := applogger.Logger{}
    // start the logger. set the loglevel application wise
    // set to debug level
    log.Start(applogger.LevelDebug)
    // applicaiton code goes here
    Example()
    // stop the logger
    log.Stop()
}

//  dummy function
func Example() {
    log.Started("Example")

    log.Debug("Example", "Debug Log")
    log.Info("Example", "Info Log")
    log.Warning("Example", "Warn Log")
    log.Error("Example()", "Error Log", error.New("Dummy Error"))

    log.Completed("Example")
}

Output

DEBUG: 2019/10/31 20:26:10 main.go:24: Example() Started
INFO: 2019/10/31 20:26:10 main.go:26: Example() Info Log
WARNING: 2019/10/31 20:26:10 main.go:27: Example() Warn Log
ERROR: 2019/10/31 20:26:10 main.go:28: Example() Error Log: Dummy Error
DEBUG: 2019/10/31 20:26:10 main.go:30: Example()  Completed

Documentation

Index

Constants

View Source
const (
	// LevelDebug logs everything
	LevelDebug int32 = 1

	// LevelInfo logs Info, Warnings and Errors
	LevelInfo int32 = 2

	// LevelWarn logs Warning and Errors
	LevelWarn int32 = 4

	// LevelError logs just Errors
	LevelError int32 = 8
)

Variables

This section is empty.

Functions

func Info

func Info(format string, a ...interface{})

Info godoc

func LogLevel

func LogLevel() int32

LogLevel returns the configured logging level.

Types

type ApplicationLog

type ApplicationLog struct {
	LogLevel int32
	Debug    *log.Logger
	Info     *log.Logger
	Warning  *log.Logger
	Error    *log.Logger
	File     *log.Logger
	LogFile  *os.File
}

ApplicationLog provides support to write to log files.

type Logger

type Logger struct {
	// DisableColor default behavior is to log with no color
	DisableColor bool
	// DataTimeUTC default behavior is to log at local time
	DataTimeUTC bool
}

Logger it loads the config for logging

func (*Logger) Completed

func (l *Logger) Completed(functionName string)

Completed uses the Serialize destination and writes a Completed tag to the log line

func (*Logger) CompletedError

func (l *Logger) CompletedError(functionName string, err error)

CompletedError uses the Error destination and writes a Completed tag to the log line

func (*Logger) CompletedErrorf

func (l *Logger) CompletedErrorf(functionName string, err error, format string, a ...interface{})

CompletedErrorf uses the Error destination and writes a Completed tag to the log line

func (*Logger) Completedf

func (l *Logger) Completedf(functionName string, format string, a ...interface{})

Completedf uses the Serialize destination and writes a Completed tag to the log line

func (*Logger) Debug

func (l *Logger) Debug(format string, a ...interface{})

Debug writes to the Debug destination

func (*Logger) Error

func (l *Logger) Error(err string)

Error writes to the Error destination and accepts an err

func (*Logger) ErrorG

func (l *Logger) ErrorG(format string, a ...interface{})

ErrorG will be used for

func (*Logger) Errorf

func (l *Logger) Errorf(format string, err error, a ...interface{})

Errorf writes to the Error destination and accepts an err

func (*Logger) GinLogger

func (l *Logger) GinLogger() gin.HandlerFunc

GinLogger handler function to custom gin logger

func (*Logger) Info

func (l *Logger) Info(format string, a ...interface{})

Info writes to the Info destination

func (*Logger) LogDirectoryCleanup

func (l *Logger) LogDirectoryCleanup(baseFilePath string, daysToKeep int)

LogDirectoryCleanup performs all the directory cleanup and maintenance.

func (*Logger) Start

func (l *Logger) Start(logLevel int32)

Start initializes ApplicationLog and only displays the specified logging level.

func (*Logger) StartFile

func (l *Logger) StartFile(logLevel int32, baseFilePath string, daysToKeep int)

StartFile initializes tracelog and only displays the specified logging level and creates a file to capture writes.

func (*Logger) Started

func (l *Logger) Started(functionName string)

Started uses the Serialize destination and adds a Started tag to the log line

func (*Logger) Startedf

func (l *Logger) Startedf(functionName string, format string, a ...interface{})

Startedf uses the Serialize destination and writes a Started tag to the log line

func (*Logger) Stop

func (l *Logger) Stop() error

Stop will release resources and shutdown all processing.

func (*Logger) Warning

func (l *Logger) Warning(format string, a ...interface{})

Warning writes to the Warning destination

Jump to

Keyboard shortcuts

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