aelog

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2019 License: MIT Imports: 7 Imported by: 0

README

App Engine Logger

Build Status Go Report Card GoDoc

This is Logger for App Engine 2nd Generation. App Engine Plain Logger only supports structured logging (ref: https://cloud.google.com/logging/docs/structured-logging), so this does not support logging experience which proprietary App Engine API provided.

How to use

mux := http.NewServeMux()
mux.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
    ctx := request.Context()
    aelog.Infof(ctx, "some log message")
})

h := middleware.AELogger("ServeHTTP")(mux)

if err := http.ListenAndServe(fmt.Sprintf(":%s", port), h); err != nil {
    panic(err)
}

License

MIT

Documentation

Overview

Package aelog provides the structured log of an application's logs from within an App Engine application.

Example:

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

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Criticalf

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

Criticalf is like Debugf, but the severity is critical level.

Example
ctx := trace.NewContext(context.Background(), nil)
Criticalf(ctx, "Criticalf: %s", "Sample Text")
Output:

{"severity":"CRITICAL","message":"Criticalf: Sample Text","logging.googleapis.com/trace":"projects//traces/00000000000000000000000000000000","logging.googleapis.com/spanId":"0000000000000000"}

func Debugf

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

Debugf formats its arguments according to the format, analogous to fmt.Printf, and records the text as log message at debug level. The log message will be associated with the platform request linked with the context.

Example
ctx := trace.NewContext(context.Background(), nil)
Debugf(ctx, "Debugf: %s", "Sample Text")
Output:

{"severity":"DEBUG","message":"Debugf: Sample Text","logging.googleapis.com/trace":"projects//traces/00000000000000000000000000000000","logging.googleapis.com/spanId":"0000000000000000"}

func Errorf

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

Errorf is like Debugf, but the severity is error level.

Example
ctx := trace.NewContext(context.Background(), nil)
Errorf(ctx, "Errorf: %s", "Sample Text")
Output:

{"severity":"ERROR","message":"Errorf: Sample Text","logging.googleapis.com/trace":"projects//traces/00000000000000000000000000000000","logging.googleapis.com/spanId":"0000000000000000"}

func Infof

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

Infof is like Debugf, but the severity is info level.

Example
ctx := trace.NewContext(context.Background(), nil)
Infof(ctx, "Infof: %s", "Sample Text")
Output:

{"severity":"INFO","message":"Infof: Sample Text","logging.googleapis.com/trace":"projects//traces/00000000000000000000000000000000","logging.googleapis.com/spanId":"0000000000000000"}

func OutputJSON

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

OutputJSON fills the fields required with the structured log described in https://cloud.google.com/logging/docs/agent/configuration#special-fields and outputs the log in json format.

func OutputText

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

OutputText outputs log using standard log package.

func SetOutput

func SetOutput(f func(context.Context, string, string, ...interface{}))

SetOutput allows to set the log output format. The default log setting is json format.

func Warningf

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

Warningf is like Debugf, but the severity is warning level.

Example
ctx := trace.NewContext(context.Background(), nil)
Warningf(ctx, "Warningf: %s", "Sample Text")
Output:

{"severity":"WARNING","message":"Warningf: Sample Text","logging.googleapis.com/trace":"projects//traces/00000000000000000000000000000000","logging.googleapis.com/spanId":"0000000000000000"}

Types

This section is empty.

Directories

Path Synopsis
internal
Package middleware provides the http.Handler with spancontext.
Package middleware provides the http.Handler with spancontext.

Jump to

Keyboard shortcuts

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