Request logs rolling with suffixes from Jetty

It seemed simple enough. The goal: get jetty to log requests to a file such as request.log and rotate that file on a daily basis to something with a suffix.

By default Jetty wants to rename request logs something like mm_dd_yy_request.log, this is all well and good, but it complicates the logic of any tool you might use to sync and remove log files. For example log4j's RollingFileAppender will append numeric suffixes like .1 to the end of logs it has closed and rotated out, but with Jetty's default configuration, one has to get a little tricky to figure out what request log is still open. It's not as easy as grabbing request.log.* to grab the out-of-rotation logs.

I discovered the solution in the code of RolloverFileOutputStream, the class in jetty-util that Jetty's NCSARequestLog class uses internally to write the log files. When logfile appending is turned off and RolloverFileOutputStream attempts to open a new log where a file with the same name already exists, RolloverFileOuputStream will rename the existing file by appending the date, format specified by the system property ROLLOVERFILE_BACKUP_FORMAT, to the existing logfile name. This means that the request.log is the live, open log and files named like request.log.yyyyMMdd-HHmmss are the logs that are out of rotation.

So to achieve this, modify the RequestLog entry in jetty.xml to look like this:

    <Ref id="RequestLog">
      <Set name="requestLog">
        <New id="RequestLogImpl" class="org.mortbay.jetty.NCSARequestLog">
          <Arg><SystemProperty name="jetty.logs" default="./logs"/>/request.log</Arg>
          <Set name="retainDays">31</Set>
          <Set name="append">false</Set>
          <Set name="extended">false</Set>
          <Set name="LogTimeZone">GMT</Set>
          <Set name="ignorePaths">
            <Array type="java.lang.String">
              <Item>/solr/ping</Item>
            </Array>
          </Set>
        </New>
      </Set>
    </Ref>

And at starup of your jetty instance, do something like:
java -DROLLOVERFILE_BACKUP_FORMAT=yyyyMMdd-HHmmss -jar start.jar
And Viola! New log messages are written to request.log and logs are rolled out to request.log.somenicesuffixhere.

As for the ignorePaths stanze in the configuration above, you probably don't need it in your configuration. It's handy for me to skip logging health checks.

Also as for syncing the logs off the individual machines they're written to, rsync's --remove-sent-files option is pretty handy.

My new Dell Studio 15's laptop screen is great. It is bright, and by bright I mean that on full brightness I can use it outside on a sunny day with my sunglasses on and still read the screen comfortably. This brightness is great except for cases when I don't want it so bright, like when I'm working in a darker room. One night I discovered that the lower third of my vision had a dark blind spot after doing some work while watching a movie. That can't be good.

Problem is, I don't always remember to adjust the brightness, and from what I can tell, it always boots into Ubuntu af full brightness, so I dug around for a way to change the brightness automatically. Thanks to google I found a post over on LinuxScrew that talks about changing the brightness for a dell inspiron 1501. Turns out the Studio 15 has a similar method using /proc. Cat'ing the file shows me the acceptable brightness levels:

# cat /proc/acpi/video/M86/LCD/brightness 
levels:  6 12 18 24 30 36 42 48 54 60 66 72 78 84 90 100
current: 100

Echo'ing something to the file (as root) sets the value:
# echo -n 18 > /proc/acpi/video/M86/LCD/brightness 

There's lots of places to go with this, but for now I'm going to pop it into rc.local and run with it.

No more blind spots, excellent.
top