| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- package common
- import (
- "fmt"
- "log/slog"
- "os"
- "time"
- "github.com/gin-gonic/gin"
- )
- func SysLog(s string) {
- slog.Info(s, "component", "system")
- }
- func SysError(s string) {
- slog.Error(s, "component", "system")
- }
- func FatalLog(v ...any) {
- msg := fmt.Sprint(v...)
- slog.Error(msg, "component", "system", "level", "fatal")
- os.Exit(1)
- }
- func LogStartupSuccess(startTime time.Time, port string) {
- duration := time.Since(startTime)
- durationMs := duration.Milliseconds()
- // Get network IPs
- networkIps := GetNetworkIps()
- // Print blank line for spacing
- fmt.Fprintf(gin.DefaultWriter, "\n")
- // Print the main success message
- fmt.Fprintf(gin.DefaultWriter, " \033[32m%s %s\033[0m ready in %d ms\n", SystemName, Version, durationMs)
- fmt.Fprintf(gin.DefaultWriter, "\n")
- // Skip fancy startup message in container environments
- if !IsRunningInContainer() {
- // Print local URL
- fmt.Fprintf(gin.DefaultWriter, " ➜ \033[1mLocal:\033[0m http://localhost:%s/\n", port)
- }
- // Print network URLs
- for _, ip := range networkIps {
- fmt.Fprintf(gin.DefaultWriter, " ➜ \033[1mNetwork:\033[0m http://%s:%s/\n", ip, port)
- }
- // Print blank line for spacing
- fmt.Fprintf(gin.DefaultWriter, "\n")
- }
|