Computing Magazine

Logging To Stdout And Stderr

Posted on the 15 May 2016 by Hean Hong Leong @hongster

There are many sophisticated logging tools that provide advanced features like analytics. Depending on your application needs, sometimes all we want is just simple logging. For such, I recommend logging to standard output and standard error.

1 of the advantages is flexibility of redirecting/piping of log data to files and applications. It also works on most programming languages, including Go. I will be Go for illustration.

I wrote a simple logger (https://github.com/hongster/goldilocks), that logs output to standard streams by default. Informational and warning messages to Stdout, error messages to Stderr. Using the example application in README,

I can redirect standard and error log to separate files

./myapp > log.txt 2> error.txt

Combine all log into single file

./myapp &> combined.txt

Capture only non-error messages

./myapp > log.txt

Pass the log into another application for processing

./myapp 2>&1 | gzip > log.txt.gz

This is quite common among Linux applications.


You Might Also Like :

Back to Featured Articles on Logo Paperblog

These articles might interest you :

  • Skinny Creamy Italian Vanilla Gelato / Fior Di Latte Gelato - Made with Minimal...

    Skinny Creamy Italian Vanilla Gelato Fior Latte Made with Minimal Sugar Cream

    version; Today, I will be sharing a fantastic gelato recipe!Is gelato the same as ice cream?Although gelato is the Italian word for ice cream, both are... Read more

    The 21 October 2018 by   Zoebakeforhappykids
    FOOD & DRINK, RECIPES
  • How To Make Your Boyfriend Give You Money Without Asking Him

    Money has always been a sensitive issue in a relationship. Women like it when their boyfriend pays for dinner, movie ticket, and other dating expenses. Read more

    The 21 October 2018 by   Naijapary
    SOCIETY, A-CLASSER
  • Discover the Nature and Beauty of the High Mountain Environments in the Valle...

    Discover Nature Beauty High Mountain Environments Valle d'Aosta.

    Aosta Valley is the smallest region in Italy; in its northwest, it is located between France and Switzerland. At its core are its majestic peaks (the region... Read more

    The 21 October 2018 by   Hugor
    DESTINATIONS
  • The Autumn 100 - My Ultra Comeback

    I thought I made pretty good time getting to the turnaround point. Now I was pleased it was downhill all the way to Goring, except there still seemed to be load... Read more

    The 21 October 2018 by   Jamesrichardadams
    FITNESS, OTHER SPORTS, SPORTS
  • When You Should Come In To Net

    When Should Come

    One of the main goals in doubles tennis is to take the net, as it decreases the likelihood of hitting the ball into the net and gives you better angles to put... Read more

    The 21 October 2018 by   Jen Campbell
  • …Root, Root, Root

    …Root, Root, Root

    As the end of October comes into view so too does the beginning of the 2018 World Series. This year sees the Boston Red Sox take on the LA Dodgers in a battle o... Read more

    The 21 October 2018 by   Zer
    SELF EXPRESSION
  • Loneliness Limited

    Loneliness Limited

    Is anyone here a fan of the writings of the American author Kurt Vonnegut? He was quite fashionable in the 1960s and early 1970s but I think his cachet is not... Read more

    The 21 October 2018 by   Ashleylister
    BOOKS, CREATIVITY, CULTURE, SELF EXPRESSION

Magazine