Wednesday, December 12, 2012

Logging Best Practices


Declaring a logger

private static final Logger LOG = Logger.getLogger(MyClassName.class.getName())

Log Levels

TRACE

In general, trace-level logging should be used only for tracing the flow of execution through a program and for flagging particular positions in a program (i.e. to ensure they have been reached). While you may want to trace every method of a class in early stages of development, you should ensure that you are only tracing key aspects of the flow when it is time to pass the code onto other developers. An overabundance of TRACE statements (especially in simple getter and setter methods) can hinder others rather than help them.

Entering a method

public void myMethod(){
     if(LOG.isTraceEnabled()){
          LOG.trace(">> myMethod()");
     }
    ...

Exiting a method

     ....
     if(LOG.isTraceEnabled()){
          LOG.trace("<< myMethod()");
     }
}


Constructors

public OntModelService(){
    if(LOG.isTraceEnabled()){
        LOG.trace("** OntModelService()");
    }
}

DEBUG

Use DEBUG to report results to yourself and other developers

INFO

Use INFO to report results to Administrators and Users

WARN

Dangerious for the application but do not interup the execution

ERROR

Application can no longer continue to work correctly

USING ENVIRONMENT FILE in log4j.properties


1. Define a parameter in the log4.properties e.g. 

log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=${log.path}/logs/myApp.log 
log4j.appender.R.MaxFileSize=500MB
log4j.appender.R.MaxBackupIndex=1000
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d{ISO8601}[%-5p] - - [%X{sessionId}](%C.%M.java:%L) - %m%n

2. AND set the following JVM Parameter on the Server (this is JAVA_OPT in catalina script)

-Dlog.path="c:/temp/"

You can also set this variable as a JAVA_OPTS environement variable.This variable will be read by tomcat automatically and will be given to the JVM as parameter
Linux Example:
           
         set JAVA_OPTS="$JAVA_OPTS -Dlog.path=/logs/temp/"


Windows Example:

        set JAVA_OPTS=%JAVA_OPTS% -Dlog.path=c:\logs\temp\


Some other log4j best practices are here : http://juliusdavies.ca/logging.html

Hibernate : Enable Logging of the SQL Statements

Define a seperate appender

         name="SQL" class="org.apache.log4j.DailyRollingFileAppender">
                 name="File" value="c:/logs/sql.log" />
                 name="Append" value="false" />
                 name="Threshold" value="TRACE" />
                 name="DatePattern" value="'.'yyyy-MM-dd" />
                 class="org.apache.log4j.PatternLayout">
                         name="ConversionPattern" value="%d{ISO8601} %-5p [%c] %m%n" />
                
        
define the log categories
         name="org.hibernate.type">
                 value="TRACE" />
                 ref="SQL"/>
        
         name="org.hibernate.SQL">
                 value="TRACE" />
                 ref="SQL"/>
        

Basic Git Commands

Creating a local git repository

git init

Adding your changes to the local git repository

git add .

git commit -m"initial import"

Tagging your changes to the remote server

git tag -a v1.1 -m "Version 1.1 is waiting for review"

Commiting changes to the remote server

git push origin master

Commiting tags to the remote server

git push --tags


Tuesday, November 6, 2012

Installing ZeroMQ to Ubuntu Lucid

install c++ compiler etc...:
sudo apt-get install  build-essential libtool autoconf automake uuid-dev e2fsprogs

install zeromq using these hints: http://johanharjono.com/archives/633 :
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:chris-lea/zeromq
sudo add-apt-repository ppa:chris-lea/libpgm
sudo apt-get update
sudo apt-get install libzmq1
sudo apt-get install libzmq-dev
sudo apt-get install libpgm-5.1-0
pip install pyzmq
 
git clone git://github.com/zeromq/libzmq.git
cd libzmq
./autogen.sh && ./configure && make && sudo make install && echo ":: ALL OK ::"
sudo cp src/.libs/libzmq.so /usr/local/lib
sudo ldconfig -v
ls -al /usr/local/lib/libzmq.*
Ref: https://github.com/mslinn/zeromq-demo

Saturday, October 20, 2012

Installing JRuby in OSX

Be sure that you have installed java and download Lastest version of jruby from jruby.org website by using curl command.

curl -O http://jruby.org.s3.amazonaws.com/downloads/1.7.0.RC2/jruby-bin-1.7.0.RC2.tar.gz

Create a hidden directory under your home directory and unpack the file.

cd
mkdir .opt
mv /Downloads/jruby-bin-1.7.0.RC2.tar.gz
cd .opt
tar xvfz jruby-bin-1.7.0.RC2.tar.gz
ln -s jruby-1.7.0.RC2 jruby

Edit your .bash_profile file and add the following

export PATH=$PATH:/Users/kg/.opt/jruby/bin

Open a new terminal window

Saturday, October 6, 2012

Creating your MySQL Database





You can create three dabases and you them as your development, test and production databases. they do not have to be on differnt servers.


CREATE DATABASE myprojectdb_dev CHARACTER SET utf8;;
CREATE DATABASE myprojectdb_test CHARACTER SET utf8;;
CREATE DATABASE myprojectdb_prod CHARACTER SET utf8;;

GRANT ALL ON myprojectdb_dev.* TO 'myprojectdb'@'%' IDENTIFIED BY 'myprojectdb';
GRANT ALL ON myprojectdb_test.* TO 'myprojectdb'@'%' IDENTIFIED BY 'myprojectdb';
GRANT ALL ON myprojectdb_prod.* TO 'myprojectdb'@'%' IDENTIFIED BY 'myprojectdb';

FLUSH PRIVILEGES;

Thursday, July 5, 2012

success and happiness

success is getting what you want. And, that happiness is wanting what you get.

LinkWithin

Related Posts Plugin for WordPress, Blogger...