jsonlog

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2021 License: MIT Imports: 6 Imported by: 1

README

jsonlog

Description

A structured json logger package

Godoc

Usage

package main

import "github.com/datewu/jsonlog"

func main() {
	logger := jsonlog.New(os.Stdout, jsonlog.LevelInfo)
	logger.PrintInfo("build info", map[string]string{
		"version":   "v0.0.1",
		"buildTime": "2021/06/30",
	})
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Level

type Level int8
const (
	LevelDebug Level = iota
	LevelInfo
	LevelError
	LevelFatal
	LevelOff
)

func (Level) String

func (l Level) String() string

String ...

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger holds the output destination that the log entries will be written to, the minimum severity level that log entries will be written for, and a mutex for concurrent writes.

func Default added in v0.0.3

func Default() *Logger

Default write to stdout with the minimum level set to LevelDebug.

func New

func New(out io.Writer, minLevel Level) *Logger

New create a new Logger

func (*Logger) Debug added in v0.0.3

func (l *Logger) Debug(msg string, props map[string]string)

Debug writes a log entry at LevelDebug to the output destination.

func (*Logger) Err added in v0.0.3

func (l *Logger) Err(err error, props map[string]string)

Err writes a log entry at LevelError to the output destination.

func (*Logger) Fatal added in v0.0.3

func (l *Logger) Fatal(err error, props map[string]string)

Fatal writes a log entry at LevelFatal to the output destination and exit 1.

func (*Logger) Info added in v0.0.3

func (l *Logger) Info(msg string, props map[string]string)

Info writes a log entry at LevelInfo to the output destination.

func (*Logger) Write

func (l *Logger) Write(msg []byte) (int, error)

Write satisfies the io.Writer interface by call writeRaw.

Jump to

Keyboard shortcuts

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