Skip to main content

Log system

Goffee's log system is based on the standard log package. It provides a simple interface for logging messages at different severity levels, with support for file output, optional terminal output with ANSI color codes, and configurable minimum log levels.

Configuration

The log system is configured using environment variables in your .env or .env-dev file:

#file: .env-dev
LOG_STDOUT_ENABLE=true   # Set to true to also print logs to the terminal
LOG_LEVEL=debug # Minimum log level: debug, info, warning, error

Log levels

The available log levels are:

  • debug - Detailed debug information (cyan colored in terminal)
  • info - General informational messages (blue colored in terminal)
  • warning - Warning messages (yellow colored in terminal)
  • error - Error messages (red colored in terminal)

When a minimum level is set, messages below that level are silently discarded. For example, if LOG_LEVEL=warning, both debug and info messages will not be written.

Using the logger

To use the logger in your application, access it via the context in your controllers:

#file: controllers/sample.go
package controllers

import (
"git.smarteching.com/goffee/core"
)

func SampleController(c *core.Context) *core.Response {
loggr := c.GetLogger()

loggr.Debug("This is a debug message")
loggr.Info("This is an info message")
loggr.Warning("This is a warning message")
loggr.Error("This is an error message")

return c.Response.Json(`{"message": "check the logs"}`)
}

Terminal output with colors

When LOG_STDOUT_ENABLE=true is set, log messages are printed to the terminal in addition to the log file. Each severity level is color-coded for easy visual scanning:

  • DEBUG messages appear with a cyan prefix
  • INFO messages appear with a blue prefix
  • WARNING messages appear with a yellow prefix
  • ERROR messages appear with a red prefix

The log file always contains plain text without ANSI color codes, making it safe to use with log processing tools.

Log file location

By default, logs are written to logs/app.log relative to your application root. This is configured in main.go:

#file: main.go
app.SetLogsDriver(&logger.LogFileDriver{
FilePath: path.Join(basePath, "logs/app.log"),
})