Documentation ¶
Overview ¶
Package glog implements leveled, structured logging for Google App Engine, Kubernetes Engine, Cloud Run, and Cloud Functions.
Structured logs are written to stdout or stderr as JSON objects serialized on a single line. The Logging agent then sends the structured logs to Cloud Logging as the jsonPayload of the LogEntry structure.
Index ¶
- Variables
- func Alert(v ...any)
- func Alertf(format string, v ...any)
- func Alertj(msg string, v any)
- func Alertln(v ...any)
- func Alertw(msg string, kvs ...any)
- func Critical(v ...any)
- func Criticalf(format string, v ...any)
- func Criticalj(msg string, v any)
- func Criticalln(v ...any)
- func Criticalw(msg string, kvs ...any)
- func Debug(v ...any)
- func Debugf(format string, v ...any)
- func Debugj(msg string, v any)
- func Debugln(v ...any)
- func Debugw(msg string, kvs ...any)
- func Emergency(v ...any)
- func Emergencyf(format string, v ...any)
- func Emergencyj(msg string, v any)
- func Emergencyln(v ...any)
- func Emergencyw(msg string, kvs ...any)
- func Error(v ...any)
- func Errorf(format string, v ...any)
- func Errorj(msg string, v any)
- func Errorln(v ...any)
- func Errorw(msg string, kvs ...any)
- func Info(v ...any)
- func Infof(format string, v ...any)
- func Infoj(msg string, v any)
- func Infoln(v ...any)
- func Infow(msg string, kvs ...any)
- func Notice(v ...any)
- func Noticef(format string, v ...any)
- func Noticej(msg string, v any)
- func Noticeln(v ...any)
- func Noticew(msg string, kvs ...any)
- func Print(v ...any)
- func Printf(format string, v ...any)
- func Printj(msg string, v any)
- func Println(v ...any)
- func Printw(msg string, kvs ...any)
- func SetupLogger(l *log.Logger)
- func Warning(v ...any)
- func Warningf(format string, v ...any)
- func Warningj(msg string, v any)
- func Warningln(v ...any)
- func Warningw(msg string, kvs ...any)
- type Logger
- func (l Logger) Alert(v ...any)
- func (l Logger) Alertf(format string, v ...any)
- func (l Logger) Alertj(msg string, v any)
- func (l Logger) Alertln(v ...any)
- func (l Logger) Alertw(msg string, kvs ...any)
- func (l Logger) Critical(v ...any)
- func (l Logger) Criticalf(format string, v ...any)
- func (l Logger) Criticalj(msg string, v any)
- func (l Logger) Criticalln(v ...any)
- func (l Logger) Criticalw(msg string, kvs ...any)
- func (l Logger) Debug(v ...any)
- func (l Logger) Debugf(format string, v ...any)
- func (l Logger) Debugj(msg string, v any)
- func (l Logger) Debugln(v ...any)
- func (l Logger) Debugw(msg string, kvs ...any)
- func (l Logger) Emergency(v ...any)
- func (l Logger) Emergencyf(format string, v ...any)
- func (l Logger) Emergencyj(msg string, v any)
- func (l Logger) Emergencyln(v ...any)
- func (l Logger) Emergencyw(msg string, kvs ...any)
- func (l Logger) Error(v ...any)
- func (l Logger) Errorf(format string, v ...any)
- func (l Logger) Errorj(msg string, v any)
- func (l Logger) Errorln(v ...any)
- func (l Logger) Errorw(msg string, kvs ...any)
- func (l Logger) Info(v ...any)
- func (l Logger) Infof(format string, v ...any)
- func (l Logger) Infoj(msg string, v any)
- func (l Logger) Infoln(v ...any)
- func (l Logger) Infow(msg string, kvs ...any)
- func (l Logger) Notice(v ...any)
- func (l Logger) Noticef(format string, v ...any)
- func (l Logger) Noticej(msg string, v any)
- func (l Logger) Noticeln(v ...any)
- func (l Logger) Noticew(msg string, kvs ...any)
- func (l Logger) Print(v ...any)
- func (l Logger) Printf(format string, v ...any)
- func (l Logger) Printj(msg string, v any)
- func (l Logger) Println(v ...any)
- func (l Logger) Printw(msg string, kvs ...any)
- func (l *Logger) SetContext(ctx context.Context)
- func (l Logger) Warning(v ...any)
- func (l Logger) Warningf(format string, v ...any)
- func (l Logger) Warningj(msg string, v any)
- func (l Logger) Warningln(v ...any)
- func (l Logger) Warningw(msg string, kvs ...any)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var LogSourceLocation bool = true
LogSourceLocation should be set to false to avoid associating source code location information with the entry.
var ProjectID string = os.Getenv("GOOGLE_CLOUD_PROJECT")
ProjectID should be set to the Google Cloud project ID.
Functions ¶
func Alert ¶
func Alert(v ...any)
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 ...any)
Alertf logs when a person must take an action immediately. Arguments are handled in the manner of fmt.Printf.
func Alertj ¶ added in v0.3.0
func Alertj(msg string, v any)
Alertj logs when a person must take an action immediately. Arguments populate jsonPayload in the log entry.
func Alertln ¶
func Alertln(v ...any)
Alertln logs when a person must take an action immediately. Arguments are handled in the manner of fmt.Println.
func Alertw ¶ added in v0.7.5
func Alertw(msg string, kvs ...any)
Alertw logs when a person must take an action immediately. Arguments populate jsonPayload in the log entry.
func Critical ¶
func Critical(v ...any)
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 ...any)
Criticalf logs events that cause more severe problems or outages. Arguments are handled in the manner of fmt.Printf.
func Criticalj ¶ added in v0.3.0
func Criticalj(msg string, v any)
Criticalj logs events that cause more severe problems or outages. Arguments populate jsonPayload in the log entry.
func Criticalln ¶
func Criticalln(v ...any)
Criticalln logs events that cause more severe problems or outages. Arguments are handled in the manner of fmt.Println.
func Criticalw ¶ added in v0.7.5
func Criticalw(msg string, kvs ...any)
Criticalw logs events that cause more severe problems or outages. Arguments populate jsonPayload in the log entry.
func Debug ¶
func Debug(v ...any)
Debug logs debug or trace information. Arguments are handled in the manner of fmt.Print.
func Debugf ¶
func Debugf(format string, v ...any)
Debugf logs debug or trace information. Arguments are handled in the manner of fmt.Printf.
func Debugj ¶ added in v0.3.0
func Debugj(msg string, v any)
Debugj logs debug or trace information. Arguments populate jsonPayload in the log entry.
func Debugln ¶
func Debugln(v ...any)
Debugln logs debug or trace information. Arguments are handled in the manner of fmt.Println.
func Debugw ¶ added in v0.7.5
func Debugw(msg string, kvs ...any)
Debugw logs debug or trace information. Arguments populate jsonPayload in the log entry.
func Emergency ¶
func Emergency(v ...any)
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 ...any)
Emergencyf logs when one or more systems are unusable. Arguments are handled in the manner of fmt.Printf.
func Emergencyj ¶ added in v0.3.0
func Emergencyj(msg string, v any)
Emergencyj logs when one or more systems are unusable. Arguments populate jsonPayload in the log entry.
func Emergencyln ¶
func Emergencyln(v ...any)
Emergencyln logs when one or more systems are unusable. Arguments are handled in the manner of fmt.Println.
func Emergencyw ¶ added in v0.7.5
func Emergencyw(msg string, kvs ...any)
Emergencyw logs when one or more systems are unusable. Arguments populate jsonPayload in the log entry.
func Error ¶
func Error(v ...any)
Error logs events likely to cause problems. Arguments are handled in the manner of fmt.Print.
func Errorf ¶
func Errorf(format string, v ...any)
Errorf logs events likely to cause problems. Arguments are handled in the manner of fmt.Printf.
func Errorj ¶ added in v0.3.0
func Errorj(msg string, v any)
Errorj logs events likely to cause problems. Arguments populate jsonPayload in the log entry.
func Errorln ¶
func Errorln(v ...any)
Errorln logs events likely to cause problems. Arguments are handled in the manner of fmt.Println.
func Errorw ¶ added in v0.7.5
func Errorw(msg string, kvs ...any)
Errorw logs events likely to cause problems. Arguments populate jsonPayload in the log entry.
func Info ¶
func Info(v ...any)
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 ...any)
Infof logs routine information, such as ongoing status or performance. Arguments are handled in the manner of fmt.Printf.
Example ¶
package main import ( "github.com/ncruces/go-gcp/glog" ) func main() { glog.Infof("Hello %q!", "Google") }
Output: {"message":"Hello \"Google\"!","severity":"INFO"}
func Infoj ¶ added in v0.3.0
func Infoj(msg string, v any)
Infoj logs routine information, such as ongoing status or performance. Arguments populate jsonPayload in the log entry.
func Infoln ¶
func Infoln(v ...any)
Infoln logs routine information, such as ongoing status or performance. Arguments are handled in the manner of fmt.Println.
func Infow ¶ added in v0.7.5
func Infow(msg string, kvs ...any)
Infow logs routine information, such as ongoing status or performance. Arguments populate jsonPayload in the log entry.
func Notice ¶
func Notice(v ...any)
Notice logs normal but significant events, such as start up, shut down, or configuration. Arguments are handled in the manner of fmt.Print.
func Noticef ¶
func Noticef(format string, v ...any)
Noticef logs normal but significant events, such as start up, shut down, or configuration. Arguments are handled in the manner of fmt.Printf.
func Noticej ¶ added in v0.3.0
func Noticej(msg string, v any)
Noticej logs normal but significant events, such as start up, shut down, or configuration. Arguments populate jsonPayload in the log entry.
func Noticeln ¶
func Noticeln(v ...any)
Noticeln logs normal but significant events, such as start up, shut down, or configuration. Arguments are handled in the manner of fmt.Println.
func Noticew ¶ added in v0.7.5
func Noticew(msg string, kvs ...any)
Noticew logs normal but significant events, such as start up, shut down, or configuration. Arguments populate jsonPayload in the log entry.
func Print ¶
func Print(v ...any)
Print logs an entry with no assigned severity level. Arguments are handled in the manner of fmt.Print.
Example ¶
package main import ( "github.com/ncruces/go-gcp/glog" ) func main() { glog.Print("Test") }
Output: {"message":"Test"}
func Printf ¶
func Printf(format string, v ...any)
Printf logs an entry with no assigned severity level. Arguments are handled in the manner of fmt.Printf.
func Printj ¶ added in v0.3.0
func Printj(msg string, v any)
Printj logs an entry with no assigned severity level. Arguments populate jsonPayload in the log entry.
func Println ¶
func Println(v ...any)
Println logs an entry with no assigned severity level. Arguments are handled in the manner of fmt.Println.
func Printw ¶ added in v0.7.5
func Printw(msg string, kvs ...any)
Printw logs an entry with no assigned severity level. Arguments populate jsonPayload in the log entry.
func SetupLogger ¶ added in v0.7.5
SetupLogger sets up a log.Logger to output structured logs at the default severity level.
Example ¶
package main import ( "log" "github.com/ncruces/go-gcp/glog" ) func main() { glog.SetupLogger(log.Default()) log.Print("Test") }
Output: {"message":"Test"}
func Warning ¶
func Warning(v ...any)
Warning logs events that might cause problems. Arguments are handled in the manner of fmt.Print.
func Warningf ¶
func Warningf(format string, v ...any)
Warningf logs events that might cause problems. Arguments are handled in the manner of fmt.Printf.
func Warningj ¶ added in v0.3.0
func Warningj(msg string, v any)
Warningj logs events that might cause problems. Arguments populate jsonPayload in the log entry.
Example ¶
package main import ( "github.com/ncruces/go-gcp/glog" ) func main() { glog.Warningj("Warning", map[string]string{ "component": "app", }) }
Output: {"component":"app","message":"Warning","severity":"WARNING"}
func Warningln ¶
func Warningln(v ...any)
Warningln logs events that might cause problems. Arguments are handled in the manner of fmt.Println.
func Warningw ¶ added in v0.7.5
func Warningw(msg string, kvs ...any)
Warningw logs events that might cause problems. Arguments populate jsonPayload in the log entry.
Example ¶
package main import ( "github.com/ncruces/go-gcp/glog" ) func main() { glog.Warningw("Warning", "component", "app") }
Output: {"component":"app","message":"Warning","severity":"WARNING"}
Types ¶
type Logger ¶ added in v0.2.0
type Logger struct {
// contains filtered or unexported fields
}
A Logger that logs entries with additional context.
func ForContext ¶ added in v0.6.10
ForContext creates a Logger with metadata from a context.Context.
func ForRequest ¶ added in v0.2.0
ForRequest creates a Logger with metadata from an http.Request.
func (Logger) Alert ¶ added in v0.2.0
func (l Logger) Alert(v ...any)
Alert logs when a person must take an action immediately. Arguments are handled in the manner of fmt.Print.
func (Logger) Alertf ¶ added in v0.2.0
Alertf logs when a person must take an action immediately. Arguments are handled in the manner of fmt.Printf.
func (Logger) Alertj ¶ added in v0.3.0
Alertj logs when a person must take an action immediately. Arguments populate jsonPayload in the log entry.
func (Logger) Alertln ¶ added in v0.2.0
func (l Logger) Alertln(v ...any)
Alertln logs when a person must take an action immediately. Arguments are handled in the manner of fmt.Println.
func (Logger) Alertw ¶ added in v0.7.5
Alertw logs when a person must take an action immediately. Arguments populate jsonPayload in the log entry.
func (Logger) Critical ¶ added in v0.2.0
func (l Logger) Critical(v ...any)
Critical logs events that cause more severe problems or outages. Arguments are handled in the manner of fmt.Print.
func (Logger) Criticalf ¶ added in v0.2.0
Criticalf logs events that cause more severe problems or outages. Arguments are handled in the manner of fmt.Printf.
func (Logger) Criticalj ¶ added in v0.3.0
Criticalj logs events that cause more severe problems or outages. Arguments populate jsonPayload in the log entry.
func (Logger) Criticalln ¶ added in v0.2.0
func (l Logger) Criticalln(v ...any)
Criticalln logs events that cause more severe problems or outages. Arguments are handled in the manner of fmt.Println.
func (Logger) Criticalw ¶ added in v0.7.5
Criticalw logs events that cause more severe problems or outages. Arguments populate jsonPayload in the log entry.
func (Logger) Debug ¶ added in v0.2.0
func (l Logger) Debug(v ...any)
Debug logs debug or trace information. Arguments are handled in the manner of fmt.Print.
func (Logger) Debugf ¶ added in v0.2.0
Debugf logs debug or trace information. Arguments are handled in the manner of fmt.Printf.
func (Logger) Debugj ¶ added in v0.3.0
Debugj logs debug or trace information. Arguments populate jsonPayload in the log entry.
func (Logger) Debugln ¶ added in v0.2.0
func (l Logger) Debugln(v ...any)
Debugln logs debug or trace information. Arguments are handled in the manner of fmt.Println.
func (Logger) Debugw ¶ added in v0.7.5
Debugw logs debug or trace information. Arguments populate jsonPayload in the log entry.
func (Logger) Emergency ¶ added in v0.2.0
func (l Logger) Emergency(v ...any)
Emergency logs when one or more systems are unusable. Arguments are handled in the manner of fmt.Print.
func (Logger) Emergencyf ¶ added in v0.2.0
Emergencyf logs when one or more systems are unusable. Arguments are handled in the manner of fmt.Printf.
func (Logger) Emergencyj ¶ added in v0.3.0
Emergencyj logs when one or more systems are unusable. Arguments populate jsonPayload in the log entry.
func (Logger) Emergencyln ¶ added in v0.2.0
func (l Logger) Emergencyln(v ...any)
Emergencyln logs when one or more systems are unusable. Arguments are handled in the manner of fmt.Println.
func (Logger) Emergencyw ¶ added in v0.7.5
Emergencyw logs when one or more systems are unusable. Arguments populate jsonPayload in the log entry.
func (Logger) Error ¶ added in v0.2.0
func (l Logger) Error(v ...any)
Error logs events likely to cause problems. Arguments are handled in the manner of fmt.Print.
func (Logger) Errorf ¶ added in v0.2.0
Errorf logs events likely to cause problems. Arguments are handled in the manner of fmt.Printf.
func (Logger) Errorj ¶ added in v0.3.0
Errorj logs events likely to cause problems. Arguments populate jsonPayload in the log entry.
func (Logger) Errorln ¶ added in v0.2.0
func (l Logger) Errorln(v ...any)
Errorln logs events likely to cause problems. Arguments are handled in the manner of fmt.Println.
func (Logger) Errorw ¶ added in v0.7.5
Errorw logs events likely to cause problems. Arguments populate jsonPayload in the log entry.
func (Logger) Info ¶ added in v0.2.0
func (l Logger) Info(v ...any)
Info logs routine information, such as ongoing status or performance. Arguments are handled in the manner of fmt.Print.
func (Logger) Infof ¶ added in v0.2.0
Infof logs routine information, such as ongoing status or performance. Arguments are handled in the manner of fmt.Printf.
func (Logger) Infoj ¶ added in v0.3.0
Infoj logs routine information, such as ongoing status or performance. Arguments populate jsonPayload in the log entry.
func (Logger) Infoln ¶ added in v0.2.0
func (l Logger) Infoln(v ...any)
Infoln logs routine information, such as ongoing status or performance. Arguments are handled in the manner of fmt.Println.
func (Logger) Infow ¶ added in v0.7.5
Infow logs routine information, such as ongoing status or performance. Arguments populate jsonPayload in the log entry.
func (Logger) Notice ¶ added in v0.2.0
func (l Logger) Notice(v ...any)
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 ¶ added in v0.2.0
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 ¶ added in v0.3.0
Noticej logs normal but significant events, such as start up, shut down, or configuration. Arguments populate jsonPayload in the log entry.
func (Logger) Noticeln ¶ added in v0.2.0
func (l Logger) Noticeln(v ...any)
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) Noticew ¶ added in v0.7.5
Noticew logs normal but significant events, such as start up, shut down, or configuration. Arguments populate jsonPayload in the log entry.
func (Logger) Print ¶ added in v0.2.0
func (l Logger) Print(v ...any)
Print logs an entry with no assigned severity level. Arguments are handled in the manner of fmt.Print.
func (Logger) Printf ¶ added in v0.2.0
Printf logs an entry with no assigned severity level. Arguments are handled in the manner of fmt.Printf.
func (Logger) Printj ¶ added in v0.3.0
Printj logs an entry with no assigned severity level. Arguments populate jsonPayload in the log entry.
func (Logger) Println ¶ added in v0.2.0
func (l Logger) Println(v ...any)
Println logs an entry with no assigned severity level. Arguments are handled in the manner of fmt.Println.
func (Logger) Printw ¶ added in v0.7.5
Printw logs an entry with no assigned severity level. Arguments populate jsonPayload in the log entry.
func (*Logger) SetContext ¶ added in v0.7.6
SetContext updates a Logger with metadata from a context.Context.
func (Logger) Warning ¶ added in v0.2.0
func (l Logger) Warning(v ...any)
Warning logs events that might cause problems. Arguments are handled in the manner of fmt.Print.
func (Logger) Warningf ¶ added in v0.2.0
Warningf logs events that might cause problems. Arguments are handled in the manner of fmt.Printf.
func (Logger) Warningj ¶ added in v0.3.0
Warningj logs events that might cause problems. Arguments populate jsonPayload in the log entry.