I've searched for it and only found here and here, but it does not solve my problem.
How can I, using a standard way, identify the log separating the concurrent logs like JAVA does with thread ID? Because if I have a concurrent method then the logs will be printed mixed at the output, so I think that the LOGGER needs to have a way of identifying each request "thread"
Ex:
package main
import "log"
func main() {
/* simulating 10000 users requests */
for i:=1; i < 10000; i++ {
go getHello(i)
}
}
func getHello(d int){
log.Printf("m=getHello, i=%d,begin", d)
log.Println("m=getHello, processing the hello message")
log.Printf("m=getHello, i=%d, end", d)
}
output
2016/07/29 15:59:46 m=getHello, i=1017,begin
2016/07/29 15:59:46 m=getHello, processing the hello message
2016/07/29 15:59:46 m=getHello, i=1017, end
2016/07/29 15:59:46 m=getHello, processing the hello message
2016/07/29 15:59:46 m=getHello, i=1038, end
2016/07/29 15:59:46 m=getHello, i=311,begin
2016/07/29 15:59:46 m=getHello, processing the hello message
2016/07/29 15:59:46 m=getHello, i=311, end
2016/07/29 15:59:46 m=getHello, i=1023,begin
As you can see, without using an int flag, it is impossible to know which request logged a message. In Java and C for example you can use thread id for this purpose.
How to achieve this in Golang? Thanks.