X7ROOT File Manager
Current Path:
/opt/golang/1.22.0/src/log/slog
opt
/
golang
/
1.22.0
/
src
/
log
/
slog
/
📁
..
📄
attr.go
(2.49 KB)
📄
attr_test.go
(891 B)
📄
doc.go
(12.13 KB)
📄
example_custom_levels_test.go
(2.99 KB)
📄
example_level_handler_test.go
(2.18 KB)
📄
example_log_level_test.go
(1.85 KB)
📄
example_logvaluer_group_test.go
(825 B)
📄
example_logvaluer_secret_test.go
(906 B)
📄
example_test.go
(857 B)
📄
example_wrap_test.go
(1.34 KB)
📄
handler.go
(17.48 KB)
📄
handler_test.go
(19.61 KB)
📁
internal
📄
json_handler.go
(8.05 KB)
📄
json_handler_test.go
(6.48 KB)
📄
level.go
(5.64 KB)
📄
level_test.go
(3.75 KB)
📄
logger.go
(10.22 KB)
📄
logger_test.go
(19.48 KB)
📄
record.go
(5.98 KB)
📄
record_test.go
(4 KB)
📄
slogtest_test.go
(2.61 KB)
📄
text_handler.go
(4.71 KB)
📄
text_handler_test.go
(3.81 KB)
📄
value.go
(12.8 KB)
📄
value_access_benchmark_test.go
(4.29 KB)
📄
value_test.go
(6.08 KB)
Editing: attr.go
// Copyright 2022 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package slog import ( "fmt" "time" ) // An Attr is a key-value pair. type Attr struct { Key string Value Value } // String returns an Attr for a string value. func String(key, value string) Attr { return Attr{key, StringValue(value)} } // Int64 returns an Attr for an int64. func Int64(key string, value int64) Attr { return Attr{key, Int64Value(value)} } // Int converts an int to an int64 and returns // an Attr with that value. func Int(key string, value int) Attr { return Int64(key, int64(value)) } // Uint64 returns an Attr for a uint64. func Uint64(key string, v uint64) Attr { return Attr{key, Uint64Value(v)} } // Float64 returns an Attr for a floating-point number. func Float64(key string, v float64) Attr { return Attr{key, Float64Value(v)} } // Bool returns an Attr for a bool. func Bool(key string, v bool) Attr { return Attr{key, BoolValue(v)} } // Time returns an Attr for a [time.Time]. // It discards the monotonic portion. func Time(key string, v time.Time) Attr { return Attr{key, TimeValue(v)} } // Duration returns an Attr for a [time.Duration]. func Duration(key string, v time.Duration) Attr { return Attr{key, DurationValue(v)} } // Group returns an Attr for a Group [Value]. // The first argument is the key; the remaining arguments // are converted to Attrs as in [Logger.Log]. // // Use Group to collect several key-value pairs under a single // key on a log line, or as the result of LogValue // in order to log a single value as multiple Attrs. func Group(key string, args ...any) Attr { return Attr{key, GroupValue(argsToAttrSlice(args)...)} } func argsToAttrSlice(args []any) []Attr { var ( attr Attr attrs []Attr ) for len(args) > 0 { attr, args = argsToAttr(args) attrs = append(attrs, attr) } return attrs } // Any returns an Attr for the supplied value. // See [AnyValue] for how values are treated. func Any(key string, value any) Attr { return Attr{key, AnyValue(value)} } // Equal reports whether a and b have equal keys and values. func (a Attr) Equal(b Attr) bool { return a.Key == b.Key && a.Value.Equal(b.Value) } func (a Attr) String() string { return fmt.Sprintf("%s=%s", a.Key, a.Value) } // isEmpty reports whether a has an empty key and a nil value. // That can be written as Attr{} or Any("", nil). func (a Attr) isEmpty() bool { return a.Key == "" && a.Value.num == 0 && a.Value.any == nil }
Upload File
Create Folder