Remove runwar.context from logs

I’m using the Docker image ortussolutions/commandbox:lucee5-3.4.4

When writing to stdout with Lucee’s SystemOutput or WriteDump(output='console') or even Java’s System.out, all my logs are prefixed with “[INFO ] runwar.context”. How can I remove this prefix?

Looks like the prefix is added here runwar/ at 8cded729fa5fd97ad7d29c14702230eade9da17c · Ortus-Solutions/runwar · GitHub

Commandbox itself is stripping out the prefix here commandbox/ServerService.cfc at caa3b84b44e2c6eb14228b2cc9397c6406d1ac35 · Ortus-Solutions/commandbox · GitHub

The short answer is you can’t :slight_smile: The console logs are all processed through Log4j and the logger category is part of the default format. You are correct I clean up the lines when I display them as part of CommandBox so I can control them. but the console output just sees the raw log4j output.

It’s probably possible to have a custom log4j formatter, but that ability isn’t exposed through Runwar unless there’s some system property available to change it.

Looks like the prefix is added here

That line isn’t “adding” anything. That’s just some boilerplate that captures the JBoss loggers and pipes them into Log4j.

I still don’t understand why a webserver is affecting something like SystemOutput. Shouldn’t that give straightforward access to stdout?

Because the java system out doesn’t flow directly to the standard out of the java process. It’s hooked by wrapping the System.out print reader with a special one that redirects it to log4j so we can also write out the server log text file. The raw output from java’s out stream ends up inside a Log4j logging category which is then fed to both a file appender and a console appender so we have a lot of control over it . And sending it through Log4j is what makes the messages get the extra formatting.

Could it be done differently? Probably. But this is how it has been done to date and no one has ever seemed to mind much. The LoggerStream class is what is installed as the new system out stream, it takes all messages and passes them onto Log4j. It’s probably possible to remove the console appender in Log4j and modify the loggerstream to pass the lines to log4j’s logger AND write them out to the original out print stream as well. Someone would have to test and see what all it breaks, lol.

@shanecav_singlebrook I just completed a ticket which was done for an unrelated reason, but it will give you a possible workaround for your issue as well.

This does currently require the bleeding edge builds of CommandBox (5.5.0-alpha) but it will allow you to fully customize how Log4j outputs all log entries (console and file appenders).

So for example,

 server set runwar.args='--log-pattern "%m%n"'

will strip the severity and categories off of all log lines so you just get the raw messages being stored. Keep in mind this will affect all log messages flowing through the appender, not JUST the ones coming from Java’s System.out.

Much appreciated! I will take a look at this next week. Thanks!

1 Like