8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The contents of this file are subject to the terms
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of the Common Development and Distribution License
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (the License). You may not use this file except in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * compliance with the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You can obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * opensso/legal/CDDLv1.0.txt
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * at opensso/legal/CDDLv1.0.txt.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If applicable, add the following below the CDDL Header,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with the fields enclosed by brackets [] replaced by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * your own identifying information:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * $Id: DBFormatter.java,v 1.11 2009/08/19 21:12:50 ww203982 Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/*
7f51416a939bd30ed31da090c2232423128eae9bMark de Reeper * Portions Copyrighted 2011-2013 ForgeRock, Inc.
86edd2209e1a3e78ae8c0fb3175d8a48425e291aKohei Tamura * Portions Copyrighted 2012 Open Source Solution Technology Corporation
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpackage com.sun.identity.log.handlers;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.logging.Formatter;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.logging.Handler;
7f51416a939bd30ed31da090c2232423128eae9bMark de Reeperimport java.util.logging.LogRecord;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.log.LogConstants;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.log.LogManager;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.log.LogManagerUtil;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.log.spi.Debug;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This Formatter provides support for formatting LogRecords that will help
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Database Logging.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <p>
7f51416a939bd30ed31da090c2232423128eae9bMark de Reeper * Typically this Formatter will be associated with a DBHandler (a handler meant
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * to handle Database logging). <tt> DBFormatter </TT> takes a LogRecord and
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * converts it to a Formatted string which DBHandler can understand.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic class DBFormatter extends Formatter {
7f51416a939bd30ed31da090c2232423128eae9bMark de Reeper
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private LogManager lmanager = LogManagerUtil.getLogManager();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Creates <code>DBFormatter</code> object
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public DBFormatter() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the set of all fields converted into a COMMA seperated
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * string. A typical sql query for logging a record looks like this. <p>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * insert into table "amSSO_access" (time, data, loginid, domain, level,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * ipAddress, hostname) values('10:10:10', '10th June, 2002',
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * ..., ..., ...)<p>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The getHead method returns back the set of all fields converted into a
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * COMMA seperated string. It is the duty of the formatter to fetch the all
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * field set from the LogManager and convert into a COMMA seperated string.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * By doing this the handler can be kept independent of the all field and
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * selected field set.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param h The target handler (can be null)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the set of all fields converted into a COMMA seperated string.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster @Override
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String getHead(Handler h) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String retString = lmanager.getProperty(LogConstants.ALL_FIELDS);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (Debug.messageEnabled()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Debug.message("DBFormatter: Returned String from getHead is "
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + retString);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return retString;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns a null string whenever called.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param h The target handler (can be null)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return a null string whenever called.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster @Override
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String getTail(Handler h) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return "";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
7f51416a939bd30ed31da090c2232423128eae9bMark de Reeper * Simply return the value from calling formatMessage. All DBFormatting is now handled directly in DBHandler.
7f51416a939bd30ed31da090c2232423128eae9bMark de Reeper * @param logRecord The LogRecord to format
7f51416a939bd30ed31da090c2232423128eae9bMark de Reeper * @return A String that represents the formatted LogRecord
7f51416a939bd30ed31da090c2232423128eae9bMark de Reeper */
7f51416a939bd30ed31da090c2232423128eae9bMark de Reeper @Override
7f51416a939bd30ed31da090c2232423128eae9bMark de Reeper public String format(LogRecord logRecord) {
7f51416a939bd30ed31da090c2232423128eae9bMark de Reeper return formatMessage(logRecord);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
86edd2209e1a3e78ae8c0fb3175d8a48425e291aKohei Tamura}