logging

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Copyright 2023, DASH-Industry Forum. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE.md file.

Copyright 2023, DASH-Industry Forum. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE.md file.

Index

Constants

View Source
const (
	LogText    string = "text"
	LogJSON    string = "json"
	LogPretty  string = "pretty"
	LogDiscard string = "discard"
)

Different types of logging

Variables

LogFormats returns the allowed log formats.

View Source
var LogLevels = []string{"DEBUG", "INFO", "WARN", "ERROR"}

LogLevels returns the allowed log levels.

View Source
var LogRoutes = [2]Route{
	{"GET", "/loglevel", LogLevelGet},
	{"POST", "/loglevel", LogLevelSet},
}

Functions

func GetRequestID

func GetRequestID(r *http.Request) string

GetRequestID returns the request ID.

func InitSlog added in v1.0.0

func InitSlog(level string, logFormat string) error

InitSlog initializes the global slog logger.

level and logLevel determine where the logs go and what format is used.

func LogLevel added in v1.0.0

func LogLevel() string

LogLevel returns the current log level.

func LogLevelGet

func LogLevelGet(w http.ResponseWriter, r *http.Request)

LogLevelGet handles loglevel GET request

func LogLevelSet

func LogLevelSet(w http.ResponseWriter, r *http.Request)

LogLevelSet sets the loglevel from a posted form Can be triggered like curl -F level=debug <server>/loglevel

func SetLogLevel

func SetLogLevel(level string) error

SetLogLevel sets the global log level

func SlogMiddleWare added in v1.0.0

func SlogMiddleWare(l *slog.Logger) func(next http.Handler) http.Handler

SlogMiddleWare logs access and converts panic to stack traces.

func SubLoggerWithRequestID

func SubLoggerWithRequestID(l *slog.Logger, r *http.Request) *slog.Logger

SubLoggerWithRequestID creates a new sub-logger with request_id field.

Types

type Route

type Route struct {
	Method  string
	Path    string
	Handler http.HandlerFunc
}

Jump to

Keyboard shortcuts

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