R
Railway2mo ago
sowing

go logging registers as errors

project id: 271ed33d-be6b-40ce-96ba-504a94362dac howdy y'all. I'm hosting a go app on railway and it's been great but whenever I use go's default logger or charm log, all of my logs show up as errors instead of info. I have tried modifying the default logger's output to ensure it's not printing to standard err but it's still categorizing all of my logging as errors. Just wondering if anyone has any insight as to why this is happening.
Solution:
but making a new logger with stdout as its output seems to fix the problem
Jump to solution
36 Replies
Percy
Percy2mo ago
Project ID: 271ed33d-be6b-40ce-96ba-504a94362dac
Brody
Brody2mo ago
you are on the right track, sending logs to stdout instead of stderr would print them as info, can you please provide a minimal reproducible example for me to test
sowing
sowing2mo ago
yeah i'll whip one up when i get back to my computer
Brody
Brody2mo ago
sounds good!
sowing
sowing2mo ago
ok i think this should do it
package main

import (
"os"

"github.com/charmbracelet/log"
)

func main() {
log.Default().setOutput(os.Stdout)

port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
log.Infof("Listening on port: %s", port)
}
package main

import (
"os"

"github.com/charmbracelet/log"
)

func main() {
log.Default().setOutput(os.Stdout)

port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
log.Infof("Listening on port: %s", port)
}
Brody
Brody2mo ago
what version of go do you use
sowing
sowing2mo ago
i tried both log.Default().setOutput() and log.setOutput() and both seem to send to stderr anyways 1.22
Brody
Brody2mo ago
is cmp.Or a thing in that version?
sowing
sowing2mo ago
it is indeed
Brody
Brody2mo ago
little tip but it has nothing to do with logs - port := cmp.Or(os.Getenv("PORT"), "8080") saves 3 lines haha
sowing
sowing2mo ago
that's pretty nice. never used that before lol
Brody
Brody2mo ago
okay ill get to testing now
sowing
sowing2mo ago
thanks so much!
Brody
Brody2mo ago
well not off to a good start
No description
sowing
sowing2mo ago
oh that's totally my bad no lsp in discord code blocks capitals for public methods is right. I've been writing too much rust okay so it looks like you just can't set the default logger's output to stdout
Want results from more Discord servers?
Add your server