Hi, I’m trying to set the log levels for certain l...
# box-products
d
Hi, I’m trying to set the log levels for certain log files using cfconfig - specifcally setting the default logLevel for datasource.log / trace.log to Error in order to workaround the lucee bug which has set default for all log files to info 🤦 I can’t see how to configure this using cfconfg - is this possible?
c
There's a
loggers
struct, e.g.
Copy code
"loggers":{
	"datasource":{
      "level":"ERROR"
    }
}
👍 2
d
Thanks, that sorted it
b
@danlance Also keep in mind, many of the loggers used on a per-application basis are controlled by the logger settings in the web context, which can be surprising since the default
cfconfig import xxx
imports settings into the Lucee Server context by default.
d
ok, yeah updating datasource as per the above resolved the issue with Lucee vomiting SQL logs into datasource.log - but did nor stop similar behaviour to trace.log… Could that be due to the above? If so, how can I set trace.log settings within .cfconfig.json? currently have:
Copy code
"loggers":{
		"datasource":{
		  "level":"ERROR"
		},
		"trace":{
			"level":"ERROR"
		}
	}
b
@danlance Firstly, where is this log file? In the server context or the web context?
If you type
Copy code
cfconfig show loggers
cfconfig show property=loggers fromFormat=luceeWeb
you can see ALL your lucee logging settings (assuming there is only one web context)
d
Ok - so first gives me:
Copy code
CommandBox> cfconfig show loggers
{
    "application":{
        "appender":"resource",
        "appenderArguments":{
            "path":"{lucee-config}/logs/application.log"
        },
        "layout":"classic"
    },
    "datasource":{
        "appender":"resource",
        "appenderArguments":{
            "path":"{lucee-config}/logs/datasource.log"
        },
        "layout":"classic",
        "level":"ERROR"
    },
    "deploy":{
        "appender":"resource",
        "appenderArguments":{
            "path":"{lucee-config}/logs/deploy.log"
        },
        "layout":"classic",
        "level":"info"
    },
    "exception":{
        "appender":"resource",
        "appenderArguments":{
            "path":"{lucee-config}/logs/exception.log"
        },
        "layout":"classic"
    },
    "gateway":{
        "appender":"resource",
        "appenderArguments":{
            "path":"{lucee-config}/logs/gateway.log"
        },
        "layout":"classic"
    },
    "mail":{
        "appender":"resource",
        "appenderArguments":{
            "path":"{lucee-config}/logs/mail.log"
        },
        "layout":"classic"
    },
    "mapping":{
        "appender":"resource",
        "appenderArguments":{
            "path":"{lucee-config}/logs/mapping.log"
        },
        "layout":"classic"
    },
    "memory":{
        "appender":"resource",
        "appenderArguments":{
            "path":"{lucee-config}/logs/memory.log"
        },
        "layout":"classic"
    },
    "orm":{
        "appender":"resource",
        "appenderArguments":{
            "path":"{lucee-config}/logs/orm.log"
        },
        "layout":"classic"
    },
    "remoteclient":{
        "appender":"resource",
        "appenderArguments":{
            "path":"{lucee-config}/logs/remoteclient.log"
        },
        "layout":"classic",
        "level":"info"
    },
    "requesttimeout":{
        "appender":"resource",
        "appenderArguments":{
            "path":"{lucee-config}/logs/requesttimeout.log"
        },
        "layout":"classic"
    },
    "rest":{
        "appender":"resource",
        "appenderArguments":{
            "path":"{lucee-config}/logs/rest.log"
        },
        "layout":"classic"
    },
    "scheduler":{
        "appender":"resource",
        "appenderArguments":{
            "path":"{lucee-config}/logs/scheduler.log"
        },
        "layout":"classic"
    },
    "scope":{
        "appender":"resource",
        "appenderArguments":{
            "path":"{lucee-config}/logs/scope.log"
        },
        "layout":"classic"
    },
    "search":{
        "appender":"resource",
        "appenderArguments":{
            "path":"{lucee-config}/logs/search.log"
        },
        "layout":"classic"
    },
    "thread":{
        "appender":"resource",
        "appenderArguments":{
            "path":"{lucee-config}/logs/thread.log"
        },
        "layout":"classic"
    },
    "trace":{
        "appender":"resource",
        "appenderArguments":{
            "path":"{lucee-config}/logs/trace.log"
        },
        "layout":"classic",
        "level":"ERROR"
    }
}
and second gives me:
Copy code
CommandBox> cfconfig show property=loggers fromFormat=luceeWeb
{
    "application":{
        "appender":"resource",
        "appenderArguments":{
            "path":"{lucee-config}/logs/application.log"
        },
        "layout":"classic",
        "level":"info"
    },
    "exception":{
        "appender":"resource",
        "appenderArguments":{
            "path":"{lucee-config}/logs/exception.log"
        },
        "layout":"classic",
        "level":"info"
    },
    "mail":{
        "appender":"resource",
        "appenderArguments":{
            "path":"{lucee-config}/logs/mail.log"
        },
        "layout":"classic"
    },
    "remoteclient":{
        "appender":"resource",
        "appenderArguments":{
            "path":"{lucee-config}/logs/remoteclient.log"
        },
        "layout":"classic",
        "level":"info"
    },
    "requesttimeout":{
        "appender":"resource",
        "appenderArguments":{
            "path":"{lucee-config}/logs/requesttimeout.log"
        },
        "layout":"classic"
    },
    "scheduler":{
        "appender":"resource",
        "appenderArguments":{
            "path":"{lucee-config}/logs/scheduler.log"
        },
        "layout":"classic"
    },
    "trace":{
        "appender":"resource",
        "appenderArguments":{
            "path":"{lucee-config}/logs/trace.log"
        },
        "layout":"classic"
    }
}
Datasource is just in first and not in web, but trace is in both, and the setting I’ve applies only applies to the server one…
Presume that’s why it’s apparently made no difference
So how do I using cfconfg.json set the web trace.log to be ERROR level?
@bdw429s
b
Yep, try updating the web context and see if that controls the log file in question, which BTW, you still haven't told me where it lives! https://cfml.slack.com/archives/C06TSRXCJ/p1686150598147459?thread_ts=1686144749.183639&cid=C06TSRXCJ
d
I thought that was the purpose of the above commands?
b
nope
I also didn't necessarily intend for you to just dump the output here. Use it to solve your problem 🙂 \
The log file I asked was in reference to the log file you say is filling up with entries. Where exactly is it located on your hard drive?
d
Soory mate - 3 days of debugging Lucee can leave me somewhat trigger happy…
b
So how do I using cfconfg.json set the web trace.log to be ERROR level?
Well, firstly, I would just swap it in the admin real quick to know if it even is the setting you want! We can add it to CFConfig next if that actually solves your issue
d
Trace log:
/usr/local/lib/serverHome/WEB-INF/lucee-web/logs/trace.log
Datasource log:
/usr/local/lib/serverHome/WEB-INF/lucee-web/logs/datasource.log
i.e. both are within the same folder
b
As far as "how do you use cfconfig..." that's a very broad question as CFConfig has about 30 different ways it can set config for you 🙂 • environment variable conventions • file system conventions • server.json conventions • set commands • specific logging commands It's really impossible to tell you what you need to do without knowing how you're using CFConfig in the first place
lucee-web/logs/datasource.log
i.e. both are within the same folder
More importantly, both are in the web context! I would expect the web setting to control this file
d
Ok - although lucee admin is locked up tighter than a nun’s… wallet… and setting a setting in server.json is just a matter of doing a docker build… so lucee admin is considerably harder to access
b
ok, fair
Can you just set settings and restart Lucee?
Or does it have to be loaded in from a JSON file when Lucee first starts?
d
everything we set in cfconfig.json or server.json - and then do a docker build locallly
b
This is another reason Docker makes everything harder for local dev 😕 Just using CommandBox directly allows you to easily swap the
profile
of your server over to
development
and access the admin
You may be able to get away with just testing this en var
Copy code
cfconfig_web_loggers_trace_level=error
d
ok - can give that a shot - is there an equivalent though cfconfig.json?
b
If that works, and assuming you're using the file conventions, you'll prolly want to create a
.cfconfig-web.json
file with your web settings, as documented here https://cfconfig.ortusbooks.com/using-the-cli/commandbox-server-interceptors/server-start#.cfconfig.json-file-in-webroot
I really recommend reading through the docs. They're not long and will teach you a lot 🙂
The env var name above BTW is is constructed by convention. You can effectively set any setting via env vars if you know the pattern
d
weird how the setting as currently applied works on datasource and not on the trace.log when they are in same location - is this just a Lucee thing, or is there any known logic?
b
And if you're not using the file name conventions, and configuring specific JSON files in your
server.json
, then you can configure the path to the web file in your
server.json
, as documented here: https://cfconfig.ortusbooks.com/using-the-cli/commandbox-server-interceptors/server-start#server.json-properties
weird how the setting as currently applied works on datasource and not on the trace.log when they are in same location - is this just a Lucee thing, or is there any known logic?
Who the freak knows, lol. Depends on where the code is that's running. Is it part of a .cfm page or part of Lucee that's dealing with sessions or something at the server level? Lucee also used to not inherit any logger setting from the server context to the web context. I put in a ticket a long time ago which may have possibly been resolved, but I don't know if it was ever fixed
Man, I can't even find the ticket-- that may have been back in the Railo days 🤔
d
Ultiametly trying to implement a QUICK workaround for a bug in Lucee - which is fixed in later (non release) versions and which is locking one of our client apps 2-3 times pre day For soem reason they decided to set default log level for all log files to info - so anyone using cfconfig and not setting files explicitly… needs some vaseline… GB of sql being written to log files on one of our apps… together with a bug which causes locking whenever the log files rollover…. Been a fun week
b
Yeah, sounds pretty terrible 😕
d
it sounds 🤦
b
Well, once you get the right CFConfig magic in the right JSON file, hopefully things will improve
Pro tip: watch the verbose output of the docker logs from when the server starts up and you'll see a CFConfig section in there that shows yoiu • what JSON files were loaded • what env vars were sucked in and used
👍 1
It's a great way to know your config is getting picked up
d
Already deployed the datasource stuff - slow sql heavy sections have improved 3-6 times in perf and log files not filling up trace log would be good to fix as well - as there should never be inline logging within a SQL transaction… or at least not unless debugging a world ending issue locally… 🤦
b
Ok, well let me know if the suggestions above don't fix the trace log as well
d
yep - the env var override sorted it. Looking at the .cfconfig-web.json. docs… looks pretty straightforward - will try that now…
👍 1
Ok - so flicking through carefully reading the docs, I’m not quite clear on the following: Will env vars (such as
cfconfig_web_loggers_trace_level
) take precedence over equivalent setting set in .cfconfig-web.json ?
b
@danlance The bottom of the first section here covers that https://cfconfig.ortusbooks.com/using-the-cli/env-var-overrides
Copy code
Overridden env vars will not be written to any .cfconfig.json file and will be lost when box stops. They will also take precedence and override any explicit settings already set.
So, env vars are the last thing to be applied and always have the last say over any config files (which is typical behavior for env vars in Docker in general)
The idea being you can configured your default settings in the container's JSON files and then always have the option to override any bits you want when running the container
d
Yep - the sensible and logical approach… just not one everyone follows 😕
b
Note, env var values can also contain JSON so you can overwrite complex keys too.
Copy code
cfconfig_web_loggers_trace={"appender":"resource","appenderArguments":{"path":"{lucee-config}/logs/trace.log"},"layout":"classic","level":"INFO"}
is the functional equivalent to setting each of those pieces in separate env vars as
Copy code
cfconfig_web_loggers_trace_appender=resource
cfconfig_web_loggers_trace_layout=classic
cfconfig_web_loggers_trace_level=INFO
cfconfig_web_loggers_trace_appenderArguments_path={lucee-config}/logs/trace.log
d
Thanks Brad, much appreciated. The logical thought and consideration which has gone into the planning of CFConfig - and other Box products - is refreshing to work with compared with some other products I have the pleasure of using on a regular basis…
😁 1