5 months ago
Hi, not sure if I'm doing something wrong on my end but any console.warn
shows up as an error in my logs so my logs are just filled with errors and no warnings
0 Replies
5 months ago
because it prints to stderr, instead you would want to log with json for the proper colours
5 months ago
you should use a json logger which will format your logs to something like this:
{"time":"2025-03-06T23:16:18.292397+01:00","level":"INFO","msg":"Synced 4 commands"}
so i literally write console.log({"time":"2025-03-06T23:16:18.292397+01:00","level":"INFO","msg":"Synced 4 commands"})
?
5 months ago
you should be able to configure the logging behavior or use an external package that does exactly that.
for example in go, you can just configure the logger to log json using the built in slog package slog.SetDefault([slog.New](slog.New)([slog.New](slog.New)JSONHandler(os.Stdout, &slog.HandlerOptions{AddSource: true})))
.
5 months ago
> JSON logging is the recording of log entries as structured JSON objects. This approach makes log data easy to parse and analyze with various log management systems, analytics tools, and other software applications.
5 months ago
for example, Railway will check for the "level" key in the json and correctly display it as info, error or warn
for those who might come across this in the future: a quick no dep solution is this:
// Use JSON logging in Railway
// https://discord.com/channels/713503345364697088/1347328038886703269
const util = require("util");
if (process.env.RAILWAY_PROJECT_ID) {
globalThis.console.warn = (...args) =>
process.stdout.write(
JSON.stringify({
level: "warn",
msg: args.map((arg) => typeof arg === "string" ? arg : util.inspect(arg)).join(" "),
}) + "\n"
);
}
5 months ago
interesting approach
5 months ago
!s
Status changed to Solved brody • 5 months ago