<html>
<head>
    <base href="https://docs.jboss.org/author">
            <link rel="stylesheet" href="/author/s/en/2172/19/5/_/styles/combined.css?spaceKey=TEIID&amp;forWysiwyg=true" type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://docs.jboss.org/author/display/TEIID/Custom+Logging">Custom Logging</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://docs.jboss.org/author/display/~rareddy">Ramesh Reddy</a>
    </h4>
        <br/>
                         <h4>Changes (36)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">The Teiid system provides a wealth of information using logging. To control logging level, contexts, and log locations, you should be familiar with container&#39;s {{standalone.xml}} or {{domain.xml}} configuration fileand check out &quot;logging&quot; subsystem. Refer to the Administrator Guide for more details about different Teiid contexts available.  Refer to [http://logging.apache.org/log4j/] for more information about log4j. <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">The Teiid system provides a wealth of information using logging. To control logging level, contexts, and log locations, you should be familiar with container&#39;s {{standalone.xml}} or {{domain.xml}} configuration file and check out &quot;logging&quot; subsystem. Refer to the [Administrator&#39;s Guide] for more details about different [Teiid contexts|Logging] available. <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">If you want a custom appender, follow the Log4J directions to write a custom appender. Refer to the instructions at [http://logging.apache.org/log4net/release/faq.html]. If you develop a custom logging solution, the implementation jar should be placed as a jar in &quot;org.jboss.teiid&quot; module and define its name in the module.xml file as part of the module. <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">If you want a custom log handler, follow the directions to write a custom _[java.util.logging.Handler|http://docs.oracle.com/javase/6/docs/api/java/util/logging/Handler.html]_. If you develop a custom logging Handler, the implementation class along should be placed as a jar in &quot;org.jboss.teiid&quot; module and define its name in the module.xml file as part of the module along with any dependencies it may need. See below. <br></td></tr>
            <tr><td class="diff-unchanged" > <br> <br>h1. Command Logging API <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">If you want to build a custom appender for command logging that will have access to log4j &quot;LoggingEvents&quot; to the &quot;COMMAND\_LOG&quot; context, the appender will receive a message that is an instance of {{org.teiid.logging.CommandLogMessage}}.  The relevant Teiid classes are defined in the {{teiid\-api\-7.6.jar}}. The CommmdLogMessage includes information about vdb, session, command sql, etc.  CommandLogMessages are logged at the DEBUG level. <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">If you want to build a custom handler for command logging that will have access to java.util.logging [LogRecords|http://docs.oracle.com/javase/6/docs/api/java/util/logging/LogRecord.html] to the &quot;COMMAND\_LOG&quot; context, the handler will receive a instance of LogRecord message, this object will contain a parameter of type {{org.teiid.logging.CommandLogMessage}}.  The relevant Teiid classes are defined in the _teiid\-api\-{space-metadata-from:fullVersionNumber}.jar_. The CommmdLogMessage includes information about vdb, session, command sql, etc.  CommandLogMessages are logged at the DEBUG level. <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-changed-lines" >{code:lang=Java|title=Sample CommandLogMessage <span class="diff-changed-words">Usage}<span class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">package org.something;</span></span> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">package org.something; <br></td></tr>
            <tr><td class="diff-changed-lines" >import <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">org.apache.log4j.AppenderSkeleton;</span> <span class="diff-added-words"style="background-color: #dfd;">java.util.logging.Handler;</span> <br></td></tr>
            <tr><td class="diff-changed-lines" >import <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">org.apache.log4j.spi.LoggingEvent;</span> <span class="diff-added-words"style="background-color: #dfd;">java.util.logging.LogRecord;</span> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">import org.teiid.logging.*; <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">public class CustomAppender extends AppenderSkeleton  <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">public class CommandHandler extends Handler { <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">{</span> <span class="diff-added-words"style="background-color: #dfd;">@Override</span> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;"> <br>  protected void append(LoggingEvent event) { <br>    if (event.getMessage() instanceof CommandLogMessage) { <br>      CommandLogMessage clMessage = (CommandLogMessage)event.getMessage(); <br>      String sql = clMessage.getSql(); <br>      ... <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">    public void publish(LogRecord record) { <br>         CommandLogMessage msg = (CommandLogMessage)record.getParameters()[0]; <br></td></tr>
            <tr><td class="diff-unchanged" >        //log to a database, trigger an email, etc. <br></td></tr>
            <tr><td class="diff-unchanged" >    } <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">    ... <br>  } <br> <br>  ... <br> <br>}{code} <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">    @Override <br>    public void flush() { <br>    } <br> <br>    @Override <br>    public void close() throws SecurityException { <br>    } <br>} <br>{code} <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h1. Audit Logging API <br>If you want to build a custom appender for command logging that will have access to log4j &quot;LoggingEvents&quot; to the &quot;org.teiid.AUDIT\_LOG&quot; context, the appender will receive a message that is an instance of {{org.teiid.logging.AuditMessage}}.  The relevant Teiid classes are defined in the {{teiid\-api\-7.6.jar}}. The {{AuditMessage}} includes information about user, the action, and the target\(s) of the action.  AuditMessages are logged at the DEBUG level. <br> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">{code:lang=Java|title=Sample AuditMessage Usage}package org.something; <br>import org.apache.log4j.AppenderSkeleton; <br>import org.apache.log4j.spi.LoggingEvent; <br>import org.teiid.logging.*; <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">If you want to build a custom handler for command logging that will have access to java.util.logging [LogRecords|http://docs.oracle.com/javase/6/docs/api/java/util/logging/LogRecord.html] to the &quot;AUDIT\_LOG&quot; context, the handler will receive a instance of LogRecord message, this object will contain a parameter of type {{org.teiid.logging.AuditMessage}}.  The relevant Teiid classes are defined in the _teiid\-api\-{space-metadata-from:fullVersionNumber}.jar_. AuditMessages are logged at the DEBUG level. <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">public class CustomAppender extends AppenderSkeleton  <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{code:lang=Java|title=Sample AuditMessage Usage} <br>package org.something; <br>import java.util.logging.Handler; <br>import java.util.logging.LogRecord; <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">{</span> <span class="diff-added-words"style="background-color: #dfd;"> </span> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">public class AuditHandler extends Handler { <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;"> </span> <span class="diff-added-words"style="background-color: #dfd;">@Override</span> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">  protected void append(LoggingEvent event) { <br>    if (event.getMessage() instanceof AuditMessage) { <br>      AuditMessage auditMessage = (AuditMessage)event.getMessage(); <br>      String activity = auditMessage.getActivity(); <br>      ... <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">    public void publish(LogRecord record) { <br>         AuditMessage msg = (AuditMessage)record.getParameters()[0]; <br></td></tr>
            <tr><td class="diff-unchanged" >        //log to a database, trigger an email, etc. <br></td></tr>
            <tr><td class="diff-unchanged" >    } <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">...</span> <span class="diff-added-words"style="background-color: #dfd;"> </span> <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">}</span> <span class="diff-added-words"style="background-color: #dfd;">@Override</span> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">    public void flush() { <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;"> </span> <span class="diff-added-words"style="background-color: #dfd;">}</span> <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">...</span> <span class="diff-added-words"style="background-color: #dfd;"> </span> <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;"> </span> <span class="diff-added-words"style="background-color: #dfd;">@Override</span> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">    public void close() throws SecurityException { <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">}{code}</span> <span class="diff-added-words"style="background-color: #dfd;">}</span> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">} <br>{code} <br> <br>h1. Configuration <br>Now that you have developed a custom handler class, now package implementation in Jar file, then copy this Jar file into {{&lt;jboss\-as7&gt;/modules/org/jboss/teiid/main}} folder, and edit {{module.xml}} file in the same directory and add <br> <br>{code} <br>   &lt;resource-root path=&quot;{your-jar-name}.jar&quot; /&gt; <br>{code} <br> <br>then edit {{standalone-teiid.xml}} or {{domain.xml}} file, locate the &quot;logging&quot; subsystem and add the following entries. <br> <br>{code} <br>   &lt;custom-handler name=&quot;COMMAND&quot; class=&quot;org.teiid.logging.CommandHandler&quot;  <br>     module=&quot;org.jboss.teiid&quot;&gt; <br>   &lt;/custom-handler&gt; <br> <br>   ..other entries <br> <br>   &lt;logger category=&quot;org.teiid.COMMAND_LOG&quot;&gt; <br>       &lt;level name=&quot;DEBUG&quot;/&gt; <br>       &lt;handlers&gt; <br>           &lt;handler name=&quot;COMMAND&quot;/&gt; <br>       &lt;/handlers&gt; <br>   &lt;/logger&gt; <br>{code} <br> <br>Change the above configuration accordingly for AuditHandler, if you are working with Audit Messages. <br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <p>The Teiid system provides a wealth of information using logging. To control logging level, contexts, and log locations, you should be familiar with container's <tt>standalone.xml</tt> or <tt>domain.xml</tt> configuration file and check out "logging" subsystem. Refer to the <a href="/author/display/TEIID/Administrator%27s+Guide" title="Administrator&#39;s Guide">Administrator's Guide</a> for more details about different <a href="/author/display/TEIID/Logging" title="Logging">Teiid contexts</a> available.</p>

