Is there a *native* way to add log file config to ...
# lucee
a
Is there a native way to add log file config to lucee other than a) via the admin ui; b) hacking the
lucee-server.xml
file directly c) using
<cfadmin>
which I... think... is not really supposed to be something user-land is supposed to use? Can't use cfconfig or anything to do with commandbox in this situation, unfortunately.
Failing that, if I go
<cflog file="whatEvs">
in CF, CF just goes "oh yeah, that file doesn't exist but I guess it's the first time they're using it so I'll create if for them. It's pretty obvious that'll be what they want here". The Lucee docs for
<cflog>
claims that the
file
attrib is not implemented in favour of just using
log
, but the
log
option needs the log to already be configured. So: not really the same. But is there any way to get Lucee to go "oh yeah, that file doesn't exist but I guess it's the first time they're using it so I'll create if for them. It's pretty obvious that'll be what they want here" rather than "NEIN! YOU MUST CONFIGURE IT FIRST!!!"
Oh... apparently
<cfadmin>
doesn't handle log config anyhow 😕 (ref: https://docs.lucee.org/guides/Various/cfadmin.html)
b
I'm sure cfadmin does since everything in the admin is powered by it. Of course, there are no docs for CFadmin, so...
If you can wade through the Lucee admin CFM files you can find whatever page saves the log settings
I'm not aware of any other method- but I had always just assumed cflog would create whatever you needed.
a
yeah I can't be arsed checking now, but I seem to recall
<cflog log="somethingAlreadyConfigured">
and
<cflog file="adHocFileName">
on CF. Lucee decided not to implement the latter it seems. Kinda seems like a CF compat bug now that I am annoyed by the situation 😉
If you can wade through the Lucee admin CFM files
Dude I thought we were mates. Don't suggest I self-harm like that.
😆 1
We decided for v1.0 of our requirement we'll just sling the stuff into the application.log file and be done with it: that's fine for MVP. We'll revisit later.
OK I'm back on needing to know how to manage log file settings programmatically. Reactivating this thread in case someone has a clue and didn't see this before. I was not able to find in the source code anywhere that
<cfadmin>
or (any other mechanism) was maintaining these settings. Obvs they're being maintained somehow, but I guess my patience for grokking how Lucee's source code works is not... erm... enough. I will try again though.
Solved the issue of managing log file settings programmatically: https://blog.adamcameron.me/2022/08/lucee-creating-log-file-programmatically.html
Short version:
Copy code
local.admin = new Administrator("web", server.system.environment.ADMINPASSWORD)
admin.updateLogSettings(
    name = "AdamTest",
    level = "ERROR",
    appenderClass = "lucee.commons.io.log.log4j2.appender.ResourceAppender",
    layoutClass = "lucee.commons.io.log.log4j2.layout.ClassicLayout",
    appenderArgs = {
        maxfiles = 20,
        maxfilesize = 1073741824
    }
)
writeLog(log="AdamTest", type="ERROR", text="ERROR SHOULD BE LOGGED")
writeLog(log="AdamTest", type="INFO", text="INFO SHOULD NOT BE LOGGED")
c
I've been doing it by hacking the XML using `XmlParse()`etc, but that requires an engine restart to reload the config. This is better.