001: /**
002: * Copyright 2004 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: * <p/>
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */package com.sun.portal.log.common;
013:
014: import java.util.logging.Level;
015: import java.util.logging.Handler;
016:
017: /**
018: * This class holds detail related to the Logger.
019: * This class handles the formatting of logger details to be displayed when
020: * list-loggers --detail CLI command is invoked.
021: */
022:
023: public class PortalLoggerDetail {
024:
025: static final String DELIMITER = "\t";
026: static final String LINE_SEPARATOR = System
027: .getProperty("line.separator");
028:
029: private String loggerName;
030: private Level level;
031: private boolean logToParent;
032: private String stackTraceValue;
033: private String pattern;
034: private Handler[] handlers;
035:
036: public String getLoggerName() {
037: return loggerName;
038: }
039:
040: public void setLoggerName(String loggerName) {
041: this .loggerName = loggerName;
042: }
043:
044: public Level getLevel() {
045: return level;
046: }
047:
048: public void setLevel(Level level) {
049: this .level = level;
050: }
051:
052: public boolean isLogToParent() {
053: return logToParent;
054: }
055:
056: public void setLogToParent(boolean logToParent) {
057: this .logToParent = logToParent;
058: }
059:
060: public String getStackTraceValue() {
061: return stackTraceValue;
062: }
063:
064: public void setStackTraceValue(String stackTraceValue) {
065: this .stackTraceValue = stackTraceValue;
066: }
067:
068: public String getPattern() {
069: return pattern;
070: }
071:
072: public void setPattern(String pattern) {
073: this .pattern = pattern;
074: }
075:
076: public Handler[] getHandlers() {
077: return handlers;
078: }
079:
080: public void setHandlers(Handler[] handlers) {
081: this .handlers = handlers;
082: }
083:
084: public String format(boolean fileInfo, boolean useServerLogs) {
085: StringBuffer loggerDetail = new StringBuffer();
086:
087: // LoggerName
088: if (getLoggerName() != null) {
089: loggerDetail.append(getLoggerName());
090: loggerDetail.append(LINE_SEPARATOR);
091: }
092:
093: // Level
094: if (getLevel() != null) {
095: loggerDetail.append("Level=");
096: loggerDetail.append(getLevel().toString());
097: }
098:
099: if (fileInfo) {
100: // Log to Parent
101: loggerDetail.append(DELIMITER);
102: loggerDetail.append("Use Parent Handler=");
103: loggerDetail.append(isLogToParent());
104:
105: // Handler
106: boolean fileHandlerInUse = false;
107: Handler[] handlers = getHandlers();
108: if (!useServerLogs) {
109: if (handlers != null && handlers.length != 0) {
110: loggerDetail.append(DELIMITER);
111: loggerDetail.append("Handler=");
112: StringBuffer handlersValue = new StringBuffer();
113: String handlerName;
114: for (int j = 0; j < handlers.length; j++) {
115: handlerName = handlers[j].getClass().getName();
116: if (handlerName
117: .equals("java.util.logging.FileHandler"))
118: fileHandlerInUse = true;
119: handlersValue.append(handlerName);
120: if (j + 1 != handlers.length)
121: handlersValue.append(",");
122: }
123: loggerDetail.append(handlersValue);
124: }
125: }
126:
127: // Pattern
128: loggerDetail.append(DELIMITER);
129: if (getPattern() != null && fileHandlerInUse) {
130: loggerDetail.append("Logs to File=");
131: loggerDetail.append(getPattern());
132: }
133:
134: // Stack-trace
135: loggerDetail.append(DELIMITER);
136: if (getStackTraceValue() != null && fileHandlerInUse) {
137: loggerDetail.append("Print Stacktrace=");
138: loggerDetail.append(getStackTraceValue());
139: }
140: }
141:
142: return loggerDetail.toString();
143: }
144: }
|