log

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: May 30, 2023 License: Apache-2.0 Imports: 5 Imported by: 7

README

Log

Usage
package main

import (
	"context"
	"errors"
	"fmt"

	"github.com/infiniteloopcloud/log"
)

const (
	CorrelationID log.ContextField = "correlation_id"
)

func main() {
	// Set this globally
	log.SetLevel(log.LevelToUint())
	log.SetLoggableFields([]fmt.Stringer{CorrelationID})
	 
	ctx := context.Background()
	ctx = context.WithValue(ctx, CorrelationID, "123456")
	log.Error(ctx, errors.New(""), "")
	log.Errorf(ctx, errors.New(""), "test: %s", "test")
	log.Warn(ctx, "")
	log.Info(ctx, "")
	log.Debug(ctx, "")
	// etc...
}

Documentation

Index

Constants

View Source
const (
	ErrorLevelString = "error"
	WarnLevelString  = "warn"
	InfoLevelString  = "info"
	DebugLevelString = "debug"
)
View Source
const (
	ErrorLevel uint8 = iota
	WarnLevel
	InfoLevel
	TraceLevel
	DebugLevel
)

Variables

View Source
var LevelEnvironmentVariable = "LOG_LEVEL"

LevelEnvironmentVariable get the level of logging

Functions

func AppendLoggableFields added in v0.1.2

func AppendLoggableFields(l fmt.Stringer)

func Debug

func Debug(ctx context.Context, msg string)

func Debugf

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

func Error

func Error(ctx context.Context, err error, msg string)

func Errorf

func Errorf(ctx context.Context, err error, format string, args ...interface{})

func GetLoggableFields added in v0.1.2

func GetLoggableFields() []fmt.Stringer

func Info

func Info(ctx context.Context, msg string)

func Infof

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

func LevelToUint

func LevelToUint() uint8

func Parse added in v0.1.4

func Parse(ctx context.Context, scopeLevel string, msg string, err error, fields ...Field) string

func PreHookSetLogLevel added in v0.1.3

func PreHookSetLogLevel(_ context.Context)

func SetLevel

func SetLevel(l uint8)

func SetLevelEnvironmentVariable added in v0.1.1

func SetLevelEnvironmentVariable(l string)

func SetLoggableFields

func SetLoggableFields(custom []fmt.Stringer)

func Trace

func Trace(ctx context.Context, msg string)

func Warn

func Warn(ctx context.Context, msg string)

func Warnf

func Warnf(ctx context.Context, format string, args ...interface{})

Types

type ContextField

type ContextField string
const (
	TracingTime   ContextField = "tracing_time"
	UserID        ContextField = "user_id"
	ClientHost    ContextField = "client_host"
	CorrelationID ContextField = "correlation_id"
	HTTPPath      ContextField = "http_path"
)

func (ContextField) String

func (c ContextField) String() string

type Field

type Field struct {
	Key   string
	Value string
}

Jump to

Keyboard shortcuts

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