Standard library / log

log.New()

Construct an independent logger with a destination, prefix and formatting flags. Expected stdout: 'app: hello\n'.

Formal Syntax & Structure

go syntaxgo
func New(out io.Writer, prefix string, flag int) *Logger

Parameters & Attributes

NameTypeDescription
outio.WriterWriter receiving log records.
prefixstringText prepended to each log entry.
flagintBitmask of formatting flags.

Return Value

*Logger

Construct an independent logger with a destination, prefix and formatting flags.

Working Example

Example Snippetgo
package main
import (  "bytes"  "fmt"  "log")
func main() {  var b bytes.Buffer  l := log.New(&b, "app: ", 0)  l.Print("hello")  fmt.Print(b.String())}
Go Reference