...

Source file src/github.com/sagikazarmark/slog-shim/attr_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  	"time"
    11  
    12  	"golang.org/x/exp/slog"
    13  )
    14  
    15  // An Attr is a key-value pair.
    16  type Attr = slog.Attr
    17  
    18  // String returns an Attr for a string value.
    19  func String(key, value string) Attr {
    20  	return slog.String(key, value)
    21  }
    22  
    23  // Int64 returns an Attr for an int64.
    24  func Int64(key string, value int64) Attr {
    25  	return slog.Int64(key, value)
    26  }
    27  
    28  // Int converts an int to an int64 and returns
    29  // an Attr with that value.
    30  func Int(key string, value int) Attr {
    31  	return slog.Int(key, value)
    32  }
    33  
    34  // Uint64 returns an Attr for a uint64.
    35  func Uint64(key string, v uint64) Attr {
    36  	return slog.Uint64(key, v)
    37  }
    38  
    39  // Float64 returns an Attr for a floating-point number.
    40  func Float64(key string, v float64) Attr {
    41  	return slog.Float64(key, v)
    42  }
    43  
    44  // Bool returns an Attr for a bool.
    45  func Bool(key string, v bool) Attr {
    46  	return slog.Bool(key, v)
    47  }
    48  
    49  // Time returns an Attr for a time.Time.
    50  // It discards the monotonic portion.
    51  func Time(key string, v time.Time) Attr {
    52  	return slog.Time(key, v)
    53  }
    54  
    55  // Duration returns an Attr for a time.Duration.
    56  func Duration(key string, v time.Duration) Attr {
    57  	return slog.Duration(key, v)
    58  }
    59  
    60  // Group returns an Attr for a Group Value.
    61  // The first argument is the key; the remaining arguments
    62  // are converted to Attrs as in [Logger.Log].
    63  //
    64  // Use Group to collect several key-value pairs under a single
    65  // key on a log line, or as the result of LogValue
    66  // in order to log a single value as multiple Attrs.
    67  func Group(key string, args ...any) Attr {
    68  	return slog.Group(key, args...)
    69  }
    70  
    71  // Any returns an Attr for the supplied value.
    72  // See [Value.AnyValue] for how values are treated.
    73  func Any(key string, value any) Attr {
    74  	return slog.Any(key, value)
    75  }
    76  

View as plain text