I already talked a bit about Slf4j, as a recommended interface to any implementor logger.
I have already talked about Lombok, and the fantastic way it creates java bytecode in compile time in order to make you safe some time.
Now let's reduce the time and code we need in almost every class:
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LogExample.class);
with:
@Slf4j
That's all, put that annotation in your class, and you'll have your logger, with name "log", referring that class, and using Slf4j interface. Simply perfect ;)
If you are still a log4j lover, or maybe for other loggers, Lombok provides these annotations:
@CommonsLog
Creates private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(LogExample.class);
@Log
Creates private static final java.util.logging.Logger log = java.util.logging.Logger.getLogger(LogExample.class.getName());
@Log4j
Creates private static final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(LogExample.class);
More information here!
See you soon..
This blog is written for teaching about Java technologies and best-practices. I will talk about patterns, Maven, J2EE, Artifactory, Hudson, Sonar, and so on.
Mostrando entradas con la etiqueta lombok. Mostrar todas las entradas
Mostrando entradas con la etiqueta lombok. Mostrar todas las entradas
lunes, 25 de julio de 2011
domingo, 10 de julio de 2011
Lombok, cleaning up your code
Much time without writing, ok, I have been working hard in company projects a bit, and the rest of the time trying to improve our tools and processes.
I want to introduce you to "Lombok", a nice tool that could bring light to the darkness of certain classes everyone has seen at least once.
The gain in this case is almost out of discussion, you annotate your code and magically it gets powers and kicks the ass to the bad guys. They are not dependencies and either aspects, because Lombok works in compilation time almost always. Indeed, inclusion of lombok.jar is not necessary in all cases, a few ones doesn't need it.
Some examples from their web:
@Getter and @Setter, it is like using Eclipse "generate getter and setter automatically" but Lombok does even easier and cleaner:
turns in
Those changes are made in compiled bytecode, although you can decompile this changes (delombok) and see them in Java.
Another example, let's avoid the tricky and ugly closing file even inside and exception catch.
turns in
More: automatic log declaration
turns in
(Several implementations of log are provided).
And so on and on... check the features list
http://projectlombok.org/features/index.html
This tool is also integrated with Eclipse (through installation) and Eclipse (only by including it as a dependency). Use it wisely, but use it :)
I want to introduce you to "Lombok", a nice tool that could bring light to the darkness of certain classes everyone has seen at least once.
The gain in this case is almost out of discussion, you annotate your code and magically it gets powers and kicks the ass to the bad guys. They are not dependencies and either aspects, because Lombok works in compilation time almost always. Indeed, inclusion of lombok.jar is not necessary in all cases, a few ones doesn't need it.
Some examples from their web:
@Getter and @Setter, it is like using Eclipse "generate getter and setter automatically" but Lombok does even easier and cleaner:
|
turns in
|
Those changes are made in compiled bytecode, although you can decompile this changes (delombok) and see them in Java.
Another example, let's avoid the tricky and ugly closing file even inside and exception catch.
|
turns in
|
More: automatic log declaration
|
turns in
|
(Several implementations of log are provided).
And so on and on... check the features list
http://projectlombok.org/features/index.html
This tool is also integrated with Eclipse (through installation) and Eclipse (only by including it as a dependency). Use it wisely, but use it :)
Suscribirse a:
Entradas (Atom)
Etiquetas
maven
logstash
vrr
logback
json
matrix
artifactory
cis
configuration
CheckStyle
developers
devops
filebeat
ops
elasticsearch
importance
installation
java
priority
severity
tomcat
SpringSource
book of the month
critical
debug
important
log
low
plugin
What if
code repository
curator
dependencies
essential readings
essentials
structured arguments
Eclipse
Formatter
Tunning
apache
basic
best practices
codegen
continuous deployment
continuous integration
contract-first
deploy
gradle
jenkins
kibana
lombok
manager
nexus
opinion
performance
persistence
pom.xml
slf4j
storage
svn
testing
401
409
ChekStyle
Error
Homogeneous
JavaMelody
Managing
Monitoring
Scrum
Solution
Style
Trenches
XP
advantages
algorithm
ansible
architecture
aws
bitbucket
cabotrafalgar
cd
chargers
cheap
chef
ci
comparison
cons
cow
cvs
dependences
disk
distribution
docker
docker-compose
documentation
eb
ecs
elastic
elk
ender's game
enforcing
essential tools
estimation
external
fail
findbugs
folders
git
github
grok
html
hudson
ide
inheritance
javadoc
jcl
jmr
jmx
kv
libvirt
lifecycle
load
log4j
logbacl
logger
low cost
mdc
memory
multiple files
mysql
nature
nifty-gui nifty-flow
organization
permissions
pmd
pragmatic programmer
profiles
pros
puppet
q outside the office
release
remote
reporting
save
security
several files
simulated annealing
site
snapshot
sonar
standard
strategies
stress
suppressions
surveillance
tale
throughput
unit
upload
usvn
vagrant
versioning
war
wires