Search This Blog

Showing posts with label Logger. Show all posts
Showing posts with label Logger. Show all posts

Wednesday, September 11, 2013

Open ATNA

1) Download the source https://www.projects.openhealthtools.org/sf/projects/openatna/


2) Download Maven 2.x

3) Download postgres9.x & install it


4) Type = D:\openatna\trunk\openatna> mvn install:install-file -DgroupId=org.openhealthtools.openexchange -DartifactId=openexchange-actorconfig -Dversion=1.0 -Dpackaging=jar -Dfile=D:\openxds\repo\org\openhealthtools\openexchange\openexchange-actorconfig\1.0-SNAPSHOT\openexchange-actorconfig-1.0-SNAPSHOT.jar


5) Change = D:\openatna\trunk\openatna\audit\pom.xml
    Change to 1.0 for actor-config [ which version you have in ur repo of openxds svn checkout ]

6) Type = D:\openatna\trunk\openatna> mvn install -DskipTests


Database
********

7) Go to D:\openatna\trunk\openatna\audit\src\main\resources\sql
    Use the files to create user and tables etc...


RUN
***

8)To create an executable version of OpenATNA use the following command:

    d:\xxxx> mvn -P exec install

9) COPY =  get D:\openxds\repo\org\openhealthtools\openexchange\openexchange-utils\1.0-SNAPSHOT\openexchange-utils-1.0.jar" 
    OR you can take in from openxds-web.war file web-inf\lib folder
    OR download it
   
    & copy that into D:\openatna\trunk\openatna\all\build\lib

10) Change =
    Go to D:\openatna\trunk\openatna\all\build\openatna-1.2.1-    SNAPSHOT.jar
    extract the META-INF\MANIFEST.MF
    Open it
     add the jar in last line [ one space ].
        lib\openatna-1.2.1-SNAPSHOT.jar

11) This uses a maven profile (-P command). This will create an executable jar file in the "all" directory. Change directory into the all/build folder. You should see a jar file called openatna-version.jar, where version is the version you have downloaded. This is the executable jar file. The dependencies are in the all/build/lib/ directory. To run OpenATNA, type:

    D:\openatna\trunk\openatna\all\build> java -jar openatna-1.2.1-SNAPSHOT.jar


RUN CLIENT
**********
Use eclipse to run it if u cant run the file in command prompt

12) RUN FILE = D:\openatna\trunk\openatna\all\src\test\java\org\openhealthtools\openatna\all\test\TlsClientTest0.java in eclipse [ run as JUNIT ]

13) OUTPUT = go to database tables \ messages etc..


Testing
*******
You can test against the server by running the clients in the "test" directory of the all module. These are JUnit tests and are probably easiest to run inside your IDE. The classes that are designed to run against the server are:


    org.openhealthtools.openatna.dist.test.TlsClientTest0     -    sends messages to the ARR using TLS and Syslog RFC 5424 style messages. The first set of messages use mutually authentication with message encryption. The second set of messages use mutual authentication without message encryption.

    org.openhealthtools.openatna.dist.test.UdpClientTest0     -    sends messages to the ARR using UDP and Syslog RFC 5424 style messages.

    org.openhealthtools.openatna.dist.test.BsdClientTest0     -    sends messages to the ARR using UDP and Syslog BSD style messages.

Some of these tests send erroneous messages to the ARR (on purpose :-)), so you may see error stack traces.


Reporting
*********
The 'web' module contains a simple servlet for querying the database. During the build (when you run 'mvn install') the Servlet is built and and a << war file >> is created. This war file can be dropped into a Servlet container such as Tomcat. For testing purposes, it can also be run using maven. If you change directory into the 'web' directory and type:

D:\openatna\trunk\openatna\web\target\atna.war



Tomcat 6.0
***********
simply copy the war file and run it


JBOSS 6 or Jboss eap 6
**********************

While run from eclipse, add the line in the VM arguments
    Double Click server in the server Prespective
        Open launch Configuration
        add this in VM arg at end with double quotes to avoid logging.properties null error before give one space
       
         "-Dorg.jboss.as.logging.per-deployment=false"



URL : http://localhost:8080/atna





















Log4j SocketAppender with DailyRollingFileAppender

This will create a centralized logging mechanism by using log4j
This will create daily one log-file



Step 1: -
     Create a file called log4j-server.properties and add the below content
log4j.rootLogger=INFO, R
log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d [%t] %-5p - %m%n
log4j.appender.R.File=C:/logs/examples
log4j.appender.R.DatePattern='-'yyyyMMdd'.log'

