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) *LoggerParameters & Attributes
| Name | Type | Description |
|---|---|---|
| out | io.Writer | Writer receiving log records. |
| prefix | string | Text prepended to each log entry. |
| flag | int | Bitmask 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())}