001: /**********************************************************************************
002: * $URL: $
003: * $Id: $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.component.osid.logging;
021:
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024:
025: /**
026: * @inheritDoc
027: */
028: public class WritableLog implements org.osid.logging.WritableLog {
029: private static final Log LOG = LogFactory.getLog(WritableLog.class);
030:
031: org.osid.shared.Type formatType = null;
032: org.osid.shared.Type priorityType = null;
033: private String logName = null;
034: private org.osid.shared.Id id = null;
035:
036: public String getDisplayName()
037: throws org.osid.logging.LoggingException {
038: return this .logName;
039: }
040:
041: public org.osid.shared.Id getId()
042: throws org.osid.logging.LoggingException {
043: return this .id;
044: }
045:
046: public void initialize() throws org.osid.logging.LoggingException {
047: }
048:
049: public WritableLog(org.osid.OsidContext context,
050: java.util.Map configuration, String logName)
051: throws org.osid.logging.LoggingException {
052: if (logName == null) {
053: throw new org.osid.logging.LoggingException(
054: org.osid.logging.LoggingException.NULL_ARGUMENT);
055: }
056:
057: initialize();
058: this .logName = logName;
059: }
060:
061: public void appendLog(java.io.Serializable entryItem)
062: throws org.osid.logging.LoggingException {
063:
064: try {
065: if ("trace".equalsIgnoreCase(logName)) {
066: if (LOG.isTraceEnabled())
067: LOG.trace(entryItem.toString());
068: } else if ("debug".equalsIgnoreCase(logName)) {
069: if (LOG.isDebugEnabled())
070: LOG.debug(entryItem.toString());
071: } else if ("info".equalsIgnoreCase(logName)) {
072: LOG.info(entryItem.toString());
073: } else if ("warn".equalsIgnoreCase(logName)) {
074: LOG.warn(entryItem.toString());
075: } else if ("error".equalsIgnoreCase(logName)) {
076: LOG.error(entryItem.toString());
077: } else if ("fatal".equalsIgnoreCase(logName)) {
078: LOG.fatal(entryItem.toString());
079: } else {
080: LOG.info(entryItem.toString());
081: }
082:
083: } catch (Throwable t) {
084: // Ignore - not much to do...
085: System.out.println("Sakai OSID Log:" + t.toString());
086: System.out.println(this + "Entry=" + entryItem);
087: }
088:
089: }
090:
091: public void appendLogWithTypes(java.io.Serializable entryItem,
092: org.osid.shared.Type formatType,
093: org.osid.shared.Type priorityType)
094: throws org.osid.logging.LoggingException {
095: if (formatType == null) {
096: throw new org.osid.logging.LoggingException(
097: org.osid.logging.LoggingException.FORMAT_TYPE_NOT_SET);
098: }
099: if (priorityType == null) {
100: throw new org.osid.logging.LoggingException(
101: org.osid.logging.LoggingException.PRIORITY_TYPE_NOT_SET);
102: }
103: if (entryItem == null) {
104: throw new org.osid.logging.LoggingException(
105: org.osid.logging.LoggingException.NULL_ARGUMENT);
106: }
107: appendLog(entryItem);
108: }
109:
110: public void assignPriorityType(org.osid.shared.Type priorityType)
111: throws org.osid.logging.LoggingException {
112: this .priorityType = priorityType;
113: }
114:
115: public void assignFormatType(org.osid.shared.Type formatType)
116: throws org.osid.logging.LoggingException {
117: this.formatType = formatType;
118: }
119: }
|