Month: April 2011

What is .bashrc


What is .bashrc ?

.bashrc contains the scripts that are executed when ‘BASH’ shell ( Bourne Again Shell ) is launched.  It basically contains the settings that must be enabled for a bash shell when it is launched. The ‘.bashrc’ exist at two levels ie one at the root level ( global one ) and another one at the user level ( ie shell settings specific for that particular user )

Global bashrc location : /etc/

User Specifc location : /home/username/

Ideally all your environment variables like JAVA_HOME should be set inside your .bashrc.

eg :

#Setting Java Home and Path Variable
export JAVA_HOME=/home/mindtree/java/jdk1.6.0_22
export PATH=$JAVA_HOME/bin:$PATH
export ODE_HOME=/home/mindtree/apache-ode-jbi-2.0-beta2
export RAPIDAPPSERVER_HOME=/home/mindtree/RCSBuildXMLFiles

Once you change the contents of .bashrc.  You need to execute the command

$source .bashrc

so that the changes take effect. If this doesn’t work, try starting a new terminal or a new tab within the existing terminal.

More on linux shell scripting @  http://www.arachnoid.com/linux/shell_programming.html

Cheers,

The Nonsense Blogger 🙂 🙂

Advertisements

log4j Application using Maven


First, the pom.xml that describes the Application build.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.arun.demo</groupId>
  <artifactId>DemoLogger</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <dependencies>
  	    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.6.1</version>
        <scope>runtime</scope>
    	</dependency>
  </dependencies>
</project>

Now the ‘log4j.properties’ file that should be placed in the ‘resources’ folder in the project.

#------------------------------------------------------------------------------
#
#  The following properties set the logging levels and log appender.  The
#  log4j.rootCategory variable defines the default log level and one or more
#  appenders.  For the console, use 'S'.  For the daily rolling file, use 'R'.
#  For an HTML formatted log, use 'H'.
#
#  To override the default (rootCategory) log level, define a property of the
#  form (see below for available values):
#
#        log4j.logger. =
#
#    Available logger names:
#      TODO
#
#    Possible Log Levels:
#      FATAL, ERROR, WARN, INFO, DEBUG, TRACE
#
#------------------------------------------------------------------------------

log4j.rootCategory=DEBUG, S, ALL, ERROR

log4j.logger.com.dappit.Dapper.parser=ERROR
log4j.logger.org.w3c.tidy=FATAL

#------------------------------------------------------------------------------
#
#  The following properties configure the console (stdout) appender.
#  See http://logging.apache.org/log4j/docs/api/index.html for details.
#
#------------------------------------------------------------------------------
log4j.appender.S = org.apache.log4j.ConsoleAppender
log4j.appender.S.layout = org.apache.log4j.PatternLayout
log4j.appender.S.layout.ConversionPattern = [%d{dd-MM-yyyy HH:mm:ss.SSS}] [%p] [%c]: %m%n

#------------------------------------------------------------------------------
#
#  The following properties configure the Daily Rolling File appender which includes all the log level messages.
#  See http://logging.apache.org/log4j/docs/api/index.html for details.
#
#------------------------------------------------------------------------------
log4j.appender.ALL = org.apache.log4j.DailyRollingFileAppender
log4j.appender.ALL.File = C:/Users/Arun/workspace/DemoLogger/AppLog.log
log4j.appender.ALL.Append = true
log4j.appender.ALL.DatePattern = '.'yyyy-MM-dd
log4j.appender.ALL.layout = org.apache.log4j.PatternLayout
log4j.appender.ALL.layout.ConversionPattern = [%d{dd-MM-yyyy HH:mm:ss.SSS}] [%p] [%c{1}]: %m%n

#------------------------------------------------------------------------------
#
#  The following properties configure the Daily Rolling File appender which includes all the log level messages.
#  See http://logging.apache.org/log4j/docs/api/index.html for details.
#
#------------------------------------------------------------------------------
log4j.appender.ERROR = org.apache.log4j.DailyRollingFileAppender
log4j.appender.ERROR.File = C:/Users/Arun/workspace/DemoLogger/AppErrorLog.log
log4j.appender.ERROR.Append = true
log4j.appender.ERROR.Threshold = ERROR
log4j.appender.ERROR.DatePattern = '.'yyyy-MM-dd
log4j.appender.ERROR.layout = org.apache.log4j.PatternLayout
log4j.appender.ERROR.layout.ConversionPattern = [%d{dd-MM-yyyy HH:mm:ss.SSS}] [%p] [%c{1}]: %m%n

Now the ‘DemoLogger.java’ file which contains the demo logging statements.

package com.arun.demo.logger;

import org.apache.log4j.Logger;

public class DemoLogger {

	/* Creating the static logger */
	static Logger logger = Logger.getLogger(DemoLogger.class);

	public static void main(String args[]) {

		int a=3,b;

		logger.debug("Test Debug Message");
		try {

			logger.debug("Before Exception");
			b=a/0;
			System.out.println("b : "+b);
		}
		catch(Exception e) {

			logger.error("Exception occured :"+e.getMessage());
		}

	}
}

Here all the logs are printed out on the console. They also get written on the rolling file ‘AppLog.log”. The ‘error’ level logs get written to ‘AppErrorLog.log’

Find below, the ‘Output grab’ from the console.

[15-04-2011 01:32:47.763] [DEBUG] [com.arun.demo.logger.DemoLogger]: Test Debug Message
[15-04-2011 01:32:47.789] [DEBUG] [com.arun.demo.logger.DemoLogger]: Before Exception
[15-04-2011 01:32:47.822] [ERROR] [com.arun.demo.logger.DemoLogger]: Exception occured :/ by zero

Find more on log4j at http://logging.apache.org/log4j/1.2/manual.html

Thanks,

The nonsense logger 🙂 🙂