I know that we can print variable or error using log
and fmt
. for example if I want to print variable I can do this :
h := "world"
fmt.Printf("hello = %v\n", h)
log.Printf("halo = %v\n", h)
the output would be :
hello = world
2016/12/30 09:13:12 halo = world
and usually in the error handling I found log like this
if err != nil {
log.Println("Error : something terrible happen -> ", err)
return err
}
but from above case I could also use fmt
to print the error like this
fmt.Printf("Error : something terrible happen -> %v\n",err.Error())
Is it a good practice to use fmt
instead of log
for printing the error?
And then I always use fmt
instead of log
for printing the variable when debugging.