Step 2:-
    Copy log4j-1.2.7.jar into your folder or where log4j-server.properties


Step 3:-   
    Go to cmd prompt and run with the following command.

    Ex:-
   
        D:\Log4j-server\server>    java -classpath log4j-1.2.17.jar org.apache.log4j.net.SimpleSocketServer 4712 log4j-Server.properties
        or
        D:\Log4j-server>   java -classpath .\Server\log4j-1.2.17.jar org.apache.log4j.net.SimpleSocketServer 4712 .\Server\log4j-Server.properties


Step 4:-
    Create a client log4j.properties
and add the below content
log4j.rootLogger=INFO, R
log4j.appender.R=org.apache.log4j.net.SocketAppender
log4j.appender.R.Port=4712
log4j.appender.R.RemoteHost=localhost
log4j.appender.R.ReconnectionDelay=10000

Step 5:- 

            Your Java program.

public class LogTest
{
    private static org.apache.log4j.Logger    log    = Logger.getLogger ( LogTest.class );
public static void main ( String [] args ) throws Exception
    {
      
            log.info ( "First Info Message!" );

            log.trace ( "First Trace Message!" );
            log.debug ( "First Debug Message!" );
            log.warn ( "First Warn Message!" );
            log.error ( "First Error Message!" );
            log.fatal ( "First Fatal Message!" );

}
}





OUTPUT :-

 2013-09-12 00:40:04,395 [main] INFO  - Listening on port 4712
 2013-09-12 00:40:04,400 [main] INFO  - Waiting to accept a new client.
 2013-09-12 00:40:04,751 [main] INFO  - Connected to client at /192.168.7.9
 2013-09-12 00:40:04,751 [main] INFO  - Starting new socket node.
 2013-09-12 00:40:04,760 [main] INFO  - Waiting to accept a new client.
 2013-09-12 00:40:07,736 [main] INFO  - Second Info Message!
 2013-09-12 00:40:07,737 [main] WARN  - Second Warn Message!
 2013-09-12 00:40:07,738 [main] ERROR - Second Error Message!
 2013-09-12 00:40:07,740 [main] FATAL - Second Fatal Message!
 2013-09-12 00:40:12,754 [main] INFO  - Second Info Message!
 2013-09-12 00:40:12,755 [main] WARN  - Second Warn Message!
 2013-09-12 00:40:12,757 [main] ERROR - Second Error Message!
 2013-09-12 00:40:12,758 [main] FATAL - Second Fatal Message!
 2013-09-12 00:40:13,402 [main] INFO  - Connected to client at /192.168.7.9
 2013-09-12 00:40:13,402 [main] INFO  - Starting new socket node.
 2013-09-12 00:40:13,403 [main] INFO  - Waiting to accept a new client.
 2013-09-12 00:40:13,405 [main] INFO  - First Info Message!
 2013-09-12 00:40:13,414 [main] WARN  - First Warn Message!



Friday, December 18, 2009

Logger in JSP

Apply log4j within jsp.


Information
none

Operating system used
Windows XP Home Edition Version 5.1 SP 2

Software prerequisites
Tomcat
Jakarta log tag library
Log4j 1.2.9


Procedure

1. Download the Jakarta log tag library: jakarta-taglibs-log-1.0.zip

2. Extract this archive file, e.g.: C:\Tools\jakarta-taglibs-log-1.0

The archive contains the following files:

LICENSE
log-doc.war
log-examples.war
README
taglibs-log.jar
taglibs-log.tld

3. Download Log4j 1.2.9: logging-log4j-1.2.9.zip

4. Extract this archive file, e.g.: C:\Tools\logging-log4j-1.2.9

The archive contains serveral files. The most important one is: C:\Tools\logging-log4j-1.2.9\dist\lib\log4j-1.2.9.jar

5. Install Tomcat. Follow guide "Installing Tomcat 4.1.31".

6. Create a simple a Tomcat web application called "demo":

* Create the following directories inside the Tomcat "webapps" directory:

C:\Tools\Tomcat 4.1\webapps\demo
C:\Tools\Tomcat 4.1\webapps\demo\WEB-INF
C:\Tools\Tomcat 4.1\webapps\demo\WEB-INF\classes
C:\Tools\Tomcat 4.1\webapps\demo\WEB-INF\lib

* Copy the tag library descriptor file "taglibs-log.tld" into WEB-INF.

* Copy the tag library JAR file "taglibs-log.jar" into WEB-INF/lib.

* Copy the log4j JAR file "log4j-1.2.9.jar" into WEB-INF/lib.

