LOG4PLSQL: User Guide

 

Author: Guillaume Moulard

 

Revision: Revision: 3.1.3

Last Modified: fev, 11 2005

 

 

What Is LOG4PLSQL

 

LOG4PLSQL is a PLSQL framework for logging in all PLSQL code

ú        Package,

ú        Procedure,

ú        Function,

ú        Trigger,

ú        PL/SQL Web application.

ú        Oracle Tools (Form, report,…)

 

 

Purpose:

ú        Easy of implemented and use

ú        Possibility to log apart from transaction

ú        Possibility to adapt the level of logging depending on user requirements

ú        Ability to use all LOG4J feature.

ú        Provide a complet set of tools PL/SQL developpement (bebug variable, SQLERRM, assert, call stack, ... ).

 

Log destination:

ú        Table in Oracle Datablase

ú        Oracle Datablase alert.log file

ú        Oracle Datablase trace file

ú        Standard output

ú        By log4J::Log4JbackgroundProcess:

o       Async,

o       JDBC,

o       JMS,

o       NTEventLog,

o       SMTP,

o       Socket,

o       SocketHub,

o       Syslog,

o       Telnet,

o       Writer

Log4plsql was born from the log4J spirit (and use it).

 

See : Log4j documentation : http://logging.apache.org/log4j/docs/documentation.html and the book write by Ceki Glc

 

 

Architecture

 

 

Install

 

 

1. Download zip file in project page : http://log4plsql.sourceforge.net/

 

2. unzip Log4plsql.zip (see: http://www.info-zip.org for zip tools)
  
$ unzip Log4plsql.zip

 

 

3. Edit Log4plsql\cmd\setVariable.bat or Log4plsql/cmd/setVariable.sh file

 

3.1 Change set variable

 

3.2 Save


with yours variable this command should be available:
<ORACLE_HOME>/bin/sqlplus <SYS_USER>/<SYS_PASSW_USER>@<LOG_SID>

 

 

 

4. Run install.bat or install.sh in cmd directory

Perhaps is necessary to change to exec attribute this commande : chmod +x *.sh

 

If you have some SP2-0310 error for param.sql or return.sql, ignore it, or create 2 empty file in /sql/. (param.sql and return.sql)

 

 

 

If you don’t use LOG4J features your installation is completed.

 

Next step is required if you use a LOG4J function

 

 

5. Edit .\properties\log4plsql.xml

 

5.1 Change a JDBC Parameter (see http://technet.oracle.com/software/tech/java/sqlj_jdbc/content.html)

 

5.1.1 URL : Jdbc URL for you database  : jdbc:oracle:thin:@localhost:1521:<ORACLE_SID>

 

5.1.2 USER : Database user (Use same %LOG_USER% in install.bat ) 

 

5.1.3 PWD :  Password of database user  (Use same %LOG_PASSW_USER% in install.bat )

 

5.2 Chose you ACTION/deleteInDatabase value :  Y : after log Log4JbackgroundProcess Erreur ! Signet non d‚fini. delete a row in database.

 

In my machine : .\ properties\log4j.properties :

 

<?xml version="1.0" ?>

<properties>   

  <category name="log4j">

    <property name="properties" value=".\properties\log4j.properties" />

  </category> 

  <category name="JDBC">

    <property name="URL" value="jdbc:oracle:thin:@localhost:1521:ORATEST" />

    <property name="USER" value="ulog" />

    <property name="PWD" value="ulog" />

  </category>

  <category name="ACTION">

    <property name="deleteInDatabase" value="Y" />

  </category>

</properties>

 

 

6. Start startLog4JbackgroundProcess.bat in cmd directory

 

 

 

 

Usage

Basic concept

LOG4PLSQL log level

 

 

PL/SQL Code

Constant

Value

Description

 

 

LOFF

1

The OFF has the highest possible rank and is intended to turn off logging.

 

plog.fatal('Text');

LFATAL

2

The FATAL level designates very severe error events that will presumably lead the application to abort

 

plog.error('Text');

LERROR

3

The ERROR level designates error events that might still allow the application to continue running.

 

plog.warn('Text');

LWARN 

4

The WARN level designates potentially harmful situations

 

plog.info('Text');

LINFO 

5

The INFO level designates informational messages that highlight the progress of the application at coarse-grained level.

 

plog.debug('Text');

LDEBUG

6

The DEBUG Level designates fine-grained informational events that are most useful to debug an application.

 

 

LALL  

7

The ALL has the lowest possible rank and is intended to turn on all logging.

 

LOG4PLSQL log destination

 

By default Log4PLSQL log in database table name TLOG:

 

 

SQL> desc ULOG.TLOG

 Nom                                       NULL ?   Type

 ----------------------------------------- -------- ----------------------------

 ID                                        NOT NULL NUMBER

 LDATE                                              DATE

 LLEVEL                                             NUMBER

 LSECTION                                           VARCHAR2(2000)

 LTEXTE                                             VARCHAR2(2000)

 LUSER                                              VARCHAR2(30)

 LHSECS                                             NUMBER

 

SQL>

 

To read this table you can select in the TLOG table or in the VLOG view.

 

It is possible to log to alert.log, and trace file and to view directly the log output in standard output. (see paragraph: Advanced features for developer)

 

If you want to log in other destination, it is necessary to use a Log4JbackgroundProcess feature. Currently, some log4j appenders exist for the console, files, GUI components, remote socket servers, JMS, NT Event Loggers, and remote UNIX Syslog daemons. It is also possible to log asynchronously.

Log destination exemple

 

File

 

2003-06-07 01:39:27,878 INFO  (backgroundProcess) - Start []

2003-06-07 01:39:27,888 DEBUG (backgroundProcess) - log4plsql.properties : .\properties\log4plsql.xml []

2003-06-07 01:39:27,888 DEBUG (backgroundProcess) - log4j.properties : .\\properties\\log4j.properties []

2003-06-07 01:39:27,898 DEBUG (ReaderDBThread) - ReaderLogDataBase : Connect []

2003-06-07 01:39:29,481 DEBUG (ReaderDBThread) - begin loop []

2003-06-07 01:39:38,784 DEBUG (log4plsql.SCOTT.block.codePart1) - message for debug [DatabaseLoginDate:07 juin      2003 01:39:38: 30]

2003-06-07 01:39:38,834 INFO  (log4plsql.SCOTT.block.codePart1) - message for information [DatabaseLoginDate:07 juin      2003 01:39:38: 30]

2003-06-07 01:39:38,874 WARN  (log4plsql.SCOTT.block.codePart1) - message for warning  [DatabaseLoginDate:07 juin      2003 01:39:38: 31]

2003-06-07 01:39:38,924 ERROR (log4plsql.SCOTT.block.codePart1) - message for error [DatabaseLoginDate:07 juin      2003 01:39:38: 31]

2003-06-07 01:39:38,954 FATAL (log4plsql.SCOTT.block.codePart1) - message for fatal [DatabaseLoginDate:07 juin      2003 01:39:38: 31]

Nt Event Loggers

 

 

Basic features

 

After installation it is possible to create in your database a simple procedure: