HiveBrain v1.2.0
Get Started
← Back to all entries
debuggoModerate

How can I print to Stderr in Go without using log

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
howstderrlogusingcanprintwithout

Problem

How can I write a message to Stderr without using log?

A comment in this SO post shows how to do it with log: log.Println("Message"), but what if I don't want a timestamp?

Is the following good Go?

os.Stderr.WriteString("Message")

Solution

The Go builtin functions print and println print to stderr. So if you simply want to output some text to stderr you can do

package main

func main() {
    println("Hello stderr!")
}


Documentation: https://golang.org/pkg/builtin/#print

Code Snippets

package main

func main() {
    println("Hello stderr!")
}

Context

Stack Overflow Q#29721449, score: 39

Revisions (0)

No revisions yet.