Enabling access logs in server.json is easy enough...
# box-products
b
Enabling access logs in server.json is easy enough but can the location be defined by server.json as well? I'm not seeing anything for it.
b
@bhartsfield The lack of options to control the access log mostly comes from • no one ever really asking for • trying to keep things simple
b
I'll take that as a no šŸ™‚
b
The directory the access log is written can be set in Runwar with
--logaccess-dir
, but CommandBox automatically sets it for you using the same folder as the server out log, which is hard-set to the root of the server home. There is a setting in the JSON file, but it's never been used: https://ortussolutions.atlassian.net/browse/COMMANDBOX-1257 The name of the access log file can be set in Runwar with
--logaccess-basename
but it's also hard-coded in CommandBox to be called
access
The suffix of the log file is defaulted in Runwar to
txt
and there is no setting in place currently to override it.
I'd welcome a pull to be able to set these, but the same is true of • the out log • the access log • the rewrites log And that's like 9 new settings in the JSON to make them all configurable.
šŸ‘ 1
you'd think it would just be one setting with the full path, but the underlying Undertow feature requires all three pieces to be passed in separate
Copy code
DefaultAccessLogReceiver requestsLogReceiver = DefaultAccessLogReceiver.builder().setLogWriteExecutor(logWorker)
                    .setRotate(true)
                    .setOutputDirectory(options.logRequestsDir().toPath())
                    .setLogBaseName(options.logRequestsBaseFileName())
                    .setLogNameSuffix(options.logSuffix())
                    .build();
b
server show runwar.args
doh... lol
b
if you want to overridde the default, make sure you turn off CommandBox's built in flag for access logs, or it will conflict
This is basically what kicks in when you enable it
Copy code
if( serverInfo.accesslogenable ) {
			args
				.append( '--logaccess-enable' ).append( true )
			 	.append( '--logaccess-basename' ).append( 'access' )
			 	.append( '--logaccess-dir' ).append( serverInfo.logDir );
		}
So you'd be supplying those yourself.
b
ah gotcha
b
Also, commands like
Copy code
server log --access
would no longer work
because CommandBox currently makes assumptions about what the file will be called. That would need to be made more dynamic in the event we allow the user to change it.
Copy code
serverInfo.accessLogPath = serverInfo.logDir & '/access.txt';
b
im perfectly ok with the file name, just want to get the logs writing to another drive (without worrying whether or not someone created symlinks on new servers)
runwar args worked!
b
Cool, just remember I don't document most of them on purpose because I reserve the right to change the at any time šŸ˜‰
b
uh oh lol
spoke too soon... runwar args fail with relative paths (which I wanted to use in local dev but absolute paths everywhere else)
full, absolute paths work fine
b
Yeah, runwar itself is never going to have a concept of relative paths
That's all magic CommandBox does before passing it off
šŸ‘ 1
But there's ways to make your JSON dynamic with env vars
b
its using env vars now. I just wanted ../logs in local dev
not a huge deal
b
Something like
${serverinfo.webroot}
will probably do what you need
b
not sure how I'd use that in server.json without it ALWAYS being ${serverinfo.webroot} (which is fine in local dev but not elsewhere)
I have an env called LOG_FILE_ROOT that is ../logs/ in dev but something like E:/path/to/logs everywhere else.
and this in server.json (now)
Copy code
"runwar":{
        "args":"--logaccess-enable true --logaccess-basename access --logaccess-dir ${LOG_FILE_ROOT}"
    }
starting to lean (back) towards a reverse proxy through IIS and letting it handle request logs (just can't use boncode this time because they do not support PATCH requests)
b
Question, do you actually need the access logs for local dev?
b
good point. No.
b
On a mostly unrelated note, the latest version of CommandBox now allows your args to look like this:
Copy code
"runwar":{
      "args": [
        "--logaccess-enable=true",
        "--logaccess-basename=access",
        "--logaccess-dir=${LOG_FILE_ROOT}"
      ]
    }
šŸ‘ 1
Same with JVM args. Can be a string or an array.