STDERR Printout

Now, most of the *.Println or *.Printf are directly printed out into standard output (stdout). While this is expected, it is not professional in Linux as we tend to practice "Silence is Gold". What we usually do is to perform these printout onto the standard error channel (stderr) instead of the output, unless they are actually output).

Printout using FMT and OS

Hence, instead of conventional way of printout, we use Fprintf instead.

import (
        "fmt"
        "os"
)

...
nFoo := 2
fmt.Fprintf(os.Stderr, "number of foo: %d", nFoo)
...

Logging

If you're using Log, which is a good practice, then:

import (
        "log"
        "os"
)

...
l := log.New(os.Stderr, "", 0)
l.Println("log msg")
...

Either way works. Personally I prefer FMT method since I do not need to import another log package while reserving log to generate log file.

That's all about stderr printout recipe.