2 years 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
21 Replies
2 years ago
because it prints to stderr, instead you would want to log with json for the proper colours

2 years 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"}) ?
2 years 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.NewJSONHandler(os.Stdout, &slog.HandlerOptions{AddSource: true}))).
2 years 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.
2 years 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"
);
}2 years ago
interesting approach
2 years ago
!s
Status changed to Solved brody • over 1 year ago

