Christmas is almost here and if you listen carefully you can probably hear the jingling bells on Santa's sleigh.  If you listen even harder, you can hear the cries of anguish from CF developers around the world who's server won't boot and they need to track down the console log!  In this next installment of the 12 Tips of (CommandBox) Christmas, we've got some help.

Server Logs

Whenever a CF server starts, there's a log file that captures the output that would have been sent to the console.  This can differ based on your servlet container, whether you're using Lucee or Adobe CF.  In CommandBox, we put the server's "out" log in the same place and give you an easy command to spill the contents of the log file:

CommandBox> server log

If you've been starting more than one server by name in the same folder, you can request each log file via the name of the server just like the rest of the server commands.

CommandBox> server log server1
CommandBox> server log server2

Too much text?  No worries, just pipe that unruly output through the more command for pagination or the tail command to view the last X number of lines.  Note: even if you're on Windows you can still use features like tail in the interactive CommandBox shell since we emulate the most common and useful bash operations for you.

CommandBox> server log | more
CommandBox> server log | tail lines=100

But wait, there's more

We've also got some cool new features cooking up on the bleeding edge of CommandBox which we'll be releasing soon.  You can grab this pre-release version here.

The first new feature is the ability to live-stream the console output (as well as other useful debugging information) to the console as the server starts. Once the server comes up and we open the browser window, we'll stop streaming and return you to the command prompt.  To get this behavior, just use the --debug flag when starting your server.

CommandBox> server start --debug

Oops, you just started your server and forgot the flag, but now you want to watch it come up?  No problem, the server log command we covered earlier has a new trick up its sleeve.  Add the --follow flag to server log and you'll immediately begin tailing the server's console output until you press Ctrl-C to quit.  This feature defers a the new --follow flag on CommandBox's tail command which allows you to live-tail ANY file you wish including application logs.

CommandBox> server log --follow

And finally, if you want to simulate the old behavior of starting your CF server from the command line, where the process runs in the foreground until you stop it, you can do this as well with the new --console flag on the server start command.  This will start the CF server in the foreground and live-stream the output to the console for as long as the server is up.  To stop, press Ctrl-C and CommandBox will stop the server and return you to the command line.

CommandBox> server log --console