Article 4DVTH Representative Line: Log Every Error

Representative Line: Log Every Error

by
Remy Porter
from The Daily WTF on (#4DVTH)

Tom C inherited some Go from another developer, and writes, "I'm pretty sick of finding this sort of stuff in this code."

if log, err = dockerservice.GetLoggerInstance(); err != nil {log.Err(fmt.Sprintf("Logger error: %v \n", err)) }

It's good to log every error- it'll help in the long run when you're trying to trace through the problem which happens in production but the program works fine on your machine. This code knows that accessing the logger object is code that can throw an error, so if it gets an error fetching the logger object it" logs the error. With the logger object that returned some kind of error.

raygun50.png [Advertisement] Forget logs. Next time you're struggling to replicate error, crash and performance issues in your apps - Think Raygun! Installs in minutes. Learn more. TheDailyWtf?d=yIl2AUoC8zAvspuEQw8AJo
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments