Sobes.tech
Junior — Middle

Where do you usually log in the application or system?

sobes.tech AI

Answer from AI

In Go, logging is usually done using the standard log package or more advanced libraries such as zap, logrus, or zerolog.

Logs are typically written:

  • To the console (stdout/stderr) — convenient for local development and containerized applications.
  • To files — for long-term storage and analysis.
  • To remote logging systems (e.g., via syslog, Fluentd, ELK stack).

Example of writing a log to a file using the standard package:

package main

import (
    "log"
    "os"
)

func main() {
    file, err := os.OpenFile("app.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
    if err != nil {
        log.Fatal(err)
    }
    defer file.Close()

    log.SetOutput(file)
    log.Println("Application started")
}

In real applications, more flexible libraries are often used, which allow configuring log levels, formats, and output.