spider-pigs / spiderlog

A simple logging client for spiders.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

spiderlog

Build Status Go Report Card GoDoc

spiderlog is a simple logging client.

Install

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.

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")
}

About

A simple logging client for spiders.

License:MIT License


Languages

Language:Go 100.0%