logger

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2022 License: Apache-2.0 Imports: 3 Imported by: 1

README

logger

Uber zap logger wrapper impl.

Installation

$ go get -u github.com/coolstina/logger

How to use?

It's very simple to use, just out of the box, and you can view the documentation through GoDoc.

Example

package main

import (
	"github.com/coolstina/logger"
	"go.uber.org/zap/zapcore"
)

func main() {
	logger.Configuration(
		logger.WithOutput("app.log"), 
		logger.WithTimeEncoder(zapcore.RFC3339NanoTimeEncoder),
	)

	logger.Infof("upgrade status: %v", true)
	logger.Infow("upgrade info", "status", true)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Configuration

func Configuration(ops ...Option)

func DPanicf

func DPanicf(template string, args ...interface{})

DPanicf uses fmt.Sprintf to log a templated message. In development, the logger then panics. (See DPanicLevel for details.)

func DPanicw

func DPanicw(msg string, keysAndValues ...interface{})

DPanicw logs a message with some additional context. In development, the logger then panics. (See DPanicLevel for details.) The variadic key-value pairs are treated as they are in With.

func Debugf

func Debugf(template string, args ...interface{})

Debugf uses fmt.Sprintf to log a templated message.

func Debugw

func Debugw(msg string, keysAndValues ...interface{})

Debugw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.

When debug-level logging is disabled, this is much faster than

s.With(keysAndValues).Debug(msg)

func Errorf

func Errorf(template string, args ...interface{})

Errorf uses fmt.Sprintf to log a templated message.

func Errorw

func Errorw(msg string, keysAndValues ...interface{})

Errorw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.

func Fatalf

func Fatalf(template string, args ...interface{})

Fatalf uses fmt.Sprintf to log a templated message, then calls os.Exit.

func Fatalw

func Fatalw(msg string, keysAndValues ...interface{})

Fatalw logs a message with some additional context, then calls os.Exit. The variadic key-value pairs are treated as they are in With.

func Infof

func Infof(template string, args ...interface{})

Infof uses fmt.Sprintf to log a templated message.

func Infow

func Infow(msg string, keysAndValues ...interface{})

Infow logs a message with some additional context. The variadic key-value pairs are treated as they are in With.

func NewLoggerOr

func NewLoggerOr(ops ...Option) *zap.Logger

NewLoggerOr Initialize zap li instance.

func Panicf

func Panicf(template string, args ...interface{})

Panicf uses fmt.Sprintf to log a templated message, then panics.

func Warnf

func Warnf(template string, args ...interface{})

Warnf uses fmt.Sprintf to log a templated message.

func Warnw

func Warnw(msg string, keysAndValues ...interface{})

Warnw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithEncoding added in v0.2.0

func WithEncoding(encoding string) Option

WithEncoding Specify logger format, the valid "json" and "console".

func WithOutput

func WithOutput(output ...string) Option

func WithTimeEncoder

func WithTimeEncoder(timeEncoder zapcore.TimeEncoder) Option

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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