charmbracelet / log

A minimal, colorful Go logging library 🪵
MIT License
2.4k stars 67 forks source link

Feature request: Set log level via environment variables #9

Closed yonas closed 1 year ago

yonas commented 1 year ago

Set log level via environment variables. For example: LOG_LEVEL=debug

aymanbagabas commented 1 year ago

IMO, setting the log level from environment variables is the application's responsibility, not the library's. Different applications may choose different environment variables. You could try something like:

switch os.Getenv("LOG_LEVEL") {
  case "debug": log.SetLevel(log.DebugLevel)
  case "info": log.SetLevel(log.InfoLevel)
  case "warn": log.SetLevel(log.WarnLevel)
  case "error": log.SetLevel(log.ErrorLevel)
}
muesli commented 1 year ago

I agree with @aymanbagabas. This should be set explicitly by log's user, not auto-magically.

yonas commented 1 year ago

@aymanbagabas Can you add the wontfix tag here to distinguish this project from gozeloglu's work? Thanks.