glog

package
v0.7.9 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2023 License: MIT Imports: 11 Imported by: 0

README

Google Cloud Logging in Go for App Engine, Kubernetes Engine, Cloud Run, and Cloud Functions

PkgGoDev

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

Examples

Constants

This section is empty.

Variables

View Source
var LogSourceLocation bool = true

LogSourceLocation should be set to false to avoid associating source code location information with the entry.

View Source
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

func SetupLogger(l *log.Logger)

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

func ForContext(ctx context.Context) (l Logger)

ForContext creates a Logger with metadata from a context.Context.

func ForRequest added in v0.2.0

func ForRequest(r *http.Request) (l Logger)

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

func (l Logger) 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 (Logger) Alertj added in v0.3.0

func (l Logger) Alertj(msg string, v any)

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

func (l Logger) Alertw(msg string, kvs ...any)

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

func (l Logger) 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 (Logger) Criticalj added in v0.3.0

func (l Logger) Criticalj(msg string, v any)

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

func (l Logger) Criticalw(msg string, kvs ...any)

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

func (l Logger) Debugf(format string, v ...any)

Debugf logs debug or trace information. Arguments are handled in the manner of fmt.Printf.

func (Logger) Debugj added in v0.3.0

func (l Logger) Debugj(msg string, v any)

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

func (l Logger) Debugw(msg string, kvs ...any)

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

func (l Logger) Emergencyf(format string, v ...any)

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

func (l Logger) Emergencyj(msg string, v any)

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

func (l Logger) Emergencyw(msg string, kvs ...any)

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

func (l Logger) Errorf(format string, v ...any)

Errorf logs events likely to cause problems. Arguments are handled in the manner of fmt.Printf.

func (Logger) Errorj added in v0.3.0

func (l Logger) Errorj(msg string, v any)

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

func (l Logger) Errorw(msg string, kvs ...any)

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

func (l Logger) Infof(format string, v ...any)

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

func (l Logger) Infoj(msg string, v any)

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

func (l Logger) Infow(msg string, kvs ...any)

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

func (l Logger) 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 (Logger) Noticej added in v0.3.0

func (l Logger) 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 (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

func (l Logger) 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 (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

func (l Logger) Printf(format string, v ...any)

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

func (l Logger) Printj(msg string, v any)

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

func (l Logger) Printw(msg string, kvs ...any)

Printw logs an entry with no assigned severity level. Arguments populate jsonPayload in the log entry.

func (*Logger) SetContext added in v0.7.6

func (l *Logger) SetContext(ctx context.Context)

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

func (l Logger) Warningf(format string, v ...any)

Warningf logs events that might cause problems. Arguments are handled in the manner of fmt.Printf.

func (Logger) Warningj added in v0.3.0

func (l Logger) Warningj(msg string, v any)

Warningj logs events that might cause problems. Arguments populate jsonPayload in the log entry.

func (Logger) Warningln added in v0.2.0

func (l Logger) Warningln(v ...any)

Warningln logs events that might cause problems. Arguments are handled in the manner of fmt.Println.

func (Logger) Warningw added in v0.7.5

func (l Logger) Warningw(msg string, kvs ...any)

Warningw logs events that might cause problems. Arguments populate jsonPayload in the log entry.

Jump to

Keyboard shortcuts

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