Logo

Programming-Idioms

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

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.

integer :: value(8)
msg = "asdf"
call date_and_time (values=value)
write (unit=*,fmt='(I4,"-",I2.2,"-",I2.2," ",I2.2,":",I2.2,".",I4.4,": ",A)') value(1:3), value(5:7), msg

This writes to standard output,a nd the date format is ISO 8601.
Console.WriteLine($"[{DateTime.Now}] {msg}");

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

New implementation...