stdlog

package module
v0.0.0-...-2204cf8 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2023 License: MIT Imports: 11 Imported by: 4

README

NO LONGER MAINTAINED

Documentation

Overview

Package stdlog provide log utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OnelineLog

func OnelineLog() bool

OnelineLog is derived from "OnelineLog" env variable according to strconv.ParseBool

func PrintErr

func PrintErr(v ...interface{})

PrintErr is shortcut to Err().Print

func PrintOut

func PrintOut(v ...interface{})

PrintOut is shortcut to Out().Print

func SetErr

func SetErr(l *Logger) error

SetErr set logger returned by Err

func SetOut

func SetOut(l *Logger) error

SetOut set logger returned by Out

func TimestampLog

func TimestampLog() bool

TimestampLog is derived from "TimestampLog" env variable according to strconv.ParseBool

Types

type Logger

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

Logger represent logging object.

func Err

func Err() *Logger

Err return global err Logger

if SetErr never called before, will return Logger that wrap os.Stderr and behave acording to OnelineLog and NoTimestampLog

func New

func New(w io.Writer, prefix string, timestamp bool, onelines bool) *Logger

New create new logger that write to b,

if timestamp is true, every Print will prefixed with timestamp.

if onelines is true, every Write will formated into JSON string, this option is ignored when w is *Logger

func NewFromEnv

func NewFromEnv(w io.Writer, prefix string) *Logger

NewFromEnv is same as New but timestamp and onelines are inherited from env

func Out

func Out() *Logger

Out return global out Logger

if SetOut never called before, will return Logger that wrap os.Stdout and behave acording to OnelineLog and NoTimestampLog

func (*Logger) AsLogger

func (l *Logger) AsLogger() *log.Logger

AsLogger return log.Logger instance with l as inner

func (*Logger) Print

func (l *Logger) Print(v ...interface{})

Print from Printer interface

Print the arguments. Arguments are handled in the manner of fmt.Print.

Print is safe called from multiple goroutine, it guarantees to serialize access to the Writer.

func (*Logger) Write

func (l *Logger) Write(p []byte) (n int, err error)

Write from io.Writer interface

Write is safe called from multiple goroutine, it guarantees to serialize access to the Writer.

type Printer

type Printer interface {
	Print(...interface{})
}

Printer is interface for printing log

Jump to

Keyboard shortcuts

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