go111

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2021 License: MIT Imports: 5 Imported by: 0

README

logz for Go 1.11

This is for migrating google.golang.org/appengine/log of Ape Enigne 1st generation.
Guaranteed to work on Google App Engine 1st generation of Go 1.11.

screenshot

Install

$ go get github.com/glassonion1/logz/go111

Usage

package main

import (
    "log"
    "net/http"

    logz "github.com/glassonion1/logz/go111"
    "github.com/glassonion1/logz/go111/middleware"
)

func main() {
    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")
    // Sets the middleware
    h := middleware.NetHTTP("tracer name")(mux)

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

Migrates to logz from google.golang.org/appengine/log

From App Engine Logger

import "google.golang.org/appengine/log"

func Handler(w http.ResponseWriter, r *http.Request) {
    ctx := appengine.NewContext(r)
    log.Infof(ctx, "write log %v", "info")
}

To logz

import(
-   "google.golang.org/appengine/log"
+   log "github.com/glassonion1/logz/go111"
) 

func Handler(w http.ResponseWriter, r *http.Request) {
-   ctx := appengine.NewContext(r)
+   ctx := r.Context()
    log.Infof(ctx, "write log %v", "info")
}

Removes appengine.Context to context.Context

Documentation

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 SetConfig added in v0.1.3

func SetConfig(cfg Config)

SetConfig sets config to the logger

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

type Config added in v0.1.3

type Config struct {
	// GCP Project ID
	ProjectID string
	// CallerDepth is the number of stack frames to ascend
	CallerSkip int
	// Output for application log
	ApplicationLogOut io.Writer
}

Config is configurations for logz

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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