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
- func Critical(message string, args ...interface{}) error
- func Criticale(err error) error
- func Criticalf(message string, args ...interface{}) error
- func Debug(message string, args ...interface{}) string
- func Debugf(message string, args ...interface{}) string
- func DisableOutput(disable bool)
- func EnableSyslogWriter(tag string) (err error)
- func Error(message string, args ...interface{})
- func Errore(err error) error
- func Erroref(err error)
- func Errorf(message string, args ...interface{}) error
- func Fatal(message string, args ...interface{})
- func Fatale(err error) error
- func Fatalf(message string, args ...interface{}) error
- func Info(message string, args ...interface{})
- func Infof(message string, args ...interface{}) string
- func Notice(message string, args ...interface{}) string
- func Noticef(message string, args ...interface{}) string
- func SetFatalFunc(fatalF func())
- func SetLevel(logLevel LogLevel)
- func SetPrintStackTrace(shouldPrintStackTrace bool)
- func SetSyslogLevel(logLevel LogLevel)
- func Warning(message string, args ...interface{})
- func Warningf(message string, args ...interface{}) error
- type LogLevel
- type RLog
Constants ¶
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 EnableSyslogWriter ¶
EnableSyslogWriter enables, if possible, writes to syslog. These will execute _in addition_ to normal logging
func Fatal ¶
func Fatal(message string, args ...interface{})
Fatal emits a FATAL level entry and exists the program
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.
Types ¶
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.