cflog

package module
v0.0.0-...-e3ee5eb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2019 License: MIT Imports: 12 Imported by: 0

README

cflog

A package to help with logging in GCP Cloud Functions with severity

https://godoc.org/github.com/mvndaai/cflog

Documentation

Overview

Package cflog helps with logging GCP Cloud Functions.

Example (JsonString)
package main

import (
	"context"

	"github.com/mvndaai/cflog"
)

var ctx = context.Background()

func main() {
	cflog.Warn(ctx, `{"message": "json string"}`)
}
Output:

Example (JsonStruct)
package main

import (
	"context"

	"github.com/mvndaai/cflog"
)

var ctx = context.Background()

func main() {
	type s struct {
		Message string `json:"message"`
	}

	cflog.Error(ctx, s{Message: "json struct"})
}
Output:

Example (String)
package main

import (
	"context"

	"github.com/mvndaai/cflog"
)

var ctx = context.Background()

func main() {
	cflog.Debug(ctx, "string")
}
Output:

Index

Examples

Constants

View Source
const (
	SeverityDefault   = Severity(ltype.LogSeverity_DEFAULT)
	SeverityDebug     = Severity(ltype.LogSeverity_DEBUG)
	SeverityInfo      = Severity(ltype.LogSeverity_INFO)
	SeverityNotice    = Severity(ltype.LogSeverity_NOTICE)
	SeverityWarning   = Severity(ltype.LogSeverity_WARNING)
	SeverityError     = Severity(ltype.LogSeverity_ERROR)
	SeverityCritical  = Severity(ltype.LogSeverity_CRITICAL)
	SeverityAlert     = Severity(ltype.LogSeverity_ALERT)
	SeverityEmergency = Severity(ltype.LogSeverity_EMERGENCY)
)

Using the log packages severity. https://godoc.org/google.golang.org/genproto/googleapis/logging/type#LogSeverity

Variables

This section is empty.

Functions

func Critical

func Critical(ctx context.Context, payload interface{})

Critical calls Log with the severity set to Critical.

func Debug

func Debug(ctx context.Context, payload interface{})

Debug calls Log with the severity set to Debug.

func Error

func Error(ctx context.Context, payload interface{})

Error calls Log with the severity set to Error.

func Info

func Info(ctx context.Context, payload interface{})

Info calls Log with the severity set to Info.

func Log

func Log(ctx context.Context, severity Severity, payload interface{})

Log uses an auto generated singleton client.

Warning: Any errors posting will be logged with no log severity.

func Warn

func Warn(ctx context.Context, payload interface{})

Warn calls Log with the severity set to Warning.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client holds a logging client and the resources needed for logging.

func NewClient

func NewClient(ctx context.Context) (Client, error)

NewClient creates a client for writing logs using environment variable. Use this if you want to want full control over the client. https://cloud.google.com/functions/docs/env-var

Example
package main

import (
	"context"

	"github.com/mvndaai/cflog"
)

func main() {
	c, err := cflog.NewClient(context.Background())
	if err != nil {
		//...
	}
	defer c.Close()
	if err := c.Log(context.Background(), cflog.SeverityDebug, "Debug message"); err != nil {
		//...
	}
}
Output:

func (Client) Close

func (c Client) Close() error

Close will close the underlying client.

func (Client) Log

func (c Client) Log(ctx context.Context, severity Severity, payload interface{}) error

Log creates a log using the payload given. Payload should be either a string or a struct that can marshal to JSON.

type Severity

type Severity ltype.LogSeverity

Severity is a wrapper around an int for log severity.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL