Documentation
¶
Overview ¶
Package log implements structured logging for Google App Engine, Cloud Run and Cloud Functions. The API is compatible with the standard library "log" module.
All the severities conform to the Google Cloud Logging API v2 as described in https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#logseverity. These severity levels are: DEBUG, INFO, NOTICE, WARNING, ERROR, CRITICAL, ALERT, EMERGENCY.
The ERROR, CRITICAL, ALERT, EMERGENCY logs are written to the standard error stream, while the remaining logs are written to the standard output.
Example ¶
Example shows typical severity recommendations.
package main import "github.com/apsystole/log" // Example shows typical severity recommendations. func main() { log.Debug("the lowest level") log.Print("phase 2 processing ended") // or log.Info() log.Notice("shutting down normally...") log.Warning("difficulties, retrying shutdown...") } // Errors are used sparingly to draw attention of a human, sooner or later. // nolint: unused func Errors() { log.Error("a minor problem that a real human should act on") log.Critical("a major problem") log.Fatal("a major problem - aborting") log.Panic("a major problem - dumping stacktraces and aborting") log.Alert("waky waky dear on-duty person, eggs and baky") log.Emergency("core functionality is down and needs a human to rescue it") }
Index ¶
- Variables
- func Alert(v ...interface{})
- func Alertf(format string, v ...interface{})
- func Alertj(msg string, v interface{})
- func Alertln(v ...interface{})
- func Critical(v ...interface{})
- func Criticalf(format string, v ...interface{})
- func Criticalj(msg string, v interface{})
- func Criticalln(v ...interface{})
- func Debug(v ...interface{})
- func Debugf(format string, v ...interface{})
- func Debugj(msg string, v interface{})
- func Debugln(v ...interface{})
- func Emergency(v ...interface{})
- func Emergencyf(format string, v ...interface{})
- func Emergencyj(msg string, v interface{})
- func Emergencyln(v ...interface{})
- func Error(v ...interface{})
- func Errorf(format string, v ...interface{})
- func Errorj(msg string, v interface{})
- func Errorln(v ...interface{})
- func Fatal(v ...interface{})
- func Fatalf(format string, v ...interface{})
- func Fatalj(msg string, v interface{})
- func Fatalln(v ...interface{})
- func Info(v ...interface{})
- func Infof(format string, v ...interface{})
- func Infoj(msg string, v interface{})
- func Infoln(v ...interface{})
- func Notice(v ...interface{})
- func Noticef(format string, v ...interface{})
- func Noticej(msg string, v interface{})
- func Noticeln(v ...interface{})
- func Panic(v ...interface{})
- func Panicf(format string, v ...interface{})
- func Panicj(msg string, v interface{})
- func Panicln(v ...interface{})
- func Print(v ...interface{})
- func Printf(format string, v ...interface{})
- func Printj(msg string, v interface{})
- func Println(v ...interface{})
- func Warning(v ...interface{})
- func Warningf(format string, v ...interface{})
- func Warningj(msg string, v interface{})
- func Warningln(v ...interface{})
- type Logger
- func (l *Logger) Alert(v ...interface{})
- func (l *Logger) Alertf(format string, v ...interface{})
- func (l *Logger) Alertj(msg string, v interface{})
- func (l *Logger) Alertln(v ...interface{})
- func (l *Logger) Critical(v ...interface{})
- func (l *Logger) Criticalf(format string, v ...interface{})
- func (l *Logger) Criticalj(msg string, v interface{})
- func (l *Logger) Criticalln(v ...interface{})
- func (l *Logger) Debug(v ...interface{})
- func (l *Logger) Debugf(format string, v ...interface{})
- func (l *Logger) Debugj(msg string, v interface{})
- func (l *Logger) Debugln(v ...interface{})
- func (l *Logger) Emergency(v ...interface{})
- func (l *Logger) Emergencyf(format string, v ...interface{})
- func (l *Logger) Emergencyj(msg string, v interface{})
- func (l *Logger) Emergencyln(v ...interface{})
- func (l *Logger) Error(v ...interface{})
- func (l *Logger) Errorf(format string, v ...interface{})
- func (l *Logger) Errorj(msg string, v interface{})
- func (l *Logger) Errorln(v ...interface{})
- func (l *Logger) Fatal(v ...interface{})
- func (l *Logger) Fatalf(format string, v ...interface{})
- func (l *Logger) Fatalj(msg string, v interface{})
- func (l *Logger) Fatalln(v ...interface{})
- func (l *Logger) Info(v ...interface{})
- func (l *Logger) Infof(format string, v ...interface{})
- func (l *Logger) Infoj(msg string, v interface{})
- func (l *Logger) Infoln(v ...interface{})
- func (l *Logger) Notice(v ...interface{})
- func (l *Logger) Noticef(format string, v ...interface{})
- func (l *Logger) Noticej(msg string, v interface{})
- func (l *Logger) Noticeln(v ...interface{})
- func (l *Logger) Panic(v ...interface{})
- func (l *Logger) Panicf(format string, v ...interface{})
- func (l *Logger) Panicj(msg string, v interface{})
- func (l *Logger) Panicln(v ...interface{})
- func (l *Logger) Print(v ...interface{})
- func (l *Logger) Printf(format string, v ...interface{})
- func (l *Logger) Printj(msg string, v interface{})
- func (l *Logger) Println(v ...interface{})
- func (l *Logger) Warning(v ...interface{})
- func (l *Logger) Warningf(format string, v ...interface{})
- func (l *Logger) Warningj(msg string, v interface{})
- func (l *Logger) Warningln(v ...interface{})
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ProjectID = os.Getenv("GOOGLE_CLOUD_PROJECT")
ProjectID should be set to the Google Cloud project ID to properly correlate the message traces to HTTP requests, if you use ForRequest. The initial value is taken from the environment variable GOOGLE_CLOUD_PROJECT.
Functions ¶
func Alert ¶
func Alert(v ...interface{})
Alert logs when a person must take an action immediately. Arguments are handled in the manner of fmt.Print.
func Alertf ¶
func Alertf(format string, v ...interface{})
Alertf logs when a person must take an action immediately. Arguments are handled in the manner of fmt.Printf.
func Alertj ¶
func Alertj(msg string, v interface{})
Alertj logs when a person must take an action immediately. Argument v becomes the jsonPayload field of the log entry.
func Alertln ¶
func Alertln(v ...interface{})
Alertln logs when a person must take an action immediately. Arguments are handled in the manner of fmt.Println.
func Critical ¶
func Critical(v ...interface{})
Critical logs events that cause more severe problems or outages. Arguments are handled in the manner of fmt.Print.
func Criticalf ¶
func Criticalf(format string, v ...interface{})
Criticalf logs events that cause more severe problems or outages. Arguments are handled in the manner of fmt.Printf.
func Criticalj ¶
func Criticalj(msg string, v interface{})
Criticalj logs events that cause more severe problems or outages. Argument v becomes the jsonPayload field of the log entry.
func Criticalln ¶
func Criticalln(v ...interface{})
Criticalln logs events that cause more severe problems or outages. Arguments are handled in the manner of fmt.Println.
func Debug ¶
func Debug(v ...interface{})
Debug logs detailed information that could mainly be used to catch unforeseen problems. Arguments are handled in the manner of fmt.Print.
func Debugf ¶
func Debugf(format string, v ...interface{})
Debugf logs detailed information that could mainly be used to catch unforeseen problems. Arguments are handled in the manner of fmt.Printf.
func Debugj ¶
func Debugj(msg string, v interface{})
Debugj logs detailed information that could mainly be used to catch unforeseen problems. Argument v becomes jsonPayload field in the log entry.
func Debugln ¶
func Debugln(v ...interface{})
Debugln logs detailed information that could mainly be used to catch unforeseen problems. Arguments are handled in the manner of fmt.Println.
func Emergency ¶
func Emergency(v ...interface{})
Emergency logs when one or more systems are unusable. Arguments are handled in the manner of fmt.Print.
func Emergencyf ¶
func Emergencyf(format string, v ...interface{})
Emergencyf logs when one or more systems are unusable. Arguments are handled in the manner of fmt.Printf.
func Emergencyj ¶
func Emergencyj(msg string, v interface{})
Emergencyj logs when one or more systems are unusable. Argument v becomes the jsonPayload field of the log entry.
func Emergencyln ¶
func Emergencyln(v ...interface{})
Emergencyln logs when one or more systems are unusable. Arguments are handled in the manner of fmt.Println.
func Error ¶
func Error(v ...interface{})
Error logs events likely to cause problems. Arguments are handled in the manner of fmt.Print.
func Errorf ¶
func Errorf(format string, v ...interface{})
Errorf logs events likely to cause problems. Arguments are handled in the manner of fmt.Printf.
func Errorj ¶
func Errorj(msg string, v interface{})
Errorj logs events likely to cause problems. Argument v becomes the jsonPayload field of the log entry.
func Errorln ¶
func Errorln(v ...interface{})
Errorln logs events likely to cause problems. Arguments are handled in the manner of fmt.Println.
func Fatal ¶
func Fatal(v ...interface{})
Fatal is equivalent to a call to Critical() followed by a call to os.Exit(1).
func Fatalf ¶
func Fatalf(format string, v ...interface{})
Fatalf is equivalent to a call to Criticalf() followed by a call to os.Exit(1).
func Fatalj ¶
func Fatalj(msg string, v interface{})
Fatalj is equivalent to a call to Criticalj() followed by a call to os.Exit(1).
func Fatalln ¶
func Fatalln(v ...interface{})
Fatalln is equivalent to a call to Criticalln() followed by a call to os.Exit(1).
func Info ¶
func Info(v ...interface{})
Info logs routine information, such as ongoing status or performance. Arguments are handled in the manner of fmt.Print.
func Infof ¶
func Infof(format string, v ...interface{})
Infof logs routine information, such as ongoing status or performance. Arguments are handled in the manner of fmt.Printf.
func Infoj ¶
func Infoj(msg string, v interface{})
Infoj logs routine information, such as ongoing status or performance. Argument v becomes the jsonPayload field of the log entry.
func Infoln ¶
func Infoln(v ...interface{})
Infoln logs routine information, such as ongoing status or performance. Arguments are handled in the manner of fmt.Println.
func Notice ¶
func Notice(v ...interface{})
Notice logs normal but significant events, such as start up, shut down, or configuration. Arguments are handled in the manner of fmt.Print.
Example ¶
package main import ( "github.com/apsystole/log" ) func main() { log.Notice("hello", 1, "!") log.Noticeln("hello", 2, "!") }
Output: {"message":"hello1!","severity":"NOTICE"} {"message":"hello 2 !\n","severity":"NOTICE"}
func Noticef ¶
func Noticef(format string, v ...interface{})
Noticef logs normal but significant events, such as start up, shut down, or configuration. Arguments are handled in the manner of fmt.Printf.
Example ¶
package main import ( "io" "github.com/apsystole/log" ) func main() { err := io.EOF name := "my blog.txt" log.Noticef("while reading file %q ignoring: %v", name, err) }
Output: {"message":"while reading file \"my blog.txt\" ignoring: EOF","severity":"NOTICE"}
func Noticej ¶
func Noticej(msg string, v interface{})
Noticej logs normal but significant events, such as start up, shut down, or configuration. Argument v becomes the jsonPayload field of the log entry.
Example ¶
package main import ( "github.com/apsystole/log" ) func main() { obj := struct { Seq int Component string }{ Seq: 42, Component: "app", } log.Noticej("warning", obj) }
Output: {"message":"warning","severity":"NOTICE","Seq":42,"Component":"app"}
func Noticeln ¶
func Noticeln(v ...interface{})
Noticeln logs normal but significant events, such as start up, shut down, or configuration. Arguments are handled in the manner of fmt.Println.
Example ¶
package main import ( "github.com/apsystole/log" ) func main() { log.Notice("hello", 1, "!") log.Noticeln("hello", 2, "!") }
Output: {"message":"hello1!","severity":"NOTICE"} {"message":"hello 2 !\n","severity":"NOTICE"}
func Panic ¶
func Panic(v ...interface{})
Panic is equivalent to a call to Critical() followed by a call to panic().
func Panicf ¶
func Panicf(format string, v ...interface{})
Panicf is equivalent to a call to Criticalf() followed by a call to panic().
func Panicj ¶
func Panicj(msg string, v interface{})
Panicj is equivalent to a call to Criticalj() followed by a call to panic().
func Panicln ¶
func Panicln(v ...interface{})
Panicln is equivalent to a call to Criticalln() followed by a call to panic().
func Print ¶
func Print(v ...interface{})
Print logs routine information, such as ongoing status or performance, same as Info(). Arguments are handled in the manner of fmt.Print.
func Printf ¶
func Printf(format string, v ...interface{})
Printf logs routine information, such as ongoing status or performance, same as Infof(). Arguments are handled in the manner of fmt.Printf.
func Printj ¶
func Printj(msg string, v interface{})
Printj logs routine information, such as ongoing status or performance, same as Infoj(). Argument v becomes the jsonPayload field of the log entry.
func Println ¶
func Println(v ...interface{})
Println logs routine information, such as ongoing status or performance, same as Infoln(). Arguments are handled in the manner of fmt.Println.
func Warning ¶
func Warning(v ...interface{})
Warning logs events that might cause problems. Arguments are handled in the manner of fmt.Print.
func Warningf ¶
func Warningf(format string, v ...interface{})
Warningf logs events that might cause problems. Arguments are handled in the manner of fmt.Printf.
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
func ForRequest ¶
ForRequest creates a new Logger. All the messages logged through it will trace back to the HTTP request, based on its header "X-Cloud-Trace-Context" combined with the package var ProjectID.
Setting package var ProjectID to empty disables such tracing altogether.
func New ¶ added in v0.1.1
New is for interface-level compatibility with standard library's "log" package. It creates a new Logger, which streams all its messages to w. Remaining arguments are ignored.
The ForRequest() constructor is more useful.
func (*Logger) Alert ¶
func (l *Logger) Alert(v ...interface{})
Alert logs when a person must take an action immediately. Arguments are handled in the manner of fmt.Print.
func (*Logger) Alertf ¶
Alertf logs when a person must take an action immediately. Arguments are handled in the manner of fmt.Printf.
func (*Logger) Alertj ¶
Alertj logs when a person must take an action immediately. Argument v becomes the jsonPayload field of the log entry.
func (*Logger) Alertln ¶
func (l *Logger) Alertln(v ...interface{})
Alertln logs when a person must take an action immediately. Arguments are handled in the manner of fmt.Println.
func (*Logger) Critical ¶
func (l *Logger) Critical(v ...interface{})
Critical logs events that cause more severe problems or outages. Arguments are handled in the manner of fmt.Print.
func (*Logger) Criticalf ¶
Criticalf logs events that cause more severe problems or outages. Arguments are handled in the manner of fmt.Printf.
func (*Logger) Criticalj ¶
Criticalj logs events that cause more severe problems or outages. Argument v becomes the jsonPayload field of the log entry.
func (*Logger) Criticalln ¶
func (l *Logger) Criticalln(v ...interface{})
Criticalln logs events that cause more severe problems or outages. Arguments are handled in the manner of fmt.Println.
func (*Logger) Debug ¶
func (l *Logger) Debug(v ...interface{})
Debug logs detailed information that could mainly be used to catch unforeseen problems. Arguments are handled in the manner of fmt.Print.
func (*Logger) Debugf ¶
Debugf logs detailed information that could mainly be used to catch unforeseen problems. Arguments are handled in the manner of fmt.Printf.
func (*Logger) Debugj ¶
Debugj logs detailed information that could mainly be used to catch unforeseen problems. Argument v becomes jsonPayload field in the log entry.
func (*Logger) Debugln ¶
func (l *Logger) Debugln(v ...interface{})
Debugln logs detailed information that could mainly be used to catch unforeseen problems. Arguments are handled in the manner of fmt.Println.
func (*Logger) Emergency ¶
func (l *Logger) Emergency(v ...interface{})
Emergency logs when one or more systems are unusable. Arguments are handled in the manner of fmt.Print.
func (*Logger) Emergencyf ¶
Emergencyf logs when one or more systems are unusable. Arguments are handled in the manner of fmt.Printf.
func (*Logger) Emergencyj ¶
Emergencyj logs when one or more systems are unusable. Argument v becomes the jsonPayload field of the log entry.
func (*Logger) Emergencyln ¶
func (l *Logger) Emergencyln(v ...interface{})
Emergencyln logs when one or more systems are unusable. Arguments are handled in the manner of fmt.Println.
func (*Logger) Error ¶
func (l *Logger) Error(v ...interface{})
Error logs events likely to cause problems. Arguments are handled in the manner of fmt.Print.
func (*Logger) Errorf ¶
Errorf logs events likely to cause problems. Arguments are handled in the manner of fmt.Printf.
func (*Logger) Errorj ¶
Errorj logs events likely to cause problems. Argument v becomes the jsonPayload field of the log entry.
func (*Logger) Errorln ¶
func (l *Logger) Errorln(v ...interface{})
Errorln logs events likely to cause problems. Arguments are handled in the manner of fmt.Println.
func (*Logger) Fatal ¶
func (l *Logger) Fatal(v ...interface{})
Fatal is equivalent to a call to l.Critical() followed by a call to os.Exit(1).
func (*Logger) Fatalf ¶
Fatalf is equivalent to a call to l.Criticalf() followed by a call to os.Exit(1).
func (*Logger) Fatalj ¶
Fatalj is equivalent to a call to l.Criticalj() followed by a call to os.Exit(1).
func (*Logger) Fatalln ¶
func (l *Logger) Fatalln(v ...interface{})
Fatalln is equivalent to a call to l.Criticalln() followed by a call to os.Exit(1).
func (*Logger) Info ¶
func (l *Logger) Info(v ...interface{})
Info logs routine information, such as ongoing status or performance. Arguments are handled in the manner of fmt.Print.
func (*Logger) Infof ¶
Infof logs routine information, such as ongoing status or performance. Arguments are handled in the manner of fmt.Printf.
func (*Logger) Infoj ¶
Infoj logs routine information, such as ongoing status or performance. Argument v becomes the jsonPayload field of the log entry.
func (*Logger) Infoln ¶
func (l *Logger) Infoln(v ...interface{})
Infoln logs routine information, such as ongoing status or performance. Arguments are handled in the manner of fmt.Println.
func (*Logger) Notice ¶
func (l *Logger) Notice(v ...interface{})
Notice logs normal but significant events, such as start up, shut down, or configuration. Arguments are handled in the manner of fmt.Print.
func (*Logger) Noticef ¶
Noticef logs normal but significant events, such as start up, shut down, or configuration. Arguments are handled in the manner of fmt.Printf.
func (*Logger) Noticej ¶
Noticej logs normal but significant events, such as start up, shut down, or configuration. Argument v becomes the jsonPayload field of the log entry.
func (*Logger) Noticeln ¶
func (l *Logger) Noticeln(v ...interface{})
Noticeln logs normal but significant events, such as start up, shut down, or configuration. Arguments are handled in the manner of fmt.Println.
func (*Logger) Panic ¶
func (l *Logger) Panic(v ...interface{})
Panic is equivalent to a call to l.Critical() followed by a call to panic().
func (*Logger) Panicf ¶
Panicf is equivalent to a call to l.Criticalf() followed by a call to panic().
func (*Logger) Panicj ¶
Panicj is equivalent to a call to l.Criticalj() followed by a call to panic().
func (*Logger) Panicln ¶
func (l *Logger) Panicln(v ...interface{})
Panicln is equivalent to a call to l.Criticalln() followed by a call to panic().
func (*Logger) Print ¶
func (l *Logger) Print(v ...interface{})
Print logs routine information, such as ongoing status or performance, same as l.Info(). Arguments are handled in the manner of fmt.Print.
func (*Logger) Printf ¶
Printf logs routine information, such as ongoing status or performance, same as l.Infof(). Arguments are handled in the manner of fmt.Printf.
func (*Logger) Printj ¶
Printj logs routine information, such as ongoing status or performance, same as l.Infoj(). Argument v becomes the jsonPayload field of the log entry.
func (*Logger) Println ¶
func (l *Logger) Println(v ...interface{})
Println logs routine information, such as ongoing status or performance, same as l.Infoln(). Arguments are handled in the manner of fmt.Println.
func (*Logger) Warning ¶
func (l *Logger) Warning(v ...interface{})
Warning logs events that might cause problems. Arguments are handled in the manner of fmt.Print.
func (*Logger) Warningf ¶
Warningf logs events that might cause problems. Arguments are handled in the manner of fmt.Printf.