MCPcopy
hub / github.com/rs/zerolog / ExampleContext_IPPrefix

Function ExampleContext_IPPrefix

binary_test.go:618–633  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

616 // Output: {"foo":"bar","v4":"192.168.0.1","v6":"2001:db8:85a3::8a2e:370:7334","message":"hello world"}
617}
618func ExampleContext_IPPrefix() {
619 pfxV4 := net.IPNet{IP: net.IP{192, 168, 0, 100}, Mask: net.CIDRMask(24, 32)}
620 pfxV6 := net.IPNet{IP: net.IP{0x20, 0x01, 0x0d, 0xb8, 0x85, 0xa3, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x2e, 0x03, 0x70, 0x73, 0x00}, Mask: net.CIDRMask(64, 128)}
621
622 dst := bytes.Buffer{}
623 log := New(&dst).With().
624 Str("foo", "bar").
625 IPPrefix("v4", pfxV4).
626 IPPrefix("v6", pfxV6).
627 Logger()
628
629 log.Log().Msg("hello world")
630
631 fmt.Println(decodeIfBinaryToString(dst.Bytes()))
632 // Output: {"foo":"bar","v4":"192.168.0.100/24","v6":"2001:db8:85a3::8a2e:370:7300/64","message":"hello world"}
633}
634func ExampleContext_MACAddr() {
635 mac := net.HardwareAddr{0x12, 0x34, 0x56, 0x78, 0x90, 0xab}
636

Callers

nothing calls this directly

Calls 10

NewFunction · 0.85
LoggerMethod · 0.80
WithMethod · 0.80
MsgMethod · 0.80
PrintlnMethod · 0.80
decodeIfBinaryToStringFunction · 0.70
LogMethod · 0.65
IPPrefixMethod · 0.45
StrMethod · 0.45
BytesMethod · 0.45

Tested by

no test coverage detected