Categorygithub.com/go-glog/glog
modulepackage
2.0.8+incompatible
Repository: https://github.com/go-glog/glog.git
Documentation: pkg.go.dev

# README

Glog

This fork of https://github.com/golang/glog provides all of glog's functionality and adds the ability to send errors/logs to Airbrake.io.

Logging

Please refer to the glog code & docs.

Sending errors to Airbrake.io

A basic example of how to configure glog to send logged errors to Airbrake.io:

package main

import (
	"errors"

	"gopkg.in/airbrake/glog.v2"
	"gopkg.in/airbrake/gobrake.v2"
)

var projectId int64 = 123
var apiKey string = "API_KEY"

func doSomeWork() error {
	return errors.New("hello from Go")
}

func main() {
	airbrake := gobrake.NewNotifier(projectId, apiKey)
	defer airbrake.Close()
	defer airbrake.NotifyOnPanic()

	airbrake.AddFilter(func(n *gobrake.Notice) *gobrake.Notice {
		n.Context["environment"] = "production"
		return n
	})
	glog.Gobrake = airbrake

	if err := doSomeWork(); err != nil {
		glog.Errorf("doSomeWork failed: %s", err)
	}
}

Configure severity

The default is to send only error logs to Airbrake.io. You can change the severity threshold to also send lower severity logs too, such as warnings:

glog.GobrakeSeverity = "WARNING"

# Functions

CopyStandardLogTo arranges for messages written to the Go "log" package's default logs to also appear in the Google logs for the named and lower severities.
Error logs to the ERROR, WARNING, and INFO logs.
Errorf logs to the ERROR, WARNING, and INFO logs.
Errorln logs to the ERROR, WARNING, and INFO logs.
Exit logs to the FATAL, ERROR, WARNING, and INFO logs, then calls os.Exit(1).
Exitf logs to the FATAL, ERROR, WARNING, and INFO logs, then calls os.Exit(1).
Exitln logs to the FATAL, ERROR, WARNING, and INFO logs, then calls os.Exit(1).
Fatal logs to the FATAL, ERROR, WARNING, and INFO logs, including a stack trace of all running goroutines, then calls os.Exit(255).
Fatalf logs to the FATAL, ERROR, WARNING, and INFO logs, including a stack trace of all running goroutines, then calls os.Exit(255).
Fatalln logs to the FATAL, ERROR, WARNING, and INFO logs, including a stack trace of all running goroutines, then calls os.Exit(255).
Flush flushes all pending log I/O and calls Gobrake.Flush if Gobrake is not nil.
Info logs to the INFO log.
Infof logs to the INFO log.
Infoln logs to the INFO log.
SetMaxSize sets maximum size of a log file in bytes.
V reports whether verbosity at the call site is at least the requested level.
Warning logs to the WARNING and INFO logs.
Warningf logs to the WARNING and INFO logs.
Warningln logs to the WARNING and INFO logs.

# Variables

Gobrake is an instance of Airbrake Go Notifier that is used to send logs to Airbrake.
Minimum log severity that will be sent to Airbrake.
Stats tracks the number of lines of output and number of bytes per severity level.

# Type aliases

Verbose is a boolean type that implements Infof (like Printf) etc.