How to use Foo method of log Package

Best Mock code snippet using log.Foo

binary_test.go

Source:binary_test.go Github

copy

Full Screen

1// +build binary_log2package zerolog3import (4 "bytes"5 "errors"6 "fmt"7 // "io/ioutil"8 stdlog "log"9 "time"10)11func ExampleBinaryNew() {12 dst := bytes.Buffer{}13 log := New(&dst)14 log.Info().Msg("hello world")15 fmt.Println(decodeIfBinaryToString(dst.Bytes()))16 // Output: {"level":"info","message":"hello world"}17}18func ExampleLogger_With() {19 dst := bytes.Buffer{}20 log := New(&dst).21 With().22 Str("foo", "bar").23 Logger()24 log.Info().Msg("hello world")25 fmt.Println(decodeIfBinaryToString(dst.Bytes()))26 // Output: {"level":"info","foo":"bar","message":"hello world"}27}28func ExampleLogger_Level() {29 dst := bytes.Buffer{}30 log := New(&dst).Level(WarnLevel)31 log.Info().Msg("filtered out message")32 log.Error().Msg("kept message")33 fmt.Println(decodeIfBinaryToString(dst.Bytes()))34 // Output: {"level":"error","message":"kept message"}35}36func ExampleLogger_Sample() {37 dst := bytes.Buffer{}38 log := New(&dst).Sample(&BasicSampler{N: 2})39 log.Info().Msg("message 1")40 log.Info().Msg("message 2")41 log.Info().Msg("message 3")42 log.Info().Msg("message 4")43 fmt.Println(decodeIfBinaryToString(dst.Bytes()))44 // Output: {"level":"info","message":"message 1"}45 // {"level":"info","message":"message 3"}46}47type LevelNameHook1 struct{}48func (h LevelNameHook1) Run(e *Event, l Level, msg string) {49 if l != NoLevel {50 e.Str("level_name", l.String())51 } else {52 e.Str("level_name", "NoLevel")53 }54}55type MessageHook string56func (h MessageHook) Run(e *Event, l Level, msg string) {57 e.Str("the_message", msg)58}59func ExampleLogger_Hook() {60 var levelNameHook LevelNameHook161 var messageHook MessageHook = "The message"62 dst := bytes.Buffer{}63 log := New(&dst).Hook(levelNameHook).Hook(messageHook)64 log.Info().Msg("hello world")65 fmt.Println(decodeIfBinaryToString(dst.Bytes()))66 // Output: {"level":"info","level_name":"info","the_message":"hello world","message":"hello world"}67}68func ExampleLogger_Print() {69 dst := bytes.Buffer{}70 log := New(&dst)71 log.Print("hello world")72 fmt.Println(decodeIfBinaryToString(dst.Bytes()))73 // Output: {"level":"debug","message":"hello world"}74}75func ExampleLogger_Printf() {76 dst := bytes.Buffer{}77 log := New(&dst)78 log.Printf("hello %s", "world")79 fmt.Println(decodeIfBinaryToString(dst.Bytes()))80 // Output: {"level":"debug","message":"hello world"}81}82func ExampleLogger_Debug() {83 dst := bytes.Buffer{}84 log := New(&dst)85 log.Debug().86 Str("foo", "bar").87 Int("n", 123).88 Msg("hello world")89 fmt.Println(decodeIfBinaryToString(dst.Bytes()))90 // Output: {"level":"debug","foo":"bar","n":123,"message":"hello world"}91}92func ExampleLogger_Info() {93 dst := bytes.Buffer{}94 log := New(&dst)95 log.Info().96 Str("foo", "bar").97 Int("n", 123).98 Msg("hello world")99 fmt.Println(decodeIfBinaryToString(dst.Bytes()))100 // Output: {"level":"info","foo":"bar","n":123,"message":"hello world"}101}102func ExampleLogger_Warn() {103 dst := bytes.Buffer{}104 log := New(&dst)105 log.Warn().106 Str("foo", "bar").107 Msg("a warning message")108 fmt.Println(decodeIfBinaryToString(dst.Bytes()))109 // Output: {"level":"warn","foo":"bar","message":"a warning message"}110}111func ExampleLogger_Error() {112 dst := bytes.Buffer{}113 log := New(&dst)114 log.Error().115 Err(errors.New("some error")).116 Msg("error doing something")117 fmt.Println(decodeIfBinaryToString(dst.Bytes()))118 // Output: {"level":"error","error":"some error","message":"error doing something"}119}120func ExampleLogger_WithLevel() {121 dst := bytes.Buffer{}122 log := New(&dst)123 log.WithLevel(InfoLevel).124 Msg("hello world")125 fmt.Println(decodeIfBinaryToString(dst.Bytes()))126 // Output: {"level":"info","message":"hello world"}127}128func ExampleLogger_Write() {129 dst := bytes.Buffer{}130 log := New(&dst).With().131 Str("foo", "bar").132 Logger()133 stdlog.SetFlags(0)134 stdlog.SetOutput(log)135 stdlog.Print("hello world")136 fmt.Println(decodeIfBinaryToString(dst.Bytes()))137 // Output: {"foo":"bar","message":"hello world"}138}139func ExampleLogger_Log() {140 dst := bytes.Buffer{}141 log := New(&dst)142 log.Log().143 Str("foo", "bar").144 Str("bar", "baz").145 Msg("")146 fmt.Println(decodeIfBinaryToString(dst.Bytes()))147 // Output: {"foo":"bar","bar":"baz"}148}149func ExampleEvent_Dict() {150 dst := bytes.Buffer{}151 log := New(&dst)152 log.Log().153 Str("foo", "bar").154 Dict("dict", Dict().155 Str("bar", "baz").156 Int("n", 1),157 ).158 Msg("hello world")159 fmt.Println(decodeIfBinaryToString(dst.Bytes()))160 // Output: {"foo":"bar","dict":{"bar":"baz","n":1},"message":"hello world"}161}162type User struct {163 Name string164 Age int165 Created time.Time166}167func (u User) MarshalZerologObject(e *Event) {168 e.Str("name", u.Name).169 Int("age", u.Age).170 Time("created", u.Created)171}172type Users []User173func (uu Users) MarshalZerologArray(a *Array) {174 for _, u := range uu {175 a.Object(u)176 }177}178func ExampleEvent_Array() {179 dst := bytes.Buffer{}180 log := New(&dst)181 log.Log().182 Str("foo", "bar").183 Array("array", Arr().184 Str("baz").185 Int(1),186 ).187 Msg("hello world")188 fmt.Println(decodeIfBinaryToString(dst.Bytes()))189 // Output: {"foo":"bar","array":["baz",1],"message":"hello world"}190}191func ExampleEvent_Array_object() {192 dst := bytes.Buffer{}193 log := New(&dst)194 // Users implements LogArrayMarshaler195 u := Users{196 User{"John", 35, time.Time{}},197 User{"Bob", 55, time.Time{}},198 }199 log.Log().200 Str("foo", "bar").201 Array("users", u).202 Msg("hello world")203 fmt.Println(decodeIfBinaryToString(dst.Bytes()))204 // Output: {"foo":"bar","users":[{"name":"John","age":35,"created":"0001-01-01T00:00:00Z"},{"name":"Bob","age":55,"created":"0001-01-01T00:00:00Z"}],"message":"hello world"}205}206func ExampleEvent_Object() {207 dst := bytes.Buffer{}208 log := New(&dst)209 // User implements LogObjectMarshaler210 u := User{"John", 35, time.Time{}}211 log.Log().212 Str("foo", "bar").213 Object("user", u).214 Msg("hello world")215 fmt.Println(decodeIfBinaryToString(dst.Bytes()))216 // Output: {"foo":"bar","user":{"name":"John","age":35,"created":"0001-01-01T00:00:00Z"},"message":"hello world"}217}218func ExampleEvent_EmbedObject() {219 price := Price{val: 6449, prec: 2, unit: "$"}220 dst := bytes.Buffer{}221 log := New(&dst)222 log.Log().223 Str("foo", "bar").224 EmbedObject(price).225 Msg("hello world")226 fmt.Println(decodeIfBinaryToString(dst.Bytes()))227 // Output: {"foo":"bar","price":"$64.49","message":"hello world"}228}229func ExampleEvent_Interface() {230 dst := bytes.Buffer{}231 log := New(&dst)232 obj := struct {233 Name string `json:"name"`234 }{235 Name: "john",236 }237 log.Log().238 Str("foo", "bar").239 Interface("obj", obj).240 Msg("hello world")241 fmt.Println(decodeIfBinaryToString(dst.Bytes()))242 // Output: {"foo":"bar","obj":{"name":"john"},"message":"hello world"}243}244func ExampleEvent_Dur() {245 d := time.Duration(10 * time.Second)246 dst := bytes.Buffer{}247 log := New(&dst)248 log.Log().249 Str("foo", "bar").250 Dur("dur", d).251 Msg("hello world")252 fmt.Println(decodeIfBinaryToString(dst.Bytes()))253 // Output: {"foo":"bar","dur":10000,"message":"hello world"}254}255func ExampleEvent_Durs() {256 d := []time.Duration{257 time.Duration(10 * time.Second),258 time.Duration(20 * time.Second),259 }260 dst := bytes.Buffer{}261 log := New(&dst)262 log.Log().263 Str("foo", "bar").264 Durs("durs", d).265 Msg("hello world")266 fmt.Println(decodeIfBinaryToString(dst.Bytes()))267 // Output: {"foo":"bar","durs":[10000,20000],"message":"hello world"}268}269func ExampleContext_Dict() {270 dst := bytes.Buffer{}271 log := New(&dst).With().272 Str("foo", "bar").273 Dict("dict", Dict().274 Str("bar", "baz").275 Int("n", 1),276 ).Logger()277 log.Log().Msg("hello world")278 fmt.Println(decodeIfBinaryToString(dst.Bytes()))279 // Output: {"foo":"bar","dict":{"bar":"baz","n":1},"message":"hello world"}280}281func ExampleContext_Array() {282 dst := bytes.Buffer{}283 log := New(&dst).With().284 Str("foo", "bar").285 Array("array", Arr().286 Str("baz").287 Int(1),288 ).Logger()289 log.Log().Msg("hello world")290 fmt.Println(decodeIfBinaryToString(dst.Bytes()))291 // Output: {"foo":"bar","array":["baz",1],"message":"hello world"}292}293func ExampleContext_Array_object() {294 // Users implements LogArrayMarshaler295 u := Users{296 User{"John", 35, time.Time{}},297 User{"Bob", 55, time.Time{}},298 }299 dst := bytes.Buffer{}300 log := New(&dst).With().301 Str("foo", "bar").302 Array("users", u).303 Logger()304 log.Log().Msg("hello world")305 fmt.Println(decodeIfBinaryToString(dst.Bytes()))306 // Output: {"foo":"bar","users":[{"name":"John","age":35,"created":"0001-01-01T00:00:00Z"},{"name":"Bob","age":55,"created":"0001-01-01T00:00:00Z"}],"message":"hello world"}307}308type Price struct {309 val uint64310 prec int311 unit string312}313func (p Price) MarshalZerologObject(e *Event) {314 denom := uint64(1)315 for i := 0; i < p.prec; i++ {316 denom *= 10317 }318 result := []byte(p.unit)319 result = append(result, fmt.Sprintf("%d.%d", p.val/denom, p.val%denom)...)320 e.Str("price", string(result))321}322func ExampleContext_EmbedObject() {323 price := Price{val: 6449, prec: 2, unit: "$"}324 dst := bytes.Buffer{}325 log := New(&dst).With().326 Str("foo", "bar").327 EmbedObject(price).328 Logger()329 log.Log().Msg("hello world")330 fmt.Println(decodeIfBinaryToString(dst.Bytes()))331 // Output: {"foo":"bar","price":"$64.49","message":"hello world"}332}333func ExampleContext_Object() {334 // User implements LogObjectMarshaler335 u := User{"John", 35, time.Time{}}336 dst := bytes.Buffer{}337 log := New(&dst).With().338 Str("foo", "bar").339 Object("user", u).340 Logger()341 log.Log().Msg("hello world")342 fmt.Println(decodeIfBinaryToString(dst.Bytes()))343 // Output: {"foo":"bar","user":{"name":"John","age":35,"created":"0001-01-01T00:00:00Z"},"message":"hello world"}344}345func ExampleContext_Interface() {346 obj := struct {347 Name string `json:"name"`348 }{349 Name: "john",350 }351 dst := bytes.Buffer{}352 log := New(&dst).With().353 Str("foo", "bar").354 Interface("obj", obj).355 Logger()356 log.Log().Msg("hello world")357 fmt.Println(decodeIfBinaryToString(dst.Bytes()))358 // Output: {"foo":"bar","obj":{"name":"john"},"message":"hello world"}359}360func ExampleContext_Dur() {361 d := time.Duration(10 * time.Second)362 dst := bytes.Buffer{}363 log := New(&dst).With().364 Str("foo", "bar").365 Dur("dur", d).366 Logger()367 log.Log().Msg("hello world")368 fmt.Println(decodeIfBinaryToString(dst.Bytes()))369 // Output: {"foo":"bar","dur":10000,"message":"hello world"}370}371func ExampleContext_Durs() {372 d := []time.Duration{373 time.Duration(10 * time.Second),374 time.Duration(20 * time.Second),375 }376 dst := bytes.Buffer{}377 log := New(&dst).With().378 Str("foo", "bar").379 Durs("durs", d).380 Logger()381 log.Log().Msg("hello world")382 fmt.Println(decodeIfBinaryToString(dst.Bytes()))383 // Output: {"foo":"bar","durs":[10000,20000],"message":"hello world"}384}...

