views:

118

answers:

1

I cannot find back a library that allowed to format log output statements in a much nicer way than what is usually seen. One of the feature I remember is that it could 'offset' the log message depending on the 'nestedness' of where the log statement was occuring.

That is, instead of this:

DEBUG | DefaultBeanDefinitionDocumentReader.java| 86 | Loading bean definitions
DEBUG | AbstractAutowireCapableBeanFactory.java| 411 | Finished creating instance of bean 'MS-SQL'
DEBUG | DefaultSingletonBeanRegistry.java| 213 | Creating shared instance of singleton bean 'MySQL'
DEBUG | AutowireCapableBeanFactory.java| 383 | Creating instance of bean 'MySQL'
DEBUG | AutowireCapableBeanFactory.java| 459 | Eagerly caching bean 'MySQL' to allow for resolving potential circular references
DEBUG | AutowireCapableBeanFactory.java| 789 | Another debug message

It would shows something like this:

DEBUG | DefaultBeanDefinitionDocumentReader.java| 86  | Loading bean definitions
DEBUG | AbstractAutowireCapableBeanFactory.java | 411 | Finished creating instance of bean 'MS-SQL'
DEBUG | DefaultSingletonBeanRegistry.java       | 213 | Creating shared instance of singleton bean 'MySQL'
DEBUG | AutowireCapableBeanFactory.java         | 383 | Creating instance of bean 'MySQL'
DEBUG | AutowireCapableBeanFactory.java         | 459 | |__ Eagerly caching bean 'MySQL' to allow for resolving potential circular references
DEBUG | AutowireCapableBeanFactory.java         | 789 |     |__ Another debug message

This is an example I just made up (VeryLongCamelCaseClassNamesNotMine). But I remember seeing such cleanly formatted log output and they were really much nicer than anything I had seen before and, in addition to being just plain nicer, they were also easier to read for they reproduced some of the logical organization of the code.

Yet I cannot find anymore what that library was.

I'm pretty sure it was fully compatible with log4j or sl4j.

A: 

I see two things in your code samples:

  1. Padding of the classnames according to the longest name
  2. Messages modified depending on the "nesting".

For 1. I hardly see how this can be done, since you never know which class will log in the future. Sure, you can add padding according to the longest class name that has ever been logged, but the file will not look as nice as your sample once a longer class name is logged.

For 2. One could implement a filter (see here for logback documentation about filter) that would study the caller data and add some kind of "is nested in" prefix like you wrote in your example. This would not be too hard a task, I guess.

Hope this helps... although I do not provide you with the link to the lib you are looking for... :-(

Séb