logger

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2020 License: BSD-3-Clause Imports: 8 Imported by: 28

README

go-logger

Coverage Status Release Go Report Card Build Status

How to use it

package main

import (
	"os"
	"time"

	"github.com/deweppro/go-logger"
)

func main() {
	file, err := os.OpenFile("/tmp/demo.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
	if err != nil {
		panic(err)
	}

	defer file.Close()

	async := logger.NewAsync()
	async.SetOutput(file)
	async.Infof("async %d", 1)
	async.Warnf("async %d", 2)
	async.Errorf("async %d", 3)
	async.Debugf("async %d", 4)

	sync := logger.NewSync()
	sync.SetOutput(file)
	sync.Infof("sync %d", 1)
	sync.Warnf("sync %d", 2)
	sync.Errorf("sync %d", 3)
	sync.Debugf("sync %d", 4)

	<-time.After(time.Second)
}

Example log output:

{"time":1602721013,"type":"INF","data":"sync 1"}
{"time":1602721013,"type":"WRN","data":"sync 2"}
{"time":1602721013,"type":"ERR","data":"sync 3"}
{"time":1602721013,"type":"DBG","data":"sync 4"}
...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debugf added in v1.1.0

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

func Default added in v1.1.0

func Default() *log

func Errorf added in v1.1.0

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

func Infof added in v1.1.0

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

func New added in v1.1.0

func New() *log

func SetOutput added in v1.1.0

func SetOutput(out io.Writer)

func Warnf added in v1.1.0

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

Types

type LogMessage

type LogMessage struct {
	Time int64  `json:"time"`
	Type string `json:"type"`
	Data string `json:"data"`
}

type Logger

type Logger interface {
	SetOutput(out io.Writer)
	Infof(format string, args ...interface{})
	Warnf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Debugf(format string, args ...interface{})
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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