Log4j 4 Enterprise
Logging is an important part of any application. Logging provides debugging information, the state of the application, and a record of what happened when the application failed. As applications increase in size so does the demands and complexity of logging. Without a proper logging system it can become difficult to determine from where in an application a log statement is being executed and without an easy way of changing logging behavior it can have a negative effect on an application's performance.
The Apache Foundation maintains the log4j project which is an easy to use system that provides a large array of really cool features for logging. This tutorial, part of my dev environment series, is an introduction into using log4j in an enterprise setting. Topics that I will cover include; implementing log4j in a project, customizing the log statement, usage of appenders, creating loggers and logger inheritence, and setting up log4j to work on an application server. This will cover many of the basic needs of enterprise logging.
A few simple steps before we begin...
As with all my tutorials that involve coding you can download the source code here. In this example I will be using the project HttpExample, starting on revision 24. If you want to work on this code locally you will also need the log4j library which can be found here, and then add it to your project's classpath by right clicking on your project > build path > add external libraries and then navigate to the library's location (if you are using eclipse).
Web developers should hate http
I don't mean that literally, what I do mean is a web developer should hate when Java's http specification is directly accessed in the code. This is a topic I briefly touched on in my 8 signs your code sucks post awhile back. I decided to return to this topic because it touches on a very important and fundamental programming practice which is limiting dependencies in code. This article represents the initial entry into a new series I plan on covering called "Java don't care." As aforementioned this series will focus on reducing dependencies in code, as well as making your code less aware of the environment it is in, and how following these practices will help you as a developer. But back to the task at hand; why referencing Java's http specification is bad.
An intro to writing ANT Scripts
What is Ant?
A(nother) N(eat) T(ool) is a tool developed by the Apache Foundation for automating tasks in a project. It is primarily, though not exclusively used for Java projects. Most developers interaction with ant is through the xml specification, which is used to define specific operations.
The objective of this tutorial
Ant was designed with adaptability and expandability in mind, as a consequence it is used for many tasks and in many systems. As we get deeper in the dev environment series we will rely heavily on ant to make our lives easier and to carry out many important functions. For this tutorial however I will go cover what ant is primarily used for, building a project and creating a deliverable, in this case a jar file. This will provide a good intro into the usage of ant and how it works.
An Intro into Test Driven Development with JUnit4
Please read the technical guide before starting this tutorial.
This article will mark the first of a long-term series covering professional software development. For the lowdown on this project check out this article. Be sure to give me your feedback as it will be vital in helping me develop better tutorials in the future.
Test driven development seemed like a natural choice as a lead off to my series of tutorials as I had to explain why I am writing all these tests. It is also a very good development methodology that will actually save a lot of time by reducing the amount of time spent debugging. For this tutorial and the entire project, I will be using Junit4. For a synopsis on test driven development you can check out the wikipedia article here. If you need a brief refresher on JUnit you can read my tutorial here (written in Junit3).
Link Dump 10/13
http://www.codeigniter.com – An excellent and lightweight framework for developing PHP applications
http://sites.google.com/site/yacoset/ - I may not agree with everything the author says and frankly he probably doesn't care. But there is plenty of good information on his site none the less.
http://solitarygeek.com/ - If you like my site then you will probably love this one. Similar in writing style and purpose, just a more mature blog written by a more experienced developer.
Link Dump 10/6
http://sourcemaking.com/ - Co-authored by Martin Fowler, a bunch of useful information and best practices on this site.
http://www.pbell.com/index.cfm/design-patterns -A wealth of information covering many different areas of programming. Definitely something here for everybody.
http://marxsoftware.blogspot.com/ - A well established blog with hundreds of articles covering mostly Java.
Link Dump 9/28
http://www.javaworld.com/ - An excellent Java resource
http://onjava.com/ - A blog covering java (obviously) supported by O'Reilly Media
http://martinfowler.com/ - The website for one of the most respected voices in OO-development
If, else and nothing else
When I was still very new to programming I had a bad habit of writing bloated code. One of my worse areas was when it came to the usage of If statements. Often times I would write a whole if/else block when I could had just as easily gotten the same results in just one line of code.
Foreach isn’t a reach in pre-1.5
Developers living in the post 1.5 world are spoiled. With the very sweet foreach loop life is easy when you need to iterate through a list of objects. While us poor developers still living working with 1.4 or lower may not be able to totally match the 1.5 foreach loop we can certainly come close! While there are several ways to implement foreach functionality in 1.4 or below I will focus on the way I prefer to do it as I think it is the best way.
Link Dump 9/17
http://www.sixrevisions.com/ - A very active website that focuses on web design.
http://www.net.tutsplus.com/ - Has excellent tutorials on web design and development
http://java.sun.com/blueprints/corej2eepatterns/Patterns/index.html – An absolute must check out for all Java developers. Focuses on best practices for Java developers. Though I wouldn't recommend it for the very new as the concepts may be a bit advanced.
http://www.ohloh.net/ - A very good place to start if you are looking to contribute to an open source project.
