Standard library / log
log.Logger.SetPrefix()
Set the text prefix for subsequent messages. Expected stdout: 'app: hello\n'.
Formal Syntax & Structure
go syntaxgo
func (l *Logger) SetPrefix(prefix string)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| prefix | string | Text prepended to each log entry. |
Working Example
Example Snippetgo
package main
import ( "bytes" "fmt" "log")
func main() { var b bytes.Buffer l := log.New(&b, "", 0) l.SetPrefix("app: ") l.Print("hello") fmt.Print(b.String())}