/

Console Output Configuration

Console output displays logs directly in your application's console. Configure console logging to enhance your debugging and development experience.

Enable Console Output

Enable console logging:

Go
import logs "github.com/bytehide/bytehide-logs-go"

logs.SetConsoleEnabled(true)  // Enable console output (default: false)

Configuration Examples

Development Configuration

Go
logs.SetConsoleEnabled(true)
logs.SetMinimumLevel(logs.LogLevelDebug)  // Verbose console output

Production Configuration

Go
logs.SetConsoleEnabled(false)         // Disable console in production
logs.SetMinimumLevel(logs.LogLevelWarn)   // Only important messages

Debugging Configuration

Go
logs.SetConsoleEnabled(true)
logs.SetMinimumLevel(logs.LogLevelTrace)  // All messages

Environment-Based Configuration

Go
import (
    "os"
    "strings"
    logs "github.com/bytehide/bytehide-logs-go"
)

environment := os.Getenv("APP_ENVIRONMENT")
isDevelopment := strings.EqualFold(environment, "development")

logs.SetConsoleEnabled(isDevelopment)

Console Output Examples

Go
logs.SetConsoleEnabled(true)
logs.SetMinimumLevel(logs.LogLevelInfo)

logs.Info("User logged in")
// Output: [Info] User logged in

logs.Error("Database connection failed", err)
// Output: [Error] Database connection failed

Structured Console Output

Console output supports context and tags:

Go
logs.SetConsoleEnabled(true)

logs.WithContext("userId", "123").
    WithContext("action", "login").
    WithTags("auth", "success").
    Info("User logged in")
// Output: [Info] User logged in { userId: "123", action: "login" } tags: [auth, success]

Performance Considerations

SettingPerformance ImpactUse Case
SetConsoleEnabled(true)Moderate overheadDevelopment/debugging
SetConsoleEnabled(false)No overheadProduction

Optimization for Production

Go
logs.SetConsoleEnabled(false)       // Disable console for performance
logs.SetPersist(true)                // Use file logging instead
logs.SetFilePath("logs/production.log")

Best Practices

Console Output Best Practices

  • Enable console output only in development environments
  • Disable in production for better performance
  • Combine with file logging for comprehensive logging strategy
  • Use environment variables to control console output per environment

Troubleshooting

IssueSolution
No console outputVerify SetConsoleEnabled(true) was called
Performance issuesDisable console output in production
Output is truncatedCheck log level filtering

Next Steps

Previous
Log Levels