logificial

package module
v0.0.0-...-3f571dd Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2020 License: MIT Imports: 4 Imported by: 0

README

logificial

An opinionated wrapped logger around zap and logrus.
GoDoc

Usage

  1. Default Log is initialized with ZAP in development mode.
package main

import (

	"github.com/ankur-anand/logificial"
)

func main() {
	logificial.Log.Info("Hello World")
	logificial.Log.Debug("Hello Debug")
}
  1. Use NewLogger(config Config) error to override.
logificial.NewLogger(logificial.Config{
		LogLib:       logificial.ZAP,
		Level:        logificial.InfoLevel,
		EnableCaller: true,
		Development:  false,
	})
logificial.Log.Info("hello Production")

Playground- https://play.golang.org/p/6-k3x7XMdku

Contact

Ankur Anand @in_aanand

License

logificial source code is available under the MIT License.

Documentation

Overview

Package logificial is an opinionated wrapped logger around zap and logrus.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLogger

func NewLogger(config Config) error

NewLogger builds a new logger from config and overrides the default logger

Types

type Config

type Config struct {
	// LogLib the underlying library to use to construct the Log Printer
	LogLib LogLibrary `json:"log_lib"`
	// Level is Log level
	// default Info (Development default is debug)
	Level Level `json:"level"`
	// EnableCaller to show caller in Log message
	// default true
	EnableCaller bool `json:"enable_caller"`
	// Development represents Logging Mode
	// default is false
	Development bool `json:"development"`
	// OutputPath or file paths to write logging output to.
	// Default to "stdout" and also in Development mode,
	// it gets overridden to stdout.
	OutputPath string `json:"output_path"`
}

Config offers a declarative way to construct a Log Printer. Note that Config intentionally supports only the most common options that is supported by both logrus and zap.

type Level

type Level string

Level is a logging priority.

const (
	// DebugLevel has verbose message
	DebugLevel Level = "debug"
	// InfoLevel is default Log level
	InfoLevel Level = "info"
	// WarnLevel is for logging messages about possible issues
	WarnLevel Level = "warn"
	// ErrorLevel is for logging errors
	ErrorLevel Level = "error"
	// FatalLevel is for logging fatal messages.
	// The system shutdown after logging the message.
	FatalLevel Level = "fatal"
)

type LogLibrary

type LogLibrary string

LogLibrary Name

const (
	// ZAP library
	ZAP LogLibrary = "zap"
	// LOGRUS library
	LOGRUS LogLibrary = "logrus"
)

In built supported logger

type Printer

type Printer interface {
	Errorf(format string, args ...interface{})
	Fatalf(format string, args ...interface{})
	Fatal(args ...interface{})
	Infof(format string, args ...interface{})
	Info(args ...interface{})
	Warnf(format string, args ...interface{})
	Debugf(format string, args ...interface{})
	Debug(args ...interface{})
}

Printer represent common interface for the Log

var Log Printer

Log implements all union of function from zap and logrus, that can be used for logging purpose. Default value is initialized with ZAP logger in Development mode.

Jump to

Keyboard shortcuts

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