How to change log file layout?

I’m trying to create a custom log using a custom layout. I see in the
lucee-server.xml config file a section called with a
element for each of the default log types. Is it possible to add my our log
file and layout?

The default logger in tomcat isn’t super-configurable, but you can implement other loggers that are much more flexible. Probably one of the most popular loggers is “log4j” - which DOES include the Pattern Layout customization options you’re looking for. While old, and specifically written to implement log rotation, here’s an article on how to configure log4j with your Tomcat config:

Hope this helps.–
Kind regards,
Jordan Michaels
Vivio Technologies

For the lucee-specific questions, I don’t know for sure as I’m not a Lucee engineer. :wink: I just work with it (a lot).

For tomcat, it’s logging is pretty well documented:

If you consider that Lucee is at its core a java app running side a tomcat container, you can probably extrapolate a lot of your answer from there.

Wish I could offer a better answer for you.–
Kind regards,
Jordan Michaels
Vivio Technologies

Would you be able to explain a little bit about how logging works in Lucee?
When I writelog(…) it looks like it calls (I have
played with this class and was able to change the logging format) Does that
class have anything to do with layout=“classic” in the following line
found in lucee-server.xml?

<logger appender="resource" appender-arguments=
"path:{lucee-config}/logs/application.log" layout="classic" name=

and if so can I add my own class?

<logger appender="resource" appender-arguments=
"path:{lucee-config}/logs/application.log" layout=
"com.mycompany.CustomLayout" name="application"/>

the lucee-server.xml implies that it is possible:

A full class path to a Layout class available in the enviroemnt with a
empty constructor.
for every argument defined lucee tries to call a matching setter method

Sorry to revive an old thread, but I was needing to do this exact thing and I wanted to share what I have been able to learn.

Once you use <cflog file="somefile.log", it will basically always do the same layout as defined in the class ClassicLayout.

However, you can define an appender, and use the pattern layout, to get a basic customization without using log4j (which i know i better, I just have other fish to fry today).

An appender like this should get you started:

  layout-arguments="pattern:[%d{dd MMM yyyy HH:mm:ss,SSS}] %-5p %m%n" 

Then, in your code, just be sure to do <cflog log="applog" and you will get the desired result in your log file.

One thing to note that I couldn’t figure out how to suppress was no matter what format you specify, you will get a “->” separator between your format and the desired message.

You can build your pattern string as following from:

1 Like