log

package
v0.0.0-...-e419a8d Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package log provides a application log that formalize a log format.

logger, err := log.New()
if err != nil {
	panic(err)
}
defer logger.Close()

logger.Info("This is my log", log.String("Key", "String value"))
Example (Basic)
package main

import (
	"github.com/anthonycorbacho/foundation/log"
)

func main() {
	logger, err := log.New()
	if err != nil {
		panic(err)
	}
	defer logger.Close()

	logger.Info("This is my log", log.String("Key", "String value"))
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field = zap.Field

Field is a marshaling operation used to add a key-value pair to a logger's context.

func Any

func Any(key string, val interface{}) Field

Any field.

func Bool

func Bool(key string, val bool) Field

Bool constructs a field with the given key and value.

func ByteString

func ByteString(key string, val []byte) Field

ByteString constructs a field with the given key and value.

func Duration

func Duration(key string, val time.Duration) Field

Duration field.

func Error

func Error(err error) Field

Error constructs a field with the given key and value.

func Float32

func Float32(key string, val float32) Field

Float32 constructs a field with the given key and value.

func Float64

func Float64(key string, val float64) Field

Float64 constructs a field with the given key and value.

func Int

func Int(key string, val int) Field

Int constructs a field with the given key and value.

func Int32

func Int32(key string, val int32) Field

Int32 constructs a field with the given key and value.

func Int64

func Int64(key string, val int64) Field

Int64 constructs a field with the given key and value.

func String

func String(key string, val string) Field

String constructs a field with the given key and value.

func Stringer

func Stringer(key string, val fmt.Stringer) Field

Stringer constructs a field with the given key and value.

func Time

func Time(key string, val time.Time) Field

Time field.

type Logger

type Logger interface {
	// Debug logs a message at DebugLevel.
	Debug(msg string, fields ...Field)
	// Info logs a message at InfoLevel.
	Info(msg string, fields ...Field)
	// Warn logs a message at WarnLevel.
	Warn(msg string, fields ...Field)
	// Error logs a message at ErrorLevel.
	Error(msg string, fields ...Field)
	// Fatal logs a message at FatalLevel.
	Fatal(msg string, fields ...Field)
	// Panic logs a message at PanicLevel.
	Panic(msg string, fields ...Field)
	// Close closes the logger.
	Close()
}

Logger defines a leveled logging structure.

type ZapLogger

type ZapLogger struct {
	*zap.Logger
}

ZapLogger is a structure that provide a fast, leveled, structured logging using Uber zap. All methods are safe for concurrent use.

func New

func New() (*ZapLogger, error)

New creates a new logger.

func NewNop

func NewNop() *ZapLogger

NewNop returns a no-op Logger. It never writes out logs or internal errors.

func (*ZapLogger) Close

func (l *ZapLogger) Close()

Close closes the logger.

Jump to

Keyboard shortcuts

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