Skip to main content

SL4J and parameterized messages

It's common to log messages that contain run-time information. In Java, this is easier if you use SL4J instead of log4j.


Here's a useful snippet from http://javarevisited.blogspot.com/2013/08/why-use-sl4j-over-log4j-for-logging-in.html

This is how you would do in Log4j, but surely this is not fun and reduce readability of code by adding unnecessary boiler-plate code.


if (logger.isDebugEnabled()) {
    logger.debug("Processing trade with id: " + id + " symbol: " + symbol);
}


On the other hand if you use SLF4J, you can get same result in more concise format as shown below:


logger.debug("Processing trade with id: {} and symbol : {} ", id, symbol);


In SLF4J, we don't need String concatenation and don't incur cost of temporary not need String. Instead, we write log message in a template format with placeholder and supply actual value as parameters.



Comments

Popular posts from this blog

Running 2560x1080 on LG 29UM57-P on an old MacBook Pro OSX El Capitan

Yes. A mid-2011 MacBook Pro running OSX El Capitan can drive a 2560x1080 monitor via HDMI.
I was not able to get 60 Hz working. I am settling with 53 Hz. I tried many settings before finding something that works. The refresh rate seems fine to me. Maybe the text could be clearer but for a $200 monitor running this resolution, I'll take it. Apple MacBook 2015 retina resolution is 2560 x 1800. Consider buying a better monitor that may literally give you fewer headaches. Install SwitchResXFollow the instructions for disabling SIPAfter rebooting, run SwitchResX via System PreferencesSelect your LG monitorClick Custom ResolutionsClick the + icon Enter these settings (source)Exit SwitchResX and saveRebootRun SwitchResX via System PreferencesSelect your LG monitorClick Current ResolutionsSelect the 2560x1080, 53 Hz settingEnable SIPIf you discover better settings, please leave a comment.

Collecting and graphing metrics via Apache Camel, Statsd, and Graphite

If you're curious about Apache Camel's metrics reporting via Dropwizard, this guide will help you get Graphite running in a Docker container. Then you will run an instrumented Camel application and view its metrics via Graphite's browser UI.

(1) Install Docker

There are many ways to do this depending on your platform. Google it.

(2) Install and run the Docker container for Statsd and Graphite

Refer to https://github.com/hopsoft/docker-graphite-statsd

The instructions infer that you can run the container without specifying port mappings. This is plain wrong. So use the following command to start the container:

docker run -d --name graphite --restart=always -p 80:80 -p 8125:8125/udp hopsoft/graphite-statsd It is not necessary to enable Graphite's UDP listener. Statsd receives metrics via UDP and forwards them to Graphite over TCP. (3) On Windows and OSX, determine the IP address of the graphite Docker container

On Linux, you can use localhost.

On Windows and OSX, there are…

As California Burns

For the past week, San Franciscans have been wearing respirators to protect their lungs from California's burned carcass in the sky.

Some of the particulates were once human flesh and expensive multi-story homes. Some were paint, pesticides, car batteries, and insulation.

One in five people are wearing masks matter-of-factly. No hysterics. No protests. No mention of the motherfuckers who brought catastrophic runaway climatic heating to our state, burning Californians alive without any warning.

What will Kamala Harris and Dianne Feinstein do after the cadaver dogs leave Paradise? They'll do the same as Repiglicans. They'll do what they've done their entire careers. They will say and do nothing to save us. That’s why they’re senators.