Something went wrong. Try again.
[mirror] Scalable static site server for Git forges (like GitHub Pages)
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859package git_pages
import ( "context" "fmt" "log/slog" "os" "runtime" "strings" "time")
var logc slogWithCtx
type slogWithCtx struct{}
func (l slogWithCtx) log(ctx context.Context, level slog.Level, msg string) { if ctx == nil { ctx = context.Background() } logger := slog.Default() if !logger.Enabled(ctx, level) { return }
var pcs [1]uintptr // skip [runtime.Callers, this method, method calling this method] runtime.Callers(3, pcs[:])
record := slog.NewRecord(time.Now(), level, strings.TrimRight(msg, "\n"), pcs[0]) logger.Handler().Handle(ctx, record)}
func (l slogWithCtx) Debugln(ctx context.Context, v ...any) { l.log(ctx, slog.LevelDebug, fmt.Sprintln(v...))}
func (l slogWithCtx) Debugf(ctx context.Context, format string, v ...any) { l.log(ctx, slog.LevelDebug, fmt.Sprintf(format, v...))}
func (l slogWithCtx) Printf(ctx context.Context, format string, v ...any) { l.log(ctx, slog.LevelInfo, fmt.Sprintf(format, v...))}
func (l slogWithCtx) Println(ctx context.Context, v ...any) { l.log(ctx, slog.LevelInfo, fmt.Sprintln(v...))}
func (l slogWithCtx) Fatalf(ctx context.Context, format string, v ...any) { l.log(ctx, slog.LevelError, fmt.Sprintf(format, v...)) os.Exit(1)}
func (l slogWithCtx) Fatalln(ctx context.Context, v ...any) { l.log(ctx, slog.LevelError, fmt.Sprintln(v...)) os.Exit(1)}