* Create a web.xml file in the WEB-INF directory:


PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">


Demonstration log4j usage in jsp

index.jsp


http://jakarta.apache.org/taglibs/log-1.0
/WEB-INF/taglibs-log.tld



Note: You MUST add a element in the web.xml file:


http://jakarta.apache.org/taglibs/log-1.0
/WEB-INF/log.tld


* Create a log4j.properties file in the WEB-INF/classes directory:

# ***** Set root logger level to DEBUG and its two appenders to stdout and R.
log4j.rootLogger=debug, stdout, R

# ***** stdout is set to be a ConsoleAppender.
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
# ***** stdout uses PatternLayout.
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d [%c] %p - %m%n

# ***** R is set to be a RollingFileAppender.
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=${catalina.home}/logs/demo.log
# ***** Max file size is set to 100KB
log4j.appender.R.MaxFileSize=100KB
# ***** Keep one backup file
log4j.appender.R.MaxBackupIndex=1
# ***** R uses PatternLayout.
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d [%c] %p - %m%n

Note:
The location of the log file is set in:
log4j.appender.R.File=${catalina.home}/logs/demo.log



* Create two jsp files in the C:\Tools\Tomcat 4.1\webapps\demo directory:

File 1: index.jsp

<%@ taglib uri="http://jakarta.apache.org/taglibs/log-1.0" prefix="log" %>



Demonstration log4j usage in jsp





Show DEBUG message.
Show INFO message.
Show WARN message.
Show ERROR message.
Show FATAL message.


Message embedded within the open and close tags.


Using category attribute.



The log messages are shown in the Tomcat console and in the
${catalina.home}/logs/demo.log file.





File 2: test.jsp

<%@ page import="org.apache.log4j.Logger" %>



Demonstration log4j usage in jsp




<%
Logger log = Logger.getLogger("com.mobilefish.demo.test");
log.debug("Show DEBUG message");
log.info("Show INFO message");
log.warn("Show WARN message");
log.error("Show ERROR message");
log.fatal("Show FATAL message");
%>


The log messages are shown in the Tomcat console and in the
${catalina.home}/logs/demo.log file.





7. (Re)start Tomcat.

8. Access the index.jsp file:

http://localhost:8080/demo/index.jsp

9. The following log messages are shown in the Tomcat console and in the ${catalina.home}/logs/demo.log file.

2006-06-03 17:28:43,379 [root] DEBUG - Show DEBUG message.
2006-06-03 17:28:43,409 [root] INFO - Show INFO message.
2006-06-03 17:28:43,409 [root] WARN - Show WARN message.
2006-06-03 17:28:43,409 [root] ERROR - Show ERROR message.
2006-06-03 17:28:43,419 [root] FATAL - Show FATAL message.
2006-06-03 17:28:43,419 [root] FATAL - Message embedded within the open and close tags.
2006-06-03 17:28:43,419 [root] FATAL - Message passed as an attribute to the tag
2006-06-03 17:28:43,419 [com.mobilefish.demo.index] FATAL - Using category attribute.

10. Access the test.jsp file:

http://localhost:8080/demo/test.jsp

11. The following log messages are shown in the Tomcat console and in the ${catalina.home}/logs/demo.log file.

2006-06-03 17:55:43,379 [com.mobilefish.com.test] DEBUG - Show DEBUG message.
2006-06-03 17:55:43,409 [com.mobilefish.com.test] INFO - Show INFO message.
2006-06-03 17:55:43,409 [com.mobilefish.com.test] WARN - Show WARN message.
2006-06-03 17:55:43,409 [com.mobilefish.com.test] ERROR - Show ERROR message.
2006-06-03 17:55:43,419 [com.mobilefish.com.test] FATAL - Show FATAL message.

12. Change the root logger level to WARN in the log4j.properties file and restart Tomcat:

log4j.rootLogger=warn, stdout, R

When the index.jsp page is reloaded in your browser only the following messages are shown:

2006-06-03 17:48:43,409 [root] WARN - Show WARN message.
2006-06-03 17:48:43,409 [root] ERROR - Show ERROR message.
2006-06-03 17:48:43,419 [root] FATAL - Show FATAL message.
2006-06-03 17:48:43,419 [root] FATAL - Message embedded within the open and close tags.
2006-06-03 17:48:43,419 [root] FATAL - Message passed as an attribute to the tag
2006-06-03 17:48:43,419 [com.mobilefish.demo.index] FATAL - Using category attribute.

Hit Counter


View My Stats