Full Screen

Full Screen

log_example_test.go

Source:log_example_test.go Github

copy

Full Screen

1// +build !binary_log2package zerolog_test3import (4 "errors"5 "fmt"6 stdlog "log"7 "net"8 "os"9 "time"10 "github.com/rs/zerolog"11)12func ExampleNew() {13 log := zerolog.New(os.Stdout)14 log.Info().Msg("hello world")15 // Output: {"level":"info","message":"hello world"}16}17func ExampleLogger_With() {18 log := zerolog.New(os.Stdout).19 With().20 Str("foo", "bar").21 Logger()22 log.Info().Msg("hello world")23 // Output: {"level":"info","foo":"bar","message":"hello world"}24}25func ExampleLogger_Level() {26 log := zerolog.New(os.Stdout).Level(zerolog.WarnLevel)27 log.Info().Msg("filtered out message")28 log.Error().Msg("kept message")29 // Output: {"level":"error","message":"kept message"}30}31func ExampleLogger_Sample() {32 log := zerolog.New(os.Stdout).Sample(&zerolog.BasicSampler{N: 2})33 log.Info().Msg("message 1")34 log.Info().Msg("message 2")35 log.Info().Msg("message 3")36 log.Info().Msg("message 4")37 // Output: {"level":"info","message":"message 1"}38 // {"level":"info","message":"message 3"}39}40type LevelNameHook struct{}41func (h LevelNameHook) Run(e *zerolog.Event, l zerolog.Level, msg string) {42 if l != zerolog.NoLevel {43 e.Str("level_name", l.String())44 } else {45 e.Str("level_name", "NoLevel")46 }47}48type MessageHook string49func (h MessageHook) Run(e *zerolog.Event, l zerolog.Level, msg string) {50 e.Str("the_message", msg)51}52func ExampleLogger_Hook() {53 var levelNameHook LevelNameHook54 var messageHook MessageHook = "The message"55 log := zerolog.New(os.Stdout).Hook(levelNameHook).Hook(messageHook)56 log.Info().Msg("hello world")57 // Output: {"level":"info","level_name":"info","the_message":"hello world","message":"hello world"}58}59func ExampleLogger_Print() {60 log := zerolog.New(os.Stdout)61 log.Print("hello world")62 // Output: {"level":"debug","message":"hello world"}63}64func ExampleLogger_Printf() {65 log := zerolog.New(os.Stdout)66 log.Printf("hello %s", "world")67 // Output: {"level":"debug","message":"hello world"}68}69func ExampleLogger_Debug() {70 log := zerolog.New(os.Stdout)71 log.Debug().72 Str("foo", "bar").73 Int("n", 123).74 Msg("hello world")75 // Output: {"level":"debug","foo":"bar","n":123,"message":"hello world"}76}77func ExampleLogger_Info() {78 log := zerolog.New(os.Stdout)79 log.Info().80 Str("foo", "bar").81 Int("n", 123).82 Msg("hello world")83 // Output: {"level":"info","foo":"bar","n":123,"message":"hello world"}84}85func ExampleLogger_Warn() {86 log := zerolog.New(os.Stdout)87 log.Warn().88 Str("foo", "bar").89 Msg("a warning message")90 // Output: {"level":"warn","foo":"bar","message":"a warning message"}91}92func ExampleLogger_Error() {93 log := zerolog.New(os.Stdout)94 log.Error().95 Err(errors.New("some error")).96 Msg("error doing something")97 // Output: {"level":"error","error":"some error","message":"error doing something"}98}99func ExampleLogger_WithLevel() {100 log := zerolog.New(os.Stdout)101 log.WithLevel(zerolog.InfoLevel).102 Msg("hello world")103 // Output: {"level":"info","message":"hello world"}104}105func ExampleLogger_Write() {106 log := zerolog.New(os.Stdout).With().107 Str("foo", "bar").108 Logger()109 stdlog.SetFlags(0)110 stdlog.SetOutput(log)111 stdlog.Print("hello world")112 // Output: {"foo":"bar","message":"hello world"}113}114func ExampleLogger_Log() {115 log := zerolog.New(os.Stdout)116 log.Log().117 Str("foo", "bar").118 Str("bar", "baz").119 Msg("")120 // Output: {"foo":"bar","bar":"baz"}121}122func ExampleEvent_Dict() {123 log := zerolog.New(os.Stdout)124 log.Log().125 Str("foo", "bar").126 Dict("dict", zerolog.Dict().127 Str("bar", "baz").128 Int("n", 1),129 ).130 Msg("hello world")131 // Output: {"foo":"bar","dict":{"bar":"baz","n":1},"message":"hello world"}132}133type User struct {134 Name string135 Age int136 Created time.Time137}138func (u User) MarshalZerologObject(e *zerolog.Event) {139 e.Str("name", u.Name).140 Int("age", u.Age).141 Time("created", u.Created)142}143type Price struct {144 val uint64145 prec int146 unit string147}148func (p Price) MarshalZerologObject(e *zerolog.Event) {149 denom := uint64(1)150 for i := 0; i < p.prec; i++ {151 denom *= 10152 }153 result := []byte(p.unit)154 result = append(result, fmt.Sprintf("%d.%d", p.val/denom, p.val%denom)...)155 e.Str("price", string(result))156}157type Users []User158func (uu Users) MarshalZerologArray(a *zerolog.Array) {159 for _, u := range uu {160 a.Object(u)161 }162}163func ExampleEvent_Array() {164 log := zerolog.New(os.Stdout)165 log.Log().166 Str("foo", "bar").167 Array("array", zerolog.Arr().168 Str("baz").169 Int(1),170 ).171 Msg("hello world")172 // Output: {"foo":"bar","array":["baz",1],"message":"hello world"}173}174func ExampleEvent_Array_object() {175 log := zerolog.New(os.Stdout)176 // Users implements zerolog.LogArrayMarshaler177 u := Users{178 User{"John", 35, time.Time{}},179 User{"Bob", 55, time.Time{}},180 }181 log.Log().182 Str("foo", "bar").183 Array("users", u).184 Msg("hello world")185 // Output: {"foo":"bar","users":[{"name":"John","age":35,"created":"0001-01-01T00:00:00Z"},{"name":"Bob","age":55,"created":"0001-01-01T00:00:00Z"}],"message":"hello world"}186}187func ExampleEvent_Object() {188 log := zerolog.New(os.Stdout)189 // User implements zerolog.LogObjectMarshaler190 u := User{"John", 35, time.Time{}}191 log.Log().192 Str("foo", "bar").193 Object("user", u).194 Msg("hello world")195 // Output: {"foo":"bar","user":{"name":"John","age":35,"created":"0001-01-01T00:00:00Z"},"message":"hello world"}196}197func ExampleEvent_EmbedObject() {198 log := zerolog.New(os.Stdout)199 price := Price{val: 6449, prec: 2, unit: "$"}200 log.Log().201 Str("foo", "bar").202 EmbedObject(price).203 Msg("hello world")204 // Output: {"foo":"bar","price":"$64.49","message":"hello world"}205}206func ExampleEvent_Interface() {207 log := zerolog.New(os.Stdout)208 obj := struct {209 Name string `json:"name"`210 }{211 Name: "john",212 }213 log.Log().214 Str("foo", "bar").215 Interface("obj", obj).216 Msg("hello world")217 // Output: {"foo":"bar","obj":{"name":"john"},"message":"hello world"}218}219func ExampleEvent_Dur() {220 d := time.Duration(10 * time.Second)221 log := zerolog.New(os.Stdout)222 log.Log().223 Str("foo", "bar").224 Dur("dur", d).225 Msg("hello world")226 // Output: {"foo":"bar","dur":10000,"message":"hello world"}227}228func ExampleEvent_Durs() {229 d := []time.Duration{230 time.Duration(10 * time.Second),231 time.Duration(20 * time.Second),232 }233 log := zerolog.New(os.Stdout)234 log.Log().235 Str("foo", "bar").236 Durs("durs", d).237 Msg("hello world")238 // Output: {"foo":"bar","durs":[10000,20000],"message":"hello world"}239}240func ExampleContext_Dict() {241 log := zerolog.New(os.Stdout).With().242 Str("foo", "bar").243 Dict("dict", zerolog.Dict().244 Str("bar", "baz").245 Int("n", 1),246 ).Logger()247 log.Log().Msg("hello world")248 // Output: {"foo":"bar","dict":{"bar":"baz","n":1},"message":"hello world"}249}250func ExampleContext_Array() {251 log := zerolog.New(os.Stdout).With().252 Str("foo", "bar").253 Array("array", zerolog.Arr().254 Str("baz").255 Int(1),256 ).Logger()257 log.Log().Msg("hello world")258 // Output: {"foo":"bar","array":["baz",1],"message":"hello world"}259}260func ExampleContext_Array_object() {261 // Users implements zerolog.LogArrayMarshaler262 u := Users{263 User{"John", 35, time.Time{}},264 User{"Bob", 55, time.Time{}},265 }266 log := zerolog.New(os.Stdout).With().267 Str("foo", "bar").268 Array("users", u).269 Logger()270 log.Log().Msg("hello world")271 // Output: {"foo":"bar","users":[{"name":"John","age":35,"created":"0001-01-01T00:00:00Z"},{"name":"Bob","age":55,"created":"0001-01-01T00:00:00Z"}],"message":"hello world"}272}273func ExampleContext_Object() {274 // User implements zerolog.LogObjectMarshaler275 u := User{"John", 35, time.Time{}}276 log := zerolog.New(os.Stdout).With().277 Str("foo", "bar").278 Object("user", u).279 Logger()280 log.Log().Msg("hello world")281 // Output: {"foo":"bar","user":{"name":"John","age":35,"created":"0001-01-01T00:00:00Z"},"message":"hello world"}282}283func ExampleContext_EmbedObject() {284 price := Price{val: 6449, prec: 2, unit: "$"}285 log := zerolog.New(os.Stdout).With().286 Str("foo", "bar").287 EmbedObject(price).288 Logger()289 log.Log().Msg("hello world")290 // Output: {"foo":"bar","price":"$64.49","message":"hello world"}291}292func ExampleContext_Interface() {293 obj := struct {294 Name string `json:"name"`295 }{296 Name: "john",297 }298 log := zerolog.New(os.Stdout).With().299 Str("foo", "bar").300 Interface("obj", obj).301 Logger()302 log.Log().Msg("hello world")303 // Output: {"foo":"bar","obj":{"name":"john"},"message":"hello world"}304}305func ExampleContext_Dur() {306 d := time.Duration(10 * time.Second)307 log := zerolog.New(os.Stdout).With().308 Str("foo", "bar").309 Dur("dur", d).310 Logger()311 log.Log().Msg("hello world")312 // Output: {"foo":"bar","dur":10000,"message":"hello world"}313}314func ExampleContext_Durs() {315 d := []time.Duration{316 time.Duration(10 * time.Second),317 time.Duration(20 * time.Second),318 }319 log := zerolog.New(os.Stdout).With().320 Str("foo", "bar").321 Durs("durs", d).322 Logger()323 log.Log().Msg("hello world")324 // Output: {"foo":"bar","durs":[10000,20000],"message":"hello world"}325}326func ExampleContext_IPAddr() {327 hostIP := net.IP{192, 168, 0, 100}328 log := zerolog.New(os.Stdout).With().329 IPAddr("HostIP", hostIP).330 Logger()331 log.Log().Msg("hello world")332 // Output: {"HostIP":"192.168.0.100","message":"hello world"}333}334func ExampleContext_IPPrefix() {335 route := net.IPNet{IP: net.IP{192, 168, 0, 0}, Mask: net.CIDRMask(24, 32)}336 log := zerolog.New(os.Stdout).With().337 IPPrefix("Route", route).338 Logger()339 log.Log().Msg("hello world")340 // Output: {"Route":"192.168.0.0/24","message":"hello world"}341}342func ExampleContext_MacAddr() {343 mac := net.HardwareAddr{0x00, 0x14, 0x22, 0x01, 0x23, 0x45}344 log := zerolog.New(os.Stdout).With().345 MACAddr("hostMAC", mac).346 Logger()347 log.Log().Msg("hello world")348 // Output: {"hostMAC":"00:14:22:01:23:45","message":"hello world"}349}...