<p>If you want a custom log handler, follow the directions to write a custom <em><a href="http://docs.oracle.com/javase/6/docs/api/java/util/logging/Handler.html" class="external-link" rel="nofollow">java.util.logging.Handler</a></em>. If you develop a custom logging Handler, the implementation class along should be placed as a jar in "org.jboss.teiid" module and define its name in the module.xml file as part of the module along with any dependencies it may need. See below.</p>


<h1><a name="CustomLogging-CommandLoggingAPI"></a>Command Logging API</h1>
<p>If you want to build a custom handler for command logging that will have access to java.util.logging <a href="http://docs.oracle.com/javase/6/docs/api/java/util/logging/LogRecord.html" class="external-link" rel="nofollow">LogRecords</a> to the "COMMAND&#95;LOG" context, the handler will receive a instance of LogRecord message, this object will contain a parameter of type <tt>org.teiid.logging.CommandLogMessage</tt>.  The relevant Teiid classes are defined in the <em>teiid&#45;api&#45;8.2.0.Final.jar</em>. The CommmdLogMessage includes information about vdb, session, command sql, etc.  CommandLogMessages are logged at the DEBUG level.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Sample CommandLogMessage Usage</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
package org.something;
import java.util.logging.Handler;
import java.util.logging.LogRecord;

