stdlog

package
v0.0.0-...-67c52db Latest Latest
Warning

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

Go to latest
Published: May 20, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Example (Stdlog)
package main

import (
	"os"

	"github.com/sraphs/go/log"
	"github.com/sraphs/go/log/logger"
	"github.com/sraphs/go/log/stdlog"
)

func main() {
	var logText = []interface{}{"hello", 22, "world"}
	log.Init(stdlog.New(os.Stdout, "", stdlog.Lshortfile).SetCallerDepth(log.CallerSkipFrameCount))
	log.SetLevel(logger.LevelInfo)

	log.Debug(logText...) // default level is info, so this line will not be printed
	log.Info(logText...)
	log.Warn(logText...)
	log.Error(logText...)
	// log.Fatal(logText)
	// log.Panic(logText)

}
Output:

INFO : stdlog_example_test.go:16: hello 22 world
WARN : stdlog_example_test.go:17: hello 22 world
ERROR: stdlog_example_test.go:18: hello 22 world

Index

Examples

Constants

View Source
const (
	Ldate         = stdlog.Ldate                       // the date in the local time zone: 2009/01/23
	Ltime         = stdlog.Ltime                       // the time in the local time zone: 01:23:23
	Lmicroseconds = stdlog.Lmicroseconds               // microsecond resolution: 01:23:23.123123.  assumes Ltime.
	Llongfile     = stdlog.Llongfile                   // full file name and line number: /a/b/c/d.go:23
	Lshortfile    = stdlog.Lshortfile                  // final file name element and line number: d.go:23. overrides Llongfile
	LUTC          = stdlog.LUTC                        // if Ldate or Ltime is set, use UTC rather than the local time zone
	Lmsgprefix    = stdlog.Lmsgprefix                  // move the "prefix" from the beginning of the line to before the message
	LstdFlags     = stdlog.LstdFlags                   // initial values for the standard logger
	LDefaultFlags = Ldate | Lmicroseconds | Lshortfile // default value for the standard logger
)

These flags define which text to prefix to each log entry generated by the Logger. Bits are or'ed together to control what's printed. With the exception of the Lmsgprefix flag, there is no control over the order they appear (the order listed here) or the format they present (as described in the comments). The prefix is followed by a colon only when Llongfile or Lshortfile is specified. For example, flags Ldate | Ltime (or LstdFlags) produce,

2009/01/23 01:23:23 message

while flags Ldate | Ltime | Lmicroseconds | Llongfile produce,

2009/01/23 01:23:23.123123 /a/b/c/d.go:23: message

Variables

This section is empty.

Functions

func New

func New(out io.Writer, prefix string, flag int) *stdLogger

New creates a new std Logger.

Types

This section is empty.

Jump to

Keyboard shortcuts

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