Full Screen

Full Screen

shim_test.go

Source:shim_test.go Github

copy

Full Screen

...92 backendFormatter := logging.NewBackendFormatter(backend, format)93 logging.SetBackend(backendFormatter).SetLevel(logging.Level(shimLoggingLevel), "shim")94 foo := NewLogger("foo")95 bar := NewLogger("bar")96 foo.Debugf("Foo is debugging: %d", 10)97 bar.Infof("Bar is informational? %s.", "Yes")98 foo.Noticef("NOTE NOTE NOTE")99 bar.Warningf("Danger, Danger %s %s", "Will", "Robinson!")100 foo.Errorf("I'm sorry Dave, I'm afraid I can't do that.")101 bar.Criticalf("PI is not equal to 3.14, we computed it as %.2f", 4.13)102 bar.Debug("Foo is debugging:", 10)103 foo.Info("Bar is informational?", "Yes.")104 bar.Notice("NOTE NOTE NOTE")105 foo.Warning("Danger, Danger", "Will", "Robinson!")106 bar.Error("I'm sorry Dave, I'm afraid I can't do that.")107 foo.Critical("PI is not equal to", 3.14, ", we computed it as", 4.13)108 foo.SetLevel(LogWarning)109 if foo.IsEnabledFor(LogDebug) {110 t.Errorf("'foo' should not be enabled for LogDebug")111 }112 if !foo.IsEnabledFor(LogCritical) {113 t.Errorf("'foo' should be enabled for LogCritical")114 }115 bar.SetLevel(LogCritical)116 if bar.IsEnabledFor(LogDebug) {...

Full Screen

Full Screen

Foo

Using AI Code Generation

copy

Full Screen

1log.Foo()2log.Bar()3log.Foo()4log.Bar()5import "fmt"6type log struct {7}8func (l *log) init() {9 fmt.Println("log initialized")10}11var instance *log = &log{}12func init() {13 instance.init()14}15func main() {16 fmt.Println("main started")17}18In Go, we can use the init()

Full Screen

Full Screen

Foo

Using AI Code Generation

copy

Full Screen

1log.Foo()2log.Bar()3log.Baz()4log.Foo()5log.Bar()6log.Baz()7log.Foo()8log.Bar()9log.Baz()10log.Foo()11log.Bar()12log.Baz()13log.Foo()14log.Bar()15log.Baz()16log.Foo()17log.Bar()18log.Baz()19log.Foo()20log.Bar()21log.Baz()22log.Foo()23log.Bar()24log.Baz()25log.Foo()26log.Bar()27log.Baz()28log.Foo()29log.Bar()30log.Baz()31log.Foo()32log.Bar()

Full Screen

Full Screen

Foo

Using AI Code Generation

copy

Full Screen

1log.Foo()2log.Foo()3log.Foo()4Now, if you are using a method from a class in a different package, you have to import that package. For example, if you want to use the Println method of the fmt class, you have to import the fmt package. You can do this by adding the following line to the top of your file:5import "fmt"6fmt.Println("Hello World")7You can also import multiple packages by adding multiple import statements:8import "fmt"9import "math"10You can also import multiple packages in a single import statement:11import ("fmt"12If you are using a method from a class in the same package, you don’t have to import that package. You can directly use the method. For example, if you are using the Foo method of the log class in the same package, you can use it by using the following code:13log.Foo()14import "fmt"15func Foo() {16 fmt.Println("Hello World")17}18import "log"19func main() {20 log.Foo()21}22 /usr/local/go/src/log (from $GOROOT)

Full Screen

Full Screen

Foo

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 logFile, err := os.OpenFile("log.txt", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)4 if err != nil {5 log.Fatalln("failed to open log file:", err)6 }7 log.SetOutput(logFile)8 log.SetPrefix("TRACE: ")9 log.SetFlags(log.Ldate | log.Lmicroseconds | log.Llongfile)10 log.Println("message")11 log.Fatalln("fatal message")12}13The Fatal functions call os.Exit(

Full Screen

Full Screen

Foo

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 log.Foo()4}5import (6func main() {7 log.Println("Hello")8}9./1.go:7: log.Foo undefined (type *log.Logger has no field or method Foo)10./2.go:7: log.Foo undefined (type *log.Logger has no field or method Foo)11./1.go:7: log.Foo undefined (type *log.Logger has no field or method Foo)12./2.go:7: log.Foo undefined (type *log.Logger has no field or method Foo)13Now, if you want to use the log package in both the files, you can do it by importing it as:14import (15How to import a package in Go?16How to import a package in Go?

Full Screen

Full Screen

Foo

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 log.Println("Hello, world!")4}5import (6func main() {7 log.Println("Hello, world!")8}9import (10func main() {11 log.Println("Hello, world!")12}13import (14func main() {15 log.Println("Hello, world!")16}17import (18func main() {19 log.Println("Hello, world!")20}21import (22func main() {23 log.Println("Hello, world!")24}25import (26func main() {27 log.Println("Hello, world!")28}29import (30func main() {31 log.Println("Hello, world!")32}33import (34func main() {35 log.Println("Hello, world!")36}37import (38func main() {39 log.Println("Hello, world!")40}41import (42func main() {43 log.Println("Hello, world!")44}45import (46func main() {47 log.Println("Hello, world!")48}49import (50func main() {51 log.Println("

Full Screen

Full Screen

Foo

Using AI Code Generation

copy

Full Screen

1log := log.New()2log.Foo()3log := log.New()4log.Bar()5log := log.New()6log.Foo()7log := log.New()8log.Bar()9type Log struct {10}11func (l *Log) Foo() {12}13func (l *Log) Bar() {14}15func New() *Log {16}17log := log.New()18log.Foo()19log := log.New()20log.Bar()21type Log struct {22}23func (l *Log) Foo() {24}25func (l *Log) Bar() {26}27func New() *Log {28}29import (30func TestLog(t *testing.T) {31 log := New()32 log.Foo()33}34log := log.New()35log.Foo()36log := log.New()37log.Bar()38type log struct {39}40func (l *log) Foo() {41}42func (l *log) Bar() {43}44func New() *log {45}46import (

Full Screen

Full Screen

Foo

Using AI Code Generation

copy

Full Screen

1import "log"2func main() {3 log.Println("Hello World")4}5import "log"6func main() {7 log.Fatal("Hello World")8}9import "log"10func main() {11 log.Panic("Hello World")12}13log.Panic(0xc00003bf68, 0x1, 0x1)14main.main()15time.Sleep(0x5f5e100)16main.main.func1()17main.main.func2()18main.main.func3()

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Mock automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful