001: package com.sun.portal.log.common;
002:
003: import java.util.logging.Handler;
004:
005: /**
006: *
007: */
008: public class LoggerDetails {
009:
010: static final String DELIMITER = "\t";
011: static final String LINE_SEPARATOR = System
012: .getProperty("line.separator");
013:
014: private String[] handlers;
015: private String loggerName;
016: private String level;
017: private String logToParent;
018: private String stackTraceValue;
019: private String pattern;
020:
021: public String getLoggerName() {
022: return loggerName;
023: }
024:
025: public void setLoggerName(String loggerName) {
026: this .loggerName = loggerName;
027: }
028:
029: public String[] getHandlers() {
030: return handlers;
031: }
032:
033: public void setHandlers(String[] handlers) {
034: this .handlers = handlers;
035: }
036:
037: public String getLevel() {
038: return level;
039: }
040:
041: public void setLevel(String level) {
042: this .level = level;
043: }
044:
045: public String isLogToParent() {
046: return logToParent;
047: }
048:
049: public void setLogToParent(String logToParent) {
050: this .logToParent = logToParent;
051: }
052:
053: public String getStackTraceValue() {
054: return stackTraceValue;
055: }
056:
057: public void setStackTraceValue(String stackTraceValue) {
058: this .stackTraceValue = stackTraceValue;
059: }
060:
061: public String getPattern() {
062: return pattern;
063: }
064:
065: public void setPattern(String pattern) {
066: this .pattern = pattern;
067: }
068:
069: public String format(boolean fileInfo, boolean useServerLogs) {
070: StringBuffer loggerDetail = new StringBuffer();
071:
072: // LoggerName
073: if (getLoggerName() != null) {
074: loggerDetail.append(getLoggerName());
075: loggerDetail.append(LINE_SEPARATOR);
076: }
077:
078: // Level
079: if (getLevel() != null) {
080: loggerDetail.append("Level=");
081: loggerDetail.append(getLevel().toString());
082: }
083:
084: if (fileInfo) {
085: // Log to Parent
086: loggerDetail.append(DELIMITER);
087: loggerDetail.append("Use Parent Handler=");
088: loggerDetail.append(isLogToParent());
089:
090: // Print Handler and Stacktrace info only if the pattern is present
091:
092: // Handler
093: StringBuffer handlersValue = new StringBuffer();
094: boolean fileHandlerInUse = false;
095: String[] handlers = getHandlers();
096: if (!useServerLogs) {
097: if (handlers != null && handlers.length != 0) {
098: for (int j = 0; j < handlers.length; j++) {
099: if (handlers[j]
100: .equals("java.util.logging.FileHandler"))
101: fileHandlerInUse = true;
102: handlersValue.append(handlers[j]);
103: if (j + 1 != handlers.length)
104: handlersValue.append(",");
105: }
106: }
107: }
108:
109: // Pattern
110: loggerDetail.append(DELIMITER);
111: if (getPattern() != null && fileHandlerInUse) {
112: loggerDetail.append("Handler=");
113: loggerDetail.append(handlersValue);
114: loggerDetail.append(DELIMITER);
115: loggerDetail.append("Logs to File=");
116: loggerDetail.append(getPattern());
117: // Stack-trace
118: if (getStackTraceValue() != null) {
119: loggerDetail.append(DELIMITER);
120: loggerDetail.append("Print Stacktrace=");
121: loggerDetail.append(getStackTraceValue());
122: }
123: }
124: }
125:
126: return loggerDetail.toString();
127: }
128: }
|