logz

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2020 License: MIT Imports: 13 Imported by: 8

README

logz

CI for Pull Request Godoc GitHub license

Package logz provides the structured log with the OpenTelemetry(https://opentelemetry.io).
This is for Google Cloud Logging (formerly known as Stackdriver).
The logz supports to App Engine and Cloud Run and GKE.

Install

$ go get github.com/glassonion1/logz

Usage

mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    ctx := r.Context()
    logz.Infof(ctx, "logging...")
})

logz.SetProjectID("your project id")
if err := logz.InitCloudTracer(); err != nil {
    // TODO: hanlde error...
}

h := logz.HTTPMiddleware("tracer name")(mux)

log.Fatal(http.ListenAndServe(":8080", h))

Documentation

Overview

Package logz provides the structured log with the OpenTelemetry.

Example:

ctx := r.Context() // r is *http.Request
logz.Infof(ctx, "info log. requestURL: %s", r.URL.String())

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Criticalf

func Criticalf(ctx context.Context, format string, a ...interface{})

Criticalf writes critical log to the stdout

func Debugf

func Debugf(ctx context.Context, format string, a ...interface{})

Debugf writes debug log to the stdout

func Errorf

func Errorf(ctx context.Context, format string, a ...interface{})

Errorf writes error log to the stdout

func HTTPMiddleware

func HTTPMiddleware(label string) func(http.Handler) http.Handler

func HTTPMiddleware2 added in v0.1.1

func HTTPMiddleware2(label string) func(http.Handler) http.Handler

HTTPMiddleware is middleware for HTTP handler

func Infof

func Infof(ctx context.Context, format string, a ...interface{})

Infof writes info log to the stdout

func InitCloudTracer

func InitCloudTracer(opts ...option.ClientOption) error

InitCloudTracer initializes tracer of OpenTelemetry, that is for Cloud Logging(formerly known as Stackdriver Logging)

func InitStdoutTracer

func InitStdoutTracer() error

InitStdoutTracer initializes tracer of OpenTelemetry, that is for stdout

func InitTracer added in v0.1.1

func InitTracer() error

func SetProjectID

func SetProjectID(pID string)

SetProjectID sets project id to the logger

func Warningf

func Warningf(ctx context.Context, format string, a ...interface{})

Warningf writes warning log to the stdout

Types

This section is empty.

Directories

Path Synopsis
contrib
example
nethttp Module
nethttptrace Module
go111 module
internal

Jump to

Keyboard shortcuts

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