...

Source file src/github.com/sagikazarmark/slog-shim/level_120.go

Documentation: github.com/sagikazarmark/slog-shim

     1  // Copyright 2022 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build !go1.21
     6  
     7  package slog
     8  
     9  import (
    10  	"golang.org/x/exp/slog"
    11  )
    12  
    13  // A Level is the importance or severity of a log event.
    14  // The higher the level, the more important or severe the event.
    15  type Level = slog.Level
    16  
    17  // Level numbers are inherently arbitrary,
    18  // but we picked them to satisfy three constraints.
    19  // Any system can map them to another numbering scheme if it wishes.
    20  //
    21  // First, we wanted the default level to be Info, Since Levels are ints, Info is
    22  // the default value for int, zero.
    23  //
    24  // Second, we wanted to make it easy to use levels to specify logger verbosity.
    25  // Since a larger level means a more severe event, a logger that accepts events
    26  // with smaller (or more negative) level means a more verbose logger. Logger
    27  // verbosity is thus the negation of event severity, and the default verbosity
    28  // of 0 accepts all events at least as severe as INFO.
    29  //
    30  // Third, we wanted some room between levels to accommodate schemes with named
    31  // levels between ours. For example, Google Cloud Logging defines a Notice level
    32  // between Info and Warn. Since there are only a few of these intermediate
    33  // levels, the gap between the numbers need not be large. Our gap of 4 matches
    34  // OpenTelemetry's mapping. Subtracting 9 from an OpenTelemetry level in the
    35  // DEBUG, INFO, WARN and ERROR ranges converts it to the corresponding slog
    36  // Level range. OpenTelemetry also has the names TRACE and FATAL, which slog
    37  // does not. But those OpenTelemetry levels can still be represented as slog
    38  // Levels by using the appropriate integers.
    39  //
    40  // Names for common levels.
    41  const (
    42  	LevelDebug Level = slog.LevelDebug
    43  	LevelInfo  Level = slog.LevelInfo
    44  	LevelWarn  Level = slog.LevelWarn
    45  	LevelError Level = slog.LevelError
    46  )
    47  
    48  // A LevelVar is a Level variable, to allow a Handler level to change
    49  // dynamically.
    50  // It implements Leveler as well as a Set method,
    51  // and it is safe for use by multiple goroutines.
    52  // The zero LevelVar corresponds to LevelInfo.
    53  type LevelVar = slog.LevelVar
    54  
    55  // A Leveler provides a Level value.
    56  //
    57  // As Level itself implements Leveler, clients typically supply
    58  // a Level value wherever a Leveler is needed, such as in HandlerOptions.
    59  // Clients who need to vary the level dynamically can provide a more complex
    60  // Leveler implementation such as *LevelVar.
    61  type Leveler = slog.Leveler
    62  

View as plain text