core/logger/logger.go
core/logger/logger.goBrowse 1970 files
515 tokens
1,832 bytes
Token encoding: o200k_base
Snapshot 21a254f
← Back to SKILL.md
1package logger2 3import (4 "fmt"5 "net/url"6 "strings"7)8 9type Level string10 11const (12 Info Level = "info"13 Warn Level = "warn"14 Deprecation Level = "deprecation"15 Suggestion Level = "suggestion"16 Error Level = "error"17 18 DocsBaseURL = "https://railpack.com"19)20 21type Msg struct {22 Level Level23 Msg string24 DocsPath string // optional Railpack-relative path or absolute URL25}26 27type Logger struct {28 Logs []Msg29}30 31func NewLogger() *Logger {32 return &Logger{33 Logs: []Msg{},34 }35}36 37func (l *Logger) LogInfo(format string, args ...any) {38 l.log(Info, format, args...)39}40 41func (l *Logger) LogWarn(format string, args ...any) {42 l.log(Warn, format, args...)43}44 45func (l *Logger) LogDeprecation(format string, args ...any) {46 l.log(Deprecation, format, args...)47}48 49// LogSuggestion records a helpful config suggestion with an optional docs link.50// Relative paths resolve against railpack.com; absolute URLs are used unchanged.51func (l *Logger) LogSuggestion(msg string, docsPath ...string) {52 path := ""53 if len(docsPath) > 0 {54 path = docsPath[0]55 }56 l.Logs = append(l.Logs, Msg{57 Level: Suggestion,58 Msg: msg,59 DocsPath: path,60 })61}62 63func (l *Logger) LogError(format string, args ...any) {64 l.log(Error, format, args...)65}66 67func (l *Logger) log(level Level, format string, args ...any) {68 msg := format69 if len(args) > 0 {70 msg = fmt.Sprintf(format, args...)71 }72 l.Logs = append(l.Logs, Msg{73 Level: level,74 Msg: msg,75 })76}77 78// DocsURL resolves Railpack-relative docs paths while preserving absolute URLs.79func DocsURL(docsPath string) string {80 if docsPath == "" {81 return DocsBaseURL82 }83 84 parsedURL, err := url.Parse(docsPath)85 if err == nil && parsedURL.IsAbs() {86 return docsPath87 }88 89 if !strings.HasPrefix(docsPath, "/") {90 docsPath = "/" + docsPath91 }92 return DocsBaseURL + docsPath93}94