Skip to content

spider-pigs/spiderlog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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