Giter Club home page Giter Club logo

ello-golang-ctx's Introduction

Ello Go Context packages

Common packages for handling context.

logctx

The logctx package supports logger-specific context being added, read and modified within context.Context. This makes it easier to pass values such as a request id throughout the application and include it within all logs.

logctx.Get(context.Context) *LogCtx

Gets the current LogCtx from context.Context. LogCtx is a slice of logctx.Field. If LogCtx is not found, a new LogCtx struct is created.

logctx.Add(context.Context, ...Field) context.Context

Adds fields to the LogCtx within context.Context, and returns a new context.Context. If LogCtx is not found, a new LogCtx struct is created.

logctx.Field

logctx.Field represents a key-value pair. There are helpers to create fields of different types, such as logctx.String(key, val string) Field and logctx.Int(key string, val int) Field.

logctx.Zap(context.Context, ...zap.Field) []zap.Field

Extract LogCtx from context.Context and convert into a slice of zap.Field to attach to a Zap log entry.

Example

// Example Zap logger
log := zap.NewExample()

// Example context
ctx := context.TODO()

// Add key-value pair to context
ctx = logctx.Add(ctx, logctx.Int("example_one", 123))

// Log with log context
log.Info("message", logctx.Zap(ctx)...)

// Log with log context and additional context
log.Info("message", logctx.Zap(ctx, logctx.Bool("example_two", true))...)

ello-golang-ctx's People

Contributors

daverichards00 avatar daverichards-ellogroup avatar

Watchers

Piotr Kaniuk avatar Symeon Manis avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.