Skip to main content

Posts

Showing posts from January, 2010

Writing custom FreeMarker template loaders in Spring

...or "Thou shalt not hard-code any output messages in Java code".

Code is for program, algorithm, behavior, action. Code in any programming language is intended to express the data flow, not the data itself! But many programmers are forgetting about this rule, putting lots of data, both input and output, in source code. While hard-coding input data instead of loading it from some external resource is easy to spot, hard-coded parts of the output data are even more common. Typical examples are:

Localized messages shown to the user. If you have a class with (...public static final...) strings containing different messages sent to the user, you might be proud of having all UI-specific labels in one place. Wrong! Changing messages require recompilation, as well as adding new translations (another classes?) Also all this strings are constantly present in the memory (PermGen space), being referenced by the class.Contents of exception messages. This is part of a bigger problem of err…

Logback-feed: publish your application logs using Atom/RSS feed

I assume you are familiar with RSS/Atom protocol, probably you are even reading this post using feed delivered by my blog. Atom and his older brother RSS are used to publish various materials (articles, posts) allowing users to monitor multiple web sites or blogs being up to date all the time. Can you see the advantages of this protocols arising when application logs come into play? Application might publish its own logs as Atom/RSS feed making them easily available for anyone with a web browser or feed reader.

Of course granularity of the information is essential: system administrator could subscribe for tech-critical events, like application restarts or some major failures. On the other hand business administrators might like to monitor the overall health of business processes, asynchronous tasks, etc. And everything with nice-and-easy user interface (see screenshots below) instead of not very friendly log files reading.

Publishing application logs using Atom or RSS protocol with Log4…