You mean fmt.Fprintf right? Formatting a string without writing to a io.Writer (fmt.Sprintf) must be safe for concurrent use.
The "log" package should be safe for concurrent use, and has a Printf function: https://godoc.org/log#Logger """ A Logger represents an active logging object that generates lines of output to an io.Writer. Each logging operation makes a single call to the Writer's Write method. A Logger can be used simultaneously from multiple goroutines; it guarantees to serialize access to the Writer. """ On Wednesday, October 18, 2017 at 12:18:10 PM UTC-7, David Renne wrote: > > I had a question that I cant seem to figure out. I know fmt is a bad > package to use if you have any concurrent workers because it uses f.Write() > and is not thread safe apparently. > > But I like using Sprintf because I can format strings and return as a > string. How can I implement something to use the log package in a manner > that I can have a concurrently safe log function which acts like Sprintf()? > > It's just so strange to me and I have always been curious of why there > isnt a log.Sprintf(). > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.