spiderlog is a simple logging client.
import "github.com/spider-pigs/spiderlog"
There are four logging levels supported: Debug
, Info
, Warning
, Error
Here is an example of how to setup logging for a Google logging client.
package main
import (
"context"
"cloud.google.com/go/logging"
"github.com/spider-pigs/spiderlog"
)
// Initialize log to guard from nil pointer dereferences
var log = spiderlog.New()
func main() {
project := "projects/some_project_id"
client, err := logging.NewClient(context.Background(), project)
if err != nil {
log.Fatal(err)
}
log = spiderlog.New(
spiderlog.DebugLogger(client.Logger("a_log_id").StandardLogger(logging.Debug)),
spiderlog.InfoLogger(client.Logger("a_log_id").StandardLogger(logging.Info)),
spiderlog.WarningLogger(client.Logger("a_log_id").StandardLogger(logging.Warning)),
spiderlog.ErrorLogger(client.Logger("a_log_id").StandardLogger(logging.Error)),
spiderlog.StdoutEnabled(false), // Defaults to true
)
// Write an info log
log.Info("Hello World!")
// Or log with formatting
log.Infof("Hello %s!\n", "World")
}