Log4j Tutorial : How to send log messages to different log files?

One of the common requirement in Java projects, that are using Log4j logging, is to have different log files for each module (or layer) in the project. For example, if you have a web application, you may want to log the debug/info messages from the service layer to a service.log file and the log messages from the presentation layer to the web-app.log file and so on. This is very simple to achieve in Log4j.

Continue reading

Using Log MDC in multi-thread – Hello World example

The slf4j has MDC which will  delegate to underlying logging system’s MDC implementation.  The most popular logging systems are log4j and logback. They both support MDC. So the most common way to use MDC (or logging system) is through slf4j API. In this demo, logback is used as underline logging system.

What can MDC (Mapped Diagnostic Context) do for me?

MDC is a map like structure, it can save information you want to output to the log, so you don’t need add that information to every logger.info(…) as parameter. For example, in an web application, you want every log output contain http request source IP. The IP string don’t need to be added to every logger call , or passed back and forth between controller and service layers. You should save that IP in the MDC, and use %X{IP} in log configuration to add that value to every line of your log output.

Continue reading

Uploading files with Curl

I’ve always trouble uploading files with Curl. Some how the syntax for that command won’t stick, so I post it here for future reference.

What I want to do is perform a normal POST, including a file and some other variables to a remote server. This is it:

curl -i -F name=test -F [email protected] http://example.org/upload

You can add as many -F as you want. The -i option tells curl to show the response headers as well, which I find useful most of the time.

Using vpnc as a Command Line VPN Client

In many enterprises, Cisco VPNs are used to give remote developers controlled access to production web servers. This allows machines in far-flung locations to operate as if they’re on the same controlled network, making security and management much easier for the network administrators. For the remote developers, on the other hand, things aren’t always so smooth. VPN clients are built into most desktop operating systems, making manual connections relatively simple. However, the GUI software for connecting to a VPN can sometimes be buggy or difficult to use. In addition, it’s often useful to connect remote servers to a VPN; since they rarely have a GUI installed, the familiar VPN connection tools are missing.

Continue reading

Install Let’s Encrypt SSL Certificate in a Shared Hosting

Let’s encrypt lets you to get https for your website for completely free. It’s the easiest way to get SSL certificate free of cost which will be recognized by major browsers. This tutorial goes through the steps that need to be done to get and setup a free SSL certificate for your shared cPanel hosting. Even though we are talking about cPanel, it’s not exclusively only for cPanel users, the way described here to get the certificate will work for other cases too if the required conditions are met (which are necessary in all cases).

Continue reading