Repository: logging-chainsaw Updated Branches: refs/heads/master f539452a7 -> 99e527104
Fix line endings issues Project: http://git-wip-us.apache.org/repos/asf/logging-chainsaw/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-chainsaw/commit/99e52710 Tree: http://git-wip-us.apache.org/repos/asf/logging-chainsaw/tree/99e52710 Diff: http://git-wip-us.apache.org/repos/asf/logging-chainsaw/diff/99e52710 Branch: refs/heads/master Commit: 99e527104a665bbd6d1584329f6fa8b6b065b214 Parents: f539452 Author: Matt Sicker <[email protected]> Authored: Sat Oct 14 13:05:06 2017 -0500 Committer: Matt Sicker <[email protected]> Committed: Sat Oct 14 13:05:06 2017 -0500 ---------------------------------------------------------------------- .../log4j/chainsaw/JTextComponentFormatter.java | 78 +-- .../log4j/chainsaw/LoggingEventWrapper.java | 380 ++++++------ .../chainsaw/receivers/VisualReceiver.java | 78 +-- .../org/apache/log4j/helpers/Constants.java | 260 ++++---- .../apache/log4j/xml/LogFileXMLReceiver.java | 620 +++++++++---------- 5 files changed, 708 insertions(+), 708 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/99e52710/src/main/java/org/apache/log4j/chainsaw/JTextComponentFormatter.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/JTextComponentFormatter.java b/src/main/java/org/apache/log4j/chainsaw/JTextComponentFormatter.java index 6039047..89ad68a 100644 --- a/src/main/java/org/apache/log4j/chainsaw/JTextComponentFormatter.java +++ b/src/main/java/org/apache/log4j/chainsaw/JTextComponentFormatter.java @@ -1,39 +1,39 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.log4j.chainsaw; - -import java.awt.Font; - -import javax.swing.UIManager; -import javax.swing.text.Document; -import javax.swing.text.JTextComponent; -import javax.swing.text.html.HTMLDocument; - -/** - * Apply system font and size (normal size + 1) rule if the JEditorPane document contains html. - */ -public class JTextComponentFormatter -{ - public static void applySystemFontAndSize(JTextComponent textComponent) { - Document document = textComponent.getDocument(); - if (document instanceof HTMLDocument) { - Font font = UIManager.getFont("Label.font"); - String bodyRule = "body { font-family: " + font.getFamily() + "; font-size: " + (font.getSize() + 1) + "pt; }"; - ((HTMLDocument)document).getStyleSheet().addRule(bodyRule); - } - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.log4j.chainsaw; + +import java.awt.Font; + +import javax.swing.UIManager; +import javax.swing.text.Document; +import javax.swing.text.JTextComponent; +import javax.swing.text.html.HTMLDocument; + +/** + * Apply system font and size (normal size + 1) rule if the JEditorPane document contains html. + */ +public class JTextComponentFormatter +{ + public static void applySystemFontAndSize(JTextComponent textComponent) { + Document document = textComponent.getDocument(); + if (document instanceof HTMLDocument) { + Font font = UIManager.getFont("Label.font"); + String bodyRule = "body { font-family: " + font.getFamily() + "; font-size: " + (font.getSize() + 1) + "pt; }"; + ((HTMLDocument)document).getStyleSheet().addRule(bodyRule); + } + } +} http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/99e52710/src/main/java/org/apache/log4j/chainsaw/LoggingEventWrapper.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/LoggingEventWrapper.java b/src/main/java/org/apache/log4j/chainsaw/LoggingEventWrapper.java index 30429a3..63363a3 100644 --- a/src/main/java/org/apache/log4j/chainsaw/LoggingEventWrapper.java +++ b/src/main/java/org/apache/log4j/chainsaw/LoggingEventWrapper.java @@ -1,190 +1,190 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.log4j.chainsaw; - -import java.awt.Color; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -import org.apache.log4j.helpers.Constants; -import org.apache.log4j.rule.Rule; -import org.apache.log4j.spi.LoggingEvent; - -/** - * Wrap access to a LoggingEvent. All property updates need to go through this object and not through the wrapped logging event, - * since the properties are shared by two views of the same backing LoggingEvent, and loggingEvent itself creates a copy of passed-in properties.. - * - * Property reads can be made on the actual LoggingEvent. - */ -public class LoggingEventWrapper { - private final LoggingEvent loggingEvent; - private static final int DEFAULT_HEIGHT = -1; - - private Color colorRuleBackground = ChainsawConstants.COLOR_DEFAULT_BACKGROUND; - private Color colorRuleForeground = ChainsawConstants.COLOR_DEFAULT_FOREGROUND; - private int markerHeight = DEFAULT_HEIGHT; - private int msgHeight = DEFAULT_HEIGHT; - - //set to the log4jid value via setId - assumed to never change - private int id; - - private boolean searchMatch = false; - //a Map of event fields to Sets of string matches (can be used to render matches differently) - Map eventMatches = new HashMap(); - private LoggingEventWrapper syncWrapper; - private boolean displayed; - - public LoggingEventWrapper(LoggingEvent loggingEvent) { - this.loggingEvent = loggingEvent; - } - - public LoggingEventWrapper(LoggingEventWrapper loggingEventWrapper) { - this.loggingEvent = loggingEventWrapper.getLoggingEvent(); - this.id = loggingEventWrapper.id; - this.syncWrapper = loggingEventWrapper; - loggingEventWrapper.syncWrapper = this; - } - - public LoggingEvent getLoggingEvent() { - return loggingEvent; - } - - public void setProperty(String propName, String propValue) { - loggingEvent.setProperty(propName, propValue); - if (id == 0 && propName.equals(Constants.LOG4J_ID_KEY)) { - id = Integer.parseInt(propValue); - } - if (syncWrapper != null && !propName.equals(ChainsawConstants.MILLIS_DELTA_COL_NAME_LOWERCASE)) { - syncWrapper.getLoggingEvent().setProperty(propName, propValue); - } - } - - public Object removeProperty(String propName) { - Object result = loggingEvent.removeProperty(propName); - if (syncWrapper != null && !propName.equals(ChainsawConstants.MILLIS_DELTA_COL_NAME_LOWERCASE)) { - syncWrapper.getLoggingEvent().removeProperty(propName); - } - return result; - } - - public Set getPropertyKeySet() { - return loggingEvent.getPropertyKeySet(); - } - - public void updateColorRuleColors(Color backgroundColor, Color foregroundColor) { - if (backgroundColor != null && foregroundColor != null) { - this.colorRuleBackground = backgroundColor; - this.colorRuleForeground = foregroundColor; - if (syncWrapper != null) { - syncWrapper.colorRuleBackground = this.colorRuleBackground; - syncWrapper.colorRuleForeground = this.colorRuleForeground; - } - } else { - this.colorRuleBackground = ChainsawConstants.COLOR_DEFAULT_BACKGROUND; - this.colorRuleForeground = ChainsawConstants.COLOR_DEFAULT_FOREGROUND; - if (syncWrapper != null) { - syncWrapper.colorRuleBackground = this.colorRuleBackground; - syncWrapper.colorRuleForeground = this.colorRuleForeground; - } - } - } - - public void evaluateSearchRule(Rule searchRule) { - eventMatches.clear(); - searchMatch = searchRule != null && searchRule.evaluate(loggingEvent, eventMatches); - } - - public Map getSearchMatches() { - return eventMatches; - } - - public Color getForeground() { - return colorRuleForeground; - } - - public Color getBackground() { - return colorRuleBackground; - } - - public Color getColorRuleBackground() { - return colorRuleBackground; - } - - public Color getColorRuleForeground() { - return colorRuleForeground; - } - - public boolean isSearchMatch() { - return searchMatch; - } - - public void setMarkerHeight(int markerHeight) { - this.markerHeight = markerHeight; - } - - public int getMarkerHeight() { - return markerHeight; - } - - public void setMsgHeight(int msgHeight) { - this.msgHeight = msgHeight; - } - - public int getMsgHeight() { - return msgHeight; - } - - public void setDisplayed(boolean b) { - markerHeight = DEFAULT_HEIGHT; - msgHeight = DEFAULT_HEIGHT; - displayed = b; - } - - public void setPreviousDisplayedEventTimestamp(long previousDisplayedEventTimeStamp) { - setProperty(ChainsawConstants.MILLIS_DELTA_COL_NAME_LOWERCASE, String.valueOf(loggingEvent.getTimeStamp() - previousDisplayedEventTimeStamp)); - } - - public boolean isDisplayed() { - return displayed; - } - - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - LoggingEventWrapper that = (LoggingEventWrapper) o; - - if (id != that.id) { - return false; - } - - return true; - } - - public int hashCode() { - return id; - } - - public String toString() { - return "LoggingEventWrapper - id: " + id + " background: " + getBackground() + ", foreground: " + getForeground() + ", msg: " + loggingEvent.getMessage(); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.log4j.chainsaw; + +import java.awt.Color; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import org.apache.log4j.helpers.Constants; +import org.apache.log4j.rule.Rule; +import org.apache.log4j.spi.LoggingEvent; + +/** + * Wrap access to a LoggingEvent. All property updates need to go through this object and not through the wrapped logging event, + * since the properties are shared by two views of the same backing LoggingEvent, and loggingEvent itself creates a copy of passed-in properties.. + * + * Property reads can be made on the actual LoggingEvent. + */ +public class LoggingEventWrapper { + private final LoggingEvent loggingEvent; + private static final int DEFAULT_HEIGHT = -1; + + private Color colorRuleBackground = ChainsawConstants.COLOR_DEFAULT_BACKGROUND; + private Color colorRuleForeground = ChainsawConstants.COLOR_DEFAULT_FOREGROUND; + private int markerHeight = DEFAULT_HEIGHT; + private int msgHeight = DEFAULT_HEIGHT; + + //set to the log4jid value via setId - assumed to never change + private int id; + + private boolean searchMatch = false; + //a Map of event fields to Sets of string matches (can be used to render matches differently) + Map eventMatches = new HashMap(); + private LoggingEventWrapper syncWrapper; + private boolean displayed; + + public LoggingEventWrapper(LoggingEvent loggingEvent) { + this.loggingEvent = loggingEvent; + } + + public LoggingEventWrapper(LoggingEventWrapper loggingEventWrapper) { + this.loggingEvent = loggingEventWrapper.getLoggingEvent(); + this.id = loggingEventWrapper.id; + this.syncWrapper = loggingEventWrapper; + loggingEventWrapper.syncWrapper = this; + } + + public LoggingEvent getLoggingEvent() { + return loggingEvent; + } + + public void setProperty(String propName, String propValue) { + loggingEvent.setProperty(propName, propValue); + if (id == 0 && propName.equals(Constants.LOG4J_ID_KEY)) { + id = Integer.parseInt(propValue); + } + if (syncWrapper != null && !propName.equals(ChainsawConstants.MILLIS_DELTA_COL_NAME_LOWERCASE)) { + syncWrapper.getLoggingEvent().setProperty(propName, propValue); + } + } + + public Object removeProperty(String propName) { + Object result = loggingEvent.removeProperty(propName); + if (syncWrapper != null && !propName.equals(ChainsawConstants.MILLIS_DELTA_COL_NAME_LOWERCASE)) { + syncWrapper.getLoggingEvent().removeProperty(propName); + } + return result; + } + + public Set getPropertyKeySet() { + return loggingEvent.getPropertyKeySet(); + } + + public void updateColorRuleColors(Color backgroundColor, Color foregroundColor) { + if (backgroundColor != null && foregroundColor != null) { + this.colorRuleBackground = backgroundColor; + this.colorRuleForeground = foregroundColor; + if (syncWrapper != null) { + syncWrapper.colorRuleBackground = this.colorRuleBackground; + syncWrapper.colorRuleForeground = this.colorRuleForeground; + } + } else { + this.colorRuleBackground = ChainsawConstants.COLOR_DEFAULT_BACKGROUND; + this.colorRuleForeground = ChainsawConstants.COLOR_DEFAULT_FOREGROUND; + if (syncWrapper != null) { + syncWrapper.colorRuleBackground = this.colorRuleBackground; + syncWrapper.colorRuleForeground = this.colorRuleForeground; + } + } + } + + public void evaluateSearchRule(Rule searchRule) { + eventMatches.clear(); + searchMatch = searchRule != null && searchRule.evaluate(loggingEvent, eventMatches); + } + + public Map getSearchMatches() { + return eventMatches; + } + + public Color getForeground() { + return colorRuleForeground; + } + + public Color getBackground() { + return colorRuleBackground; + } + + public Color getColorRuleBackground() { + return colorRuleBackground; + } + + public Color getColorRuleForeground() { + return colorRuleForeground; + } + + public boolean isSearchMatch() { + return searchMatch; + } + + public void setMarkerHeight(int markerHeight) { + this.markerHeight = markerHeight; + } + + public int getMarkerHeight() { + return markerHeight; + } + + public void setMsgHeight(int msgHeight) { + this.msgHeight = msgHeight; + } + + public int getMsgHeight() { + return msgHeight; + } + + public void setDisplayed(boolean b) { + markerHeight = DEFAULT_HEIGHT; + msgHeight = DEFAULT_HEIGHT; + displayed = b; + } + + public void setPreviousDisplayedEventTimestamp(long previousDisplayedEventTimeStamp) { + setProperty(ChainsawConstants.MILLIS_DELTA_COL_NAME_LOWERCASE, String.valueOf(loggingEvent.getTimeStamp() - previousDisplayedEventTimeStamp)); + } + + public boolean isDisplayed() { + return displayed; + } + + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + LoggingEventWrapper that = (LoggingEventWrapper) o; + + if (id != that.id) { + return false; + } + + return true; + } + + public int hashCode() { + return id; + } + + public String toString() { + return "LoggingEventWrapper - id: " + id + " background: " + getBackground() + ", foreground: " + getForeground() + ", msg: " + loggingEvent.getMessage(); + } +} http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/99e52710/src/main/java/org/apache/log4j/chainsaw/receivers/VisualReceiver.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/receivers/VisualReceiver.java b/src/main/java/org/apache/log4j/chainsaw/receivers/VisualReceiver.java index d5e2be7..29ffd31 100644 --- a/src/main/java/org/apache/log4j/chainsaw/receivers/VisualReceiver.java +++ b/src/main/java/org/apache/log4j/chainsaw/receivers/VisualReceiver.java @@ -1,39 +1,39 @@ -/* - * Copyright 1999,2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.log4j.chainsaw.receivers; - -import java.awt.Container; - -/** - * If a receiver has a visual component, implement this interface and Chainsaw will call - * 'setContainer' passing in a container that the receiver can use. - * <p> - * For example, VFSLogFilePatternReceiver provides an optional 'promptForUserInfo', that - * when set to true, will allow a login dialog to be displayed on top of the Chainsaw window. - * - * @author Scott Deboy<[email protected]> - * - */ - -public interface VisualReceiver { - /** - * Provides access to a container. - * - * @param container - */ - void setContainer(Container container); -} +/* + * Copyright 1999,2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.log4j.chainsaw.receivers; + +import java.awt.Container; + +/** + * If a receiver has a visual component, implement this interface and Chainsaw will call + * 'setContainer' passing in a container that the receiver can use. + * <p> + * For example, VFSLogFilePatternReceiver provides an optional 'promptForUserInfo', that + * when set to true, will allow a login dialog to be displayed on top of the Chainsaw window. + * + * @author Scott Deboy<[email protected]> + * + */ + +public interface VisualReceiver { + /** + * Provides access to a container. + * + * @param container + */ + void setContainer(Container container); +} http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/99e52710/src/main/java/org/apache/log4j/helpers/Constants.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/helpers/Constants.java b/src/main/java/org/apache/log4j/helpers/Constants.java index 2e181fa..82b06c7 100644 --- a/src/main/java/org/apache/log4j/helpers/Constants.java +++ b/src/main/java/org/apache/log4j/helpers/Constants.java @@ -1,130 +1,130 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.log4j.helpers; - - -/** - * Constants used internally throughout log4j. - * - */ -public interface Constants { - - /** - * log4j package name string literal. - */ - String LOG4J_PACKAGE_NAME = "org.apache.log4j"; - - /** - * The name of the default repository is "default" (without the quotes). - */ - String DEFAULT_REPOSITORY_NAME = "default"; - - /** - * application string literal. - */ - String APPLICATION_KEY = "application"; - /** - * hostname string literal. - */ - String HOSTNAME_KEY = "hostname"; - /** - * receiver string literal. - */ - String RECEIVER_NAME_KEY = "receiver"; - /** - * group string literal. - */ - String GROUP_KEY = "group"; - /** - * log4jid string literal. - */ - String LOG4J_ID_KEY = "log4jid"; - /** - * time stamp pattern string literal. - */ - String TIMESTAMP_RULE_FORMAT = "yyyy/MM/dd HH:mm:ss"; - - /** - * The default property file name for automatic configuration. - */ - String DEFAULT_CONFIGURATION_FILE = "log4j.properties"; - /** - * The default XML configuration file name for automatic configuration. - */ - String DEFAULT_XML_CONFIGURATION_FILE = "log4j.xml"; - /** - * log4j.configuration string literal. - */ - String DEFAULT_CONFIGURATION_KEY = "log4j.configuration"; - /** - * log4j.configuratorClass string literal. - */ - String CONFIGURATOR_CLASS_KEY = "log4j.configuratorClass"; - - /** - * JNDI context name string literal. - */ - String JNDI_CONTEXT_NAME = "java:comp/env/log4j/context-name"; - - /** - * TEMP_LIST_APPENDER string literal. - */ - String TEMP_LIST_APPENDER_NAME = "TEMP_LIST_APPENDER"; - /** - * TEMP_CONSOLE_APPENDER string literal. - */ - String TEMP_CONSOLE_APPENDER_NAME = "TEMP_CONSOLE_APPENDER"; - /** - * Codes URL string literal. - */ - String CODES_HREF = - "http://logging.apache.org/log4j/docs/codes.html"; - - - /** - * ABSOLUTE string literal. - */ - String ABSOLUTE_FORMAT = "ABSOLUTE"; - /** - * SimpleTimePattern for ABSOLUTE. - */ - String ABSOLUTE_TIME_PATTERN = "HH:mm:ss,SSS"; - - /** - * SimpleTimePattern for ABSOLUTE. - */ - String SIMPLE_TIME_PATTERN = "HH:mm:ss"; - - /** - * DATE string literal. - */ - String DATE_AND_TIME_FORMAT = "DATE"; - /** - * SimpleTimePattern for DATE. - */ - String DATE_AND_TIME_PATTERN = "dd MMM yyyy HH:mm:ss,SSS"; - - /** - * ISO8601 string literal. - */ - String ISO8601_FORMAT = "ISO8601"; - /** - * SimpleTimePattern for ISO8601. - */ - String ISO8601_PATTERN = "yyyy-MM-dd HH:mm:ss,SSS"; -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.log4j.helpers; + + +/** + * Constants used internally throughout log4j. + * + */ +public interface Constants { + + /** + * log4j package name string literal. + */ + String LOG4J_PACKAGE_NAME = "org.apache.log4j"; + + /** + * The name of the default repository is "default" (without the quotes). + */ + String DEFAULT_REPOSITORY_NAME = "default"; + + /** + * application string literal. + */ + String APPLICATION_KEY = "application"; + /** + * hostname string literal. + */ + String HOSTNAME_KEY = "hostname"; + /** + * receiver string literal. + */ + String RECEIVER_NAME_KEY = "receiver"; + /** + * group string literal. + */ + String GROUP_KEY = "group"; + /** + * log4jid string literal. + */ + String LOG4J_ID_KEY = "log4jid"; + /** + * time stamp pattern string literal. + */ + String TIMESTAMP_RULE_FORMAT = "yyyy/MM/dd HH:mm:ss"; + + /** + * The default property file name for automatic configuration. + */ + String DEFAULT_CONFIGURATION_FILE = "log4j.properties"; + /** + * The default XML configuration file name for automatic configuration. + */ + String DEFAULT_XML_CONFIGURATION_FILE = "log4j.xml"; + /** + * log4j.configuration string literal. + */ + String DEFAULT_CONFIGURATION_KEY = "log4j.configuration"; + /** + * log4j.configuratorClass string literal. + */ + String CONFIGURATOR_CLASS_KEY = "log4j.configuratorClass"; + + /** + * JNDI context name string literal. + */ + String JNDI_CONTEXT_NAME = "java:comp/env/log4j/context-name"; + + /** + * TEMP_LIST_APPENDER string literal. + */ + String TEMP_LIST_APPENDER_NAME = "TEMP_LIST_APPENDER"; + /** + * TEMP_CONSOLE_APPENDER string literal. + */ + String TEMP_CONSOLE_APPENDER_NAME = "TEMP_CONSOLE_APPENDER"; + /** + * Codes URL string literal. + */ + String CODES_HREF = + "http://logging.apache.org/log4j/docs/codes.html"; + + + /** + * ABSOLUTE string literal. + */ + String ABSOLUTE_FORMAT = "ABSOLUTE"; + /** + * SimpleTimePattern for ABSOLUTE. + */ + String ABSOLUTE_TIME_PATTERN = "HH:mm:ss,SSS"; + + /** + * SimpleTimePattern for ABSOLUTE. + */ + String SIMPLE_TIME_PATTERN = "HH:mm:ss"; + + /** + * DATE string literal. + */ + String DATE_AND_TIME_FORMAT = "DATE"; + /** + * SimpleTimePattern for DATE. + */ + String DATE_AND_TIME_PATTERN = "dd MMM yyyy HH:mm:ss,SSS"; + + /** + * ISO8601 string literal. + */ + String ISO8601_FORMAT = "ISO8601"; + /** + * SimpleTimePattern for ISO8601. + */ + String ISO8601_PATTERN = "yyyy-MM-dd HH:mm:ss,SSS"; +} http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/99e52710/src/main/java/org/apache/log4j/xml/LogFileXMLReceiver.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/xml/LogFileXMLReceiver.java b/src/main/java/org/apache/log4j/xml/LogFileXMLReceiver.java index 52805da..dbd8e9d 100644 --- a/src/main/java/org/apache/log4j/xml/LogFileXMLReceiver.java +++ b/src/main/java/org/apache/log4j/xml/LogFileXMLReceiver.java @@ -1,310 +1,310 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.log4j.xml; - -import java.io.BufferedReader; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.Reader; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Collection; -import java.util.Iterator; - -import org.apache.log4j.helpers.Constants; -import org.apache.log4j.plugins.Receiver; -import org.apache.log4j.rule.ExpressionRule; -import org.apache.log4j.rule.Rule; -import org.apache.log4j.spi.Decoder; -import org.apache.log4j.spi.LoggingEvent; - -/** - * LogFileXMLReceiver will read an xml-formated log file and make the events in the log file - * available to the log4j framework. - * <p> - * This receiver supports log files created using log4j's XMLLayout, as well as java.util.logging - * XMLFormatter (via the org.apache.log4j.spi.Decoder interface). - * <p> - * By default, log4j's XMLLayout is supported (no need to specify a decoder in that case). - * <p> - * To configure this receiver to support java.util.logging's XMLFormatter, specify a 'decoder' param - * of org.apache.log4j.xml.UtilLoggingXMLDecoder. - * <p> - * Tailing -may- work, but not in all cases (try using a file:// URL). If a process has a log file - * open, the receiver may be able to read and tail the file. If the process closes the file and - * reopens the file, the receiver may not be able to continue tailing the file. - * <p> - * An expressionFilter may be specified. Only events passing the expression will be forwarded to the - * log4j framework. - * <p> - * Once the event has been "posted", it will be handled by the appenders currently configured in the - * LoggerRespository. - * - * @author Scott Deboy <[email protected]> - * @since 1.3 - */ - -public class LogFileXMLReceiver extends Receiver { - private String fileURL; - private Rule expressionRule; - private String filterExpression; - private String decoder = "org.apache.log4j.xml.XMLDecoder"; - private boolean tailing = false; - - private Decoder decoderInstance; - private Reader reader; - private static final String FILE_KEY = "file"; - private String host; - private String path; - private boolean useCurrentThread; - - /** - * Accessor - * - * @return file URL - */ - public String getFileURL() { - return fileURL; - } - - /** - * Specify the URL of the XML-formatted file to process. - * - * @param fileURL - */ - public void setFileURL(String fileURL) { - this.fileURL = fileURL; - } - - /** - * Accessor - * - * @return - */ - public String getDecoder() { - return decoder; - } - - /** - * Specify the class name implementing org.apache.log4j.spi.Decoder that can process the file. - * - * @param _decoder - */ - public void setDecoder(String _decoder) { - decoder = _decoder; - } - - /** - * Accessor - * - * @return filter expression - */ - public String getFilterExpression() { - return filterExpression; - } - - /** - * Accessor - * - * @return tailing flag - */ - public boolean isTailing() { - return tailing; - } - - /** - * Set the 'tailing' flag - may only work on file:// URLs and may stop tailing if the writing - * process closes the file and reopens. - * - * @param tailing - */ - public void setTailing(boolean tailing) { - this.tailing = tailing; - } - - /** - * Set the filter expression that will cause only events which pass the filter to be forwarded - * to the log4j framework. - * - * @param filterExpression - */ - public void setFilterExpression(String filterExpression) { - this.filterExpression = filterExpression; - } - - private boolean passesExpression(LoggingEvent event) { - if (event != null) { - if (expressionRule != null) { - return (expressionRule.evaluate(event, null)); - } - } - return true; - } - - public static void main(String[] args) { - /* - * LogFileXMLReceiver test = new LogFileXMLReceiver(); - * test.setFileURL("file:///c:/samplelog.xml"); test.setFilterExpression("level >= TRACE"); - * test.activateOptions(); - */ - } - - /** - * Close the receiver, release any resources that are accessing the file. - */ - public void shutdown() { - try { - if (reader != null) { - reader.close(); - reader = null; - } - } catch (IOException ioe) { - ioe.printStackTrace(); - } - } - - /** - * Process the file - */ - public void activateOptions() { - Runnable runnable = new Runnable() { - public void run() { - try { - URL url = new URL(fileURL); - host = url.getHost(); - if (host != null && host.equals("")) { - host = FILE_KEY; - } - path = url.getPath(); - } catch (MalformedURLException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - - try { - if (filterExpression != null) { - expressionRule = ExpressionRule.getRule(filterExpression); - } - } catch (Exception e) { - getLogger().warn("Invalid filter expression: " + filterExpression, e); - } - - Class c; - try { - c = Class.forName(decoder); - Object o = c.newInstance(); - if (o instanceof Decoder) { - decoderInstance = (Decoder) o; - } - } catch (ClassNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InstantiationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - try { - reader = new InputStreamReader(new URL(getFileURL()).openStream()); - process(reader); - } catch (FileNotFoundException fnfe) { - getLogger().info("file not available"); - } catch (IOException ioe) { - getLogger().warn("unable to load file", ioe); - return; - } - } - }; - if (useCurrentThread) { - runnable.run(); - } else { - Thread thread = new Thread(runnable, "LogFileXMLReceiver-" + getName()); - - thread.start(); - - } - } - - private void process(Reader unbufferedReader) throws IOException { - BufferedReader bufferedReader = new BufferedReader(unbufferedReader); - char[] content = new char[10000]; - getLogger().debug("processing starting: " + fileURL); - int length = 0; - do { - System.out.println("in do loop-about to process"); - while ((length = bufferedReader.read(content)) > -1) { - processEvents(decoderInstance.decodeEvents(String.valueOf(content, 0, length))); - } - if (tailing) { - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } while (tailing); - getLogger().debug("processing complete: " + fileURL); - - shutdown(); - } - - private void processEvents(Collection c) { - if (c == null) { - return; - } - - for (Iterator iter = c.iterator(); iter.hasNext();) { - LoggingEvent evt = (LoggingEvent) iter.next(); - if (passesExpression(evt)) { - if (evt.getProperty(Constants.HOSTNAME_KEY) != null) { - evt.setProperty(Constants.HOSTNAME_KEY, host); - } - if (evt.getProperty(Constants.APPLICATION_KEY) != null) { - evt.setProperty(Constants.APPLICATION_KEY, path); - } - doPost(evt); - } - } - } - - /** - * When true, this property uses the current Thread to perform the import, otherwise when false - * (the default), a new Thread is created and started to manage the import. - * - * @return - */ - public final boolean isUseCurrentThread() { - return useCurrentThread; - } - - /** - * Sets whether the current Thread or a new Thread is created to perform the import, the default - * being false (new Thread created). - * - * @param useCurrentThread - */ - public final void setUseCurrentThread(boolean useCurrentThread) { - this.useCurrentThread = useCurrentThread; - } - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.log4j.xml; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Collection; +import java.util.Iterator; + +import org.apache.log4j.helpers.Constants; +import org.apache.log4j.plugins.Receiver; +import org.apache.log4j.rule.ExpressionRule; +import org.apache.log4j.rule.Rule; +import org.apache.log4j.spi.Decoder; +import org.apache.log4j.spi.LoggingEvent; + +/** + * LogFileXMLReceiver will read an xml-formated log file and make the events in the log file + * available to the log4j framework. + * <p> + * This receiver supports log files created using log4j's XMLLayout, as well as java.util.logging + * XMLFormatter (via the org.apache.log4j.spi.Decoder interface). + * <p> + * By default, log4j's XMLLayout is supported (no need to specify a decoder in that case). + * <p> + * To configure this receiver to support java.util.logging's XMLFormatter, specify a 'decoder' param + * of org.apache.log4j.xml.UtilLoggingXMLDecoder. + * <p> + * Tailing -may- work, but not in all cases (try using a file:// URL). If a process has a log file + * open, the receiver may be able to read and tail the file. If the process closes the file and + * reopens the file, the receiver may not be able to continue tailing the file. + * <p> + * An expressionFilter may be specified. Only events passing the expression will be forwarded to the + * log4j framework. + * <p> + * Once the event has been "posted", it will be handled by the appenders currently configured in the + * LoggerRespository. + * + * @author Scott Deboy <[email protected]> + * @since 1.3 + */ + +public class LogFileXMLReceiver extends Receiver { + private String fileURL; + private Rule expressionRule; + private String filterExpression; + private String decoder = "org.apache.log4j.xml.XMLDecoder"; + private boolean tailing = false; + + private Decoder decoderInstance; + private Reader reader; + private static final String FILE_KEY = "file"; + private String host; + private String path; + private boolean useCurrentThread; + + /** + * Accessor + * + * @return file URL + */ + public String getFileURL() { + return fileURL; + } + + /** + * Specify the URL of the XML-formatted file to process. + * + * @param fileURL + */ + public void setFileURL(String fileURL) { + this.fileURL = fileURL; + } + + /** + * Accessor + * + * @return + */ + public String getDecoder() { + return decoder; + } + + /** + * Specify the class name implementing org.apache.log4j.spi.Decoder that can process the file. + * + * @param _decoder + */ + public void setDecoder(String _decoder) { + decoder = _decoder; + } + + /** + * Accessor + * + * @return filter expression + */ + public String getFilterExpression() { + return filterExpression; + } + + /** + * Accessor + * + * @return tailing flag + */ + public boolean isTailing() { + return tailing; + } + + /** + * Set the 'tailing' flag - may only work on file:// URLs and may stop tailing if the writing + * process closes the file and reopens. + * + * @param tailing + */ + public void setTailing(boolean tailing) { + this.tailing = tailing; + } + + /** + * Set the filter expression that will cause only events which pass the filter to be forwarded + * to the log4j framework. + * + * @param filterExpression + */ + public void setFilterExpression(String filterExpression) { + this.filterExpression = filterExpression; + } + + private boolean passesExpression(LoggingEvent event) { + if (event != null) { + if (expressionRule != null) { + return (expressionRule.evaluate(event, null)); + } + } + return true; + } + + public static void main(String[] args) { + /* + * LogFileXMLReceiver test = new LogFileXMLReceiver(); + * test.setFileURL("file:///c:/samplelog.xml"); test.setFilterExpression("level >= TRACE"); + * test.activateOptions(); + */ + } + + /** + * Close the receiver, release any resources that are accessing the file. + */ + public void shutdown() { + try { + if (reader != null) { + reader.close(); + reader = null; + } + } catch (IOException ioe) { + ioe.printStackTrace(); + } + } + + /** + * Process the file + */ + public void activateOptions() { + Runnable runnable = new Runnable() { + public void run() { + try { + URL url = new URL(fileURL); + host = url.getHost(); + if (host != null && host.equals("")) { + host = FILE_KEY; + } + path = url.getPath(); + } catch (MalformedURLException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + try { + if (filterExpression != null) { + expressionRule = ExpressionRule.getRule(filterExpression); + } + } catch (Exception e) { + getLogger().warn("Invalid filter expression: " + filterExpression, e); + } + + Class c; + try { + c = Class.forName(decoder); + Object o = c.newInstance(); + if (o instanceof Decoder) { + decoderInstance = (Decoder) o; + } + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + try { + reader = new InputStreamReader(new URL(getFileURL()).openStream()); + process(reader); + } catch (FileNotFoundException fnfe) { + getLogger().info("file not available"); + } catch (IOException ioe) { + getLogger().warn("unable to load file", ioe); + return; + } + } + }; + if (useCurrentThread) { + runnable.run(); + } else { + Thread thread = new Thread(runnable, "LogFileXMLReceiver-" + getName()); + + thread.start(); + + } + } + + private void process(Reader unbufferedReader) throws IOException { + BufferedReader bufferedReader = new BufferedReader(unbufferedReader); + char[] content = new char[10000]; + getLogger().debug("processing starting: " + fileURL); + int length = 0; + do { + System.out.println("in do loop-about to process"); + while ((length = bufferedReader.read(content)) > -1) { + processEvents(decoderInstance.decodeEvents(String.valueOf(content, 0, length))); + } + if (tailing) { + try { + Thread.sleep(5000); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } while (tailing); + getLogger().debug("processing complete: " + fileURL); + + shutdown(); + } + + private void processEvents(Collection c) { + if (c == null) { + return; + } + + for (Iterator iter = c.iterator(); iter.hasNext();) { + LoggingEvent evt = (LoggingEvent) iter.next(); + if (passesExpression(evt)) { + if (evt.getProperty(Constants.HOSTNAME_KEY) != null) { + evt.setProperty(Constants.HOSTNAME_KEY, host); + } + if (evt.getProperty(Constants.APPLICATION_KEY) != null) { + evt.setProperty(Constants.APPLICATION_KEY, path); + } + doPost(evt); + } + } + } + + /** + * When true, this property uses the current Thread to perform the import, otherwise when false + * (the default), a new Thread is created and started to manage the import. + * + * @return + */ + public final boolean isUseCurrentThread() { + return useCurrentThread; + } + + /** + * Sets whether the current Thread or a new Thread is created to perform the import, the default + * being false (new Thread created). + * + * @param useCurrentThread + */ + public final void setUseCurrentThread(boolean useCurrentThread) { + this.useCurrentThread = useCurrentThread; + } + +}