public class CommandHandler extends Handler {
    @Override
    public void publish(LogRecord record) {
         CommandLogMessage msg = (CommandLogMessage)record.getParameters()[0];
        //log to a database, trigger an email, etc.
    }

    @Override
    public void flush() {
    }

    @Override
    public void close() throws SecurityException {
    }
}
</pre>
</div></div>

<h1><a name="CustomLogging-AuditLoggingAPI"></a>Audit Logging API</h1>
<p>If you want to build a custom appender for command logging that will have access to log4j "LoggingEvents" to the "org.teiid.AUDIT&#95;LOG" context, the appender will receive a message that is an instance of <tt>org.teiid.logging.AuditMessage</tt>.  The relevant Teiid classes are defined in the <tt>teiid&#45;api&#45;7.6.jar</tt>. The <tt>AuditMessage</tt> includes information about user, the action, and the target&#40;s) of the action.  AuditMessages are logged at the DEBUG level.</p>

<p>If you want to build a custom handler for command logging that will have access to java.util.logging <a href="http://docs.oracle.com/javase/6/docs/api/java/util/logging/LogRecord.html" class="external-link" rel="nofollow">LogRecords</a> to the "AUDIT&#95;LOG" context, the handler will receive a instance of LogRecord message, this object will contain a parameter of type <tt>org.teiid.logging.AuditMessage</tt>.  The relevant Teiid classes are defined in the <em>teiid&#45;api&#45;8.2.0.Final.jar</em>. AuditMessages are logged at the DEBUG level.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Sample AuditMessage Usage</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
package org.something;
import java.util.logging.Handler;
import java.util.logging.LogRecord;

public class AuditHandler extends Handler {
    @Override
    public void publish(LogRecord record) {
         AuditMessage msg = (AuditMessage)record.getParameters()[0];
        //log to a database, trigger an email, etc.
    }

    @Override
    public void flush() {
    }

    @Override
    public void close() throws SecurityException {
    }
}
</pre>
</div></div>

<h1><a name="CustomLogging-Configuration"></a>Configuration</h1>
<p>Now that you have developed a custom handler class, now package implementation in Jar file, then copy this Jar file into <tt>&lt;jboss&#45;as7&gt;/modules/org/jboss/teiid/main</tt> folder, and edit <tt>module.xml</tt> file in the same directory and add</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
   &lt;resource-root path="{your-jar-name}.jar" /&gt;
</pre>
</div></div>

<p>then edit <tt>standalone-teiid.xml</tt> or <tt>domain.xml</tt> file, locate the "logging" subsystem and add the following entries.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
   &lt;custom-handler name="COMMAND" class="org.teiid.logging.CommandHandler" 
     module="org.jboss.teiid"&gt;
   &lt;/custom-handler&gt;

   ..other entries

   &lt;logger category="org.teiid.COMMAND_LOG"&gt;
       &lt;level name="DEBUG"/&gt;
       &lt;handlers&gt;
           &lt;handler name="COMMAND"/&gt;
       &lt;/handlers&gt;
   &lt;/logger&gt;
</pre>
</div></div>

<p>Change the above configuration accordingly for AuditHandler, if you are working with Audit Messages.</p>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;" class="grey">
                        <a href="https://docs.jboss.org/author/users/removespacenotification.action?spaceKey=TEIID">Stop watching space</a>
            <span style="padding: 0px 5px;">|</span>
                <a href="https://docs.jboss.org/author/users/editmyemailsettings.action">Change email notification preferences</a>
</div>
        <a href="https://docs.jboss.org/author/display/TEIID/Custom+Logging">View Online</a>
        |
        <a href="https://docs.jboss.org/author/pages/diffpagesbyversion.action?pageId=18646191&revisedVersion=3&originalVersion=2">View Changes</a>
                |
        <a href="https://docs.jboss.org/author/display/TEIID/Custom+Logging?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>