https://github.com/spider-pigs/spiderlog
A simple logging client for spiders.
https://github.com/spider-pigs/spiderlog
golang logging stackdriver-logs
Last synced: 25 days ago
JSON representation
A simple logging client for spiders.
- Host: GitHub
- URL: https://github.com/spider-pigs/spiderlog
- Owner: spider-pigs
- License: mit
- Created: 2019-06-13T11:33:50.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-12-08T15:32:55.000Z (about 5 years ago)
- Last Synced: 2024-06-19T06:50:00.294Z (over 1 year ago)
- Topics: golang, logging, stackdriver-logs
- Language: Go
- Homepage:
- Size: 13.7 KB
- Stars: 4
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# spiderlog
[](https://travis-ci.org/spider-pigs/spiderlog) [](https://goreportcard.com/report/github.com/spider-pigs/spiderlog) [](https://godoc.org/github.com/spider-pigs/spiderlog)
spiderlog is a simple logging client.
## Install
```Golang
import "github.com/spider-pigs/spiderlog"
```
## Usage
There are four logging levels supported: `Debug`, `Info`, `Warning`, `Error`
Here is an example of how to setup logging for a Google logging client.
```Golang
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")
}
```