Go Package log: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 10: Line 10:


The "log" package provides support for logging messages to <tt>stdout</tt>, <tt>stderr</tt> or custom devices.
The "log" package provides support for logging messages to <tt>stdout</tt>, <tt>stderr</tt> or custom devices.
<syntaxhighlight lang='go'>
import (
    "log"
)
...
log.Printf("something %s\n", "else")
</syntaxhighlight >


=Elements=
=Elements=

Revision as of 20:01, 15 December 2023

External

Internal

Overview

The "log" package provides support for logging messages to stdout, stderr or custom devices.

import (
    "log"
)
...

log.Printf("something %s\n", "else")

Elements

  • log.Fatal: Fatal is equivalent to Print() followed by a call to os.Exit(1).

Recipes

Changing the Logging Device

By default, the logger is set to write to stderr. To change that:

import (
    "log"
    "os"
)
...
func init() {

    // change the device for logging to stdout
    log.SetOutput(os.Stdout)
}