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

Function ExampleContext_IPAddr

binary_test.go:602–617  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

600}
601
602func ExampleContext_IPAddr() {
603 ipV4 := net.IP{192, 168, 0, 1}
604 ipV6 := net.IP{0x20, 0x01, 0x0d, 0xb8, 0x85, 0xa3, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x2e, 0x03, 0x70, 0x73, 0x34}
605
606 dst := bytes.Buffer{}
607 log := New(&dst).With().
608 Str("foo", "bar").
609 IPAddr("v4", ipV4).
610 IPAddr("v6", ipV6).
611 Logger()
612
613 log.Log().Msg("hello world")
614
615 fmt.Println(decodeIfBinaryToString(dst.Bytes()))
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)}

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
IPAddrMethod · 0.45
StrMethod · 0.45
BytesMethod · 0.45

Tested by

no test coverage detected