adaptlog

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2016 License: Apache-2.0 Imports: 0 Imported by: 3

README

adaptlog alt text build status Coverage Status

Package adaptlog is a logging abstraction in go. The name of the package is a composition of adapt(adaptive) and log(logging).

The developer uses this abstraction to avoid depending on a specific logging implementation. The package provides an abstraction that covers the standard logging(like in the standard log package) and the leveled logging (like many of them out there).

The simplest way to use adaptlog's logger is by simply implementing a Logger interface like illustrated in the samples of the examples folder.

package main

import (
    "log"

    "github.com/mantzas/adaptlog"
)

// MyLogger custom logger implementing the Simple Logger interface
type MyLogger struct {
}

// Print logging
func (l *MyLogger) Print(args ...interface{}) {
    log.Print(args...)
}

// Printf logging
func (l *MyLogger) Printf(msg string, args ...interface{}) {
    log.Printf(msg, args...)
}

// Println logging
func (l *MyLogger) Println(args ...interface{}) {
    log.Println(args...)
}

// Panic logging
func (l *MyLogger) Panic(args ...interface{}) {
    log.Panic(args...)
}

// Panicf logging
func (l *MyLogger) Panicf(msg string, args ...interface{}) {
    log.Panicf(msg, args...)
}

// Panicln logging
func (l *MyLogger) Panicln(args ...interface{}) {
    log.Panicln(args...)
}

// Fatal logging
func (l *MyLogger) Fatal(args ...interface{}) {
    log.Panic(args...)
}

// Fatalf logging
func (l *MyLogger) Fatalf(msg string, args ...interface{}) {
    log.Panicf(msg, args...)
}

// Fatalln logging
func (l *MyLogger) Fatalln(args ...interface{}) {
    log.Panicln(args...)
}

func main() {

    // configure once
    adaptlog.ConfigureSimpleLogger(new(MyLogger))

    // use logger
    adaptlog.Simple.Print("Hello World!")
}

Documentation

Overview

Package adaptlog is a logging abstraction for go. The name of the package is a composition of adapt(adaptive) and log(logging).

The developer uses this abstraction in order to avoid depending on a specific logging implementation. The package provides two abstractions:

The simple logger based on the standard log package and the level logger based on many leveled logging packages out there.

The developer has only to setup one by implementing a interface.

The simplest way to use adaptlog's simple logger is by simply implementing the SimpleLogger interface like below.

package main

import (
    "log"

    "github.com/mantzas/adaptlog"
)

// MyLogger custom logger implementing the Simple Logger interface
type MyLogger struct {
}

// Print logging
func (l *MyLogger) Print(args ...interface{}) {
    log.Print(args...)
}

// Printf logging
func (l *MyLogger) Printf(msg string, args ...interface{}) {
    log.Printf(msg, args...)
}

// Println logging
func (l *MyLogger) Println(args ...interface{}) {
    log.Println(args...)
}

// Panic logging
func (l *MyLogger) Panic(args ...interface{}) {
    log.Panic(args...)
}

// Panicf logging
func (l *MyLogger) Panicf(msg string, args ...interface{}) {
    log.Panicf(msg, args...)
}

// Panicln logging
func (l *MyLogger) Panicln(args ...interface{}) {
    log.Panicln(args...)
}

// Fatal logging
func (l *MyLogger) Fatal(args ...interface{}) {
    log.Panic(args...)
}

// Fatalf logging
func (l *MyLogger) Fatalf(msg string, args ...interface{}) {
    log.Panicf(msg, args...)
}

// Fatalln logging
func (l *MyLogger) Fatalln(args ...interface{}) {
    log.Panicln(args...)
}

func main() {

    // configure once
    adaptlog.ConfigureSimpleLogger(new(MyLogger))

    // use logger
    adaptlog.Simple.Print("Hello World!")
}

For a full guide visit https://github.com/mantzas/adaptlog

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigureLevelLogger added in v0.4.0

func ConfigureLevelLogger(logger LevelLogger)

ConfigureLevelLogger configures the level logger

func ConfigureSimpleLogger added in v0.4.0

func ConfigureSimpleLogger(logger SimpleLogger)

ConfigureSimpleLogger configures the simple logger

Types

type DebugLogger added in v0.2.0

type DebugLogger interface {
	Debug(...interface{})
	Debugf(string, ...interface{})
	Debugln(...interface{})
}

DebugLogger interface. Introduces Debug logging facilities.

type ErrorLogger added in v0.2.0

type ErrorLogger interface {
	Error(...interface{})
	Errorf(string, ...interface{})
	Errorln(...interface{})
}

ErrorLogger interface. Introduces Error logging facilities.

type FatalLogger added in v0.2.0

type FatalLogger interface {
	Fatal(...interface{})
	Fatalf(string, ...interface{})
	Fatalln(...interface{})
}

FatalLogger interface. Introduce Fatal logging facilities

type InfoLogger added in v0.2.0

type InfoLogger interface {
	Info(...interface{})
	Infof(string, ...interface{})
	Infoln(...interface{})
}

InfoLogger interface. Introduces Info logging facilities.

type LevelLogger added in v0.2.0

type LevelLogger interface {
	FatalLogger
	ErrorLogger
	WarnLogger
	InfoLogger
	DebugLogger
}

LevelLogger is the level logger interface

var Level LevelLogger

Level Logger

type PanicLogger added in v0.2.0

type PanicLogger interface {
	Panic(...interface{})
	Panicf(string, ...interface{})
	Panicln(...interface{})
}

PanicLogger interface. Introduce Panic logging facilities

type PrintLogger added in v0.2.0

type PrintLogger interface {
	Print(...interface{})
	Printf(string, ...interface{})
	Println(...interface{})
}

PrintLogger interface. Introduces Print logging facilities.

type SimpleLogger added in v0.4.0

type SimpleLogger interface {
	PrintLogger
	FatalLogger
	PanicLogger
}

SimpleLogger the simple logger interface with Print, Panic, Fatal

var Simple SimpleLogger

Simple Logger

type WarnLogger added in v0.2.0

type WarnLogger interface {
	Warn(...interface{})
	Warnf(string, ...interface{})
	Warnln(...interface{})
}

WarnLogger interface. Introduces Warn logging facilities.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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