goLogger

package module
v1.0.0 Latest Latest
Warning

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

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

README

go-logger

Coverage Status Release Go Report Card Build Status

How to use it

package main

import (
	"os"
	"time"

	goLogger "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 := goLogger.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 := goLogger.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

This section is empty.

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{})
}

func NewAsync

func NewAsync() Logger

func NewSync

func NewSync() Logger

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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