logz

package module
v0.2.3 Latest Latest
Warning

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

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

README

logz

CI for Pull Request Godoc Go Report Card GitHub license

The logz is Go library for grouping a access log and application logs. logz uses OpenTelemetry(https://opentelemetry.io) to generate the trace id.
This is for Google Cloud Logging (formerly known as Stackdriver Logging).
The logz supports to App Engine and Cloud Run and GKE.

Use go111 package if your project is App Engine 1st generation.

Install

$ go get github.com/glassonion1/logz

Usage

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

    // Writes info log
    logz.Infof(ctx, "logging...")
})

logz.SetProjectID("your gcp project id")
logz.InitTracer()
// Sets the middleware
h := middleware.NetHTTP("tracer name")(mux)

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

Examples

See this sample projects for logz detailed usage
https://github.com/glassonion1/logz/tree/main/example

How logs are grouped

The logz leverages the grouping feature of GCP Cloud Logging. See following references for more details.

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 Infof

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

Infof writes info log to the stdout

func InitTracer added in v0.1.1

func InitTracer()

InitTracer initializes OpenTelemetry tracer

func SetProjectID

func SetProjectID(projectID string)

SetProjectID sets gcp 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