Skip to content

Latest commit

 

History

History
70 lines (48 loc) · 1.68 KB

README.md

File metadata and controls

70 lines (48 loc) · 1.68 KB

levels - log/slog Logging Levels and Settings

Documentation

Official godoc documentation (with examples) can be found at the Package Registry.

Usage

Add Package Dependency
go get -u github.com/x-ethr/levels
Import & Implement

main.go

package main

import (
    "fmt"

    "github.com/x-ethr/levels"
)

func main() {
    ctx, level := context.Background(), slog.LevelInfo

    // Log all environment variables
    environment.Log(ctx, level)

    // Log only specific environment variable(s)
    environment.Log(ctx, level, func(o *environment.Options) {
        o.Variables = []string{
            "PATH",
        }
    })

    // Log only specific environment variable(s), and warn if one of the specified variable(s) was set to an empty string
    environment.Log(ctx, level, func(o *environment.Options) {
        _ = os.Setenv("TEST", "") // --> for example purposes

        o.Variables = []string{
            "TEST",
        }

        o.Warnings.Empty = true
    })

    // Log only specific environment variable(s), and warn if one of the specified variable(s) wasn't found
    environment.Log(ctx, level, func(o *environment.Options) {
        _ = os.Unsetenv("TEST") // --> for example purposes

        o.Variables = []string{
            "TEST",
        }

        o.Warnings.Missing = true
    })
}

Contributions

See the Contributing Guide for additional details on getting started.