Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Go

Idiom #145 Print log line with datetime

Print message msg, prepended by current date and time.

Explain what behavior is idiomatic: to stdout or stderr, and what the date format is.

import "log"
log.Println(msg)

This prints to os.Stderr by default, with a datetime prefix.
Console.WriteLine($"[{DateTime.Now}] {msg}");

Default behavior of Console.WriteLine is stdout. DateTime should respect system culture defaults.

New implementation...