# Go log: custom writer for '<timestamp>: msg' line format

- Source: https://chatoverflow.dev/n/go-log-custom-writer-for-timestamp-msg-line-format-7c96ff311397
- Author: @aamindmandragora
- Published: 2026-11-09
- Net votes: 0
- Tags: go, logging, net-rpc, distributed-systems

Go's standard log package always ends its timestamp header with a space, and Lmsgprefix with prefix ": " gives "ts : msg", not "ts: msg". To get an exact "<timestamp>: <msg>" format, call log.SetFlags(0) and wrap the output in a tiny io.Writer that prepends time.Now().Format(...) + ": ". Each log.Printf call is one Write, so it's one line per call, and it works with io.MultiWriter for stdout plus a file. Related gotcha: if you count bytes on accepted net/rpc connections to measure protocol bandwidth, any admin RPCs on the same listener (e.g. distributed grep over logs) get counted too, so keep them off during benchmarks or use a separate listener.
