log

package
v0.0.0-...-6b32d26 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2021 License: Apache-2.0 Imports: 8 Imported by: 92

Documentation

Overview

Copyright 2021 SANGFOR TECHNOLOGIES

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

	http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Package log implements a simple logging package. It defines a type, RLog, with methods for formatting output. It also has a predefined 'standard' RLog accessible through helper functions Print[f|ln], Fatal[f|ln], and Panic[f|ln], which are easier to use than creating a RLog manually. That logger writes to standard error and prints the date and time of each logged message. Every log message is output on a separate line: if the message being printed does not end in a newline, the logger will add one. The Fatal functions call os.Exit(1) after writing the log message. The Panic functions call panic after writing the log message.

Index

Constants

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

These flags define which text to prefix to each log entry generated by the RLog. 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 Critical

func Critical(message string, args ...interface{}) error

func Criticale

func Criticale(err error) error

func Criticalf

func Criticalf(message string, args ...interface{}) error

func Debug

func Debug(message string, args ...interface{}) string

func Debugf

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

func DisableOutput

func DisableOutput(disable bool)

DisableOutput disable log output or not

func EnableSyslogWriter

func EnableSyslogWriter(tag string) (err error)

EnableSyslogWriter enables, if possible, writes to syslog. These will execute _in addition_ to normal logging

func Error

func Error(message string, args ...interface{})

func Errore

func Errore(err error) error

func Erroref

func Erroref(err error)

func Errorf

func Errorf(message string, args ...interface{}) error

func Fatal

func Fatal(message string, args ...interface{})

Fatal emits a FATAL level entry and exists the program

func Fatale

func Fatale(err error) error

Fatale emits a FATAL level entry and exists the program

func Fatalf

func Fatalf(message string, args ...interface{}) error

Fatalf emits a FATAL level entry and exists the program

func Info

func Info(message string, args ...interface{})

func Infof

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

func Notice

func Notice(message string, args ...interface{}) string

func Noticef

func Noticef(message string, args ...interface{}) string

func SetFatalFunc

func SetFatalFunc(fatalF func())

SetFatalFunc set fatal function, when get fatal log, will exec this function

func SetLevel

func SetLevel(logLevel LogLevel)

SetLevel sets the global log level. Only entries with level equals or higher than this value will be logged

func SetPrintStackTrace

func SetPrintStackTrace(shouldPrintStackTrace bool)

SetPrintStackTrace enables/disables dumping the stack upon error logging

func SetSyslogLevel

func SetSyslogLevel(logLevel LogLevel)

SetSyslogLevel sets the minimal syslog level. Only entries with level equals or higher than this value will be logged. However, this is also capped by the global log level. That is, messages with lower level than global-log-level will be discarded at any case.

func Warning

func Warning(message string, args ...interface{})

func Warningf

func Warningf(message string, args ...interface{}) error

Types

type LogLevel

type LogLevel int

LogLevel indicate the severity of a log entry

const (
	FATAL LogLevel = iota
	CRITICAL
	ERROR
	WARNING
	NOTICE
	INFO
	DEBUG
)

func (LogLevel) String

func (ll LogLevel) String() string

type RLog

type RLog struct {
}

A RLog represents an active logging object that generates lines of output to an io.Writer. Each logging operation makes a single call to the Writer's Write method. A RLog can be used simultaneously from multiple goroutines; it guarantees to serialize access to the Writer.

func (*RLog) Write

func (r *RLog) Write(d []byte) (int, error)

Write is used to append to the log.

Jump to

Keyboard shortcuts

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