You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2012/11/01 03:20:36 UTC

svn commit: r1404452 - in /logging/log4j/log4j2/trunk/core/src/test: java/org/apache/logging/log4j/core/appender/ resources/

Author: ggregory
Date: Thu Nov  1 02:20:36 2012
New Revision: 1404452

URL: http://svn.apache.org/viewvc?rev=1404452&view=rev
Log:
Shows how to use ANSI escape codes to color messages.

Added:
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiMessagesMain.java
      - copied, changed from r1404450, logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/ColorConsoleAnsiMessagesMain.java
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleLayoutMain.java   (with props)
    logging/log4j/log4j2/trunk/core/src/test/resources/log4j2-console-style-ansi.xml   (with props)
Removed:
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/ColorConsoleAnsiMessagesMain.java

Copied: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiMessagesMain.java (from r1404450, logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/ColorConsoleAnsiMessagesMain.java)
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiMessagesMain.java?p2=logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiMessagesMain.java&p1=logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/ColorConsoleAnsiMessagesMain.java&r1=1404450&r2=1404452&rev=1404452&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/ColorConsoleAnsiMessagesMain.java (original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiMessagesMain.java Thu Nov  1 02:20:36 2012
@@ -11,12 +11,12 @@ import org.apache.logging.log4j.core.con
  * Shows how to use ANSI escape codes to color messages. Each message is printed to the console in color, but the rest of the log entry
  * (time stamp for example) is in the default color for that console.
  */
-public class ColorConsoleAnsiMessagesMain {
+public class ConsoleAppenderAnsiMessagesMain {
 
-    private static final Logger LOG = LogManager.getLogger(ColorConsoleAnsiMessagesMain.class);
+    private static final Logger LOG = LogManager.getLogger(ConsoleAppenderAnsiMessagesMain.class);
 
     public static void main(String[] args) {
-        LoggerContext ctx = Configurator.initialize(ColorConsoleAnsiMessagesMain.class.getName(), null,
+        LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(), null,
                 "target/test-classes/log4j2-console.xml");
         try {
             LOG.fatal("\u001b[1;35mFatal message.\u001b[0m");

Added: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleLayoutMain.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleLayoutMain.java?rev=1404452&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleLayoutMain.java (added)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleLayoutMain.java Thu Nov  1 02:20:36 2012
@@ -0,0 +1,30 @@
+package org.apache.logging.log4j.core.appender;
+
+import java.io.IOException;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configurator;
+
+public class ConsoleAppenderAnsiStyleLayoutMain {
+
+    private static final Logger LOG = LogManager.getLogger(ConsoleAppenderAnsiStyleLayoutMain.class);
+
+    public static void main(String[] args) {
+        LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(), null,
+                "target/test-classes/log4j2-console-style-ansi.xml");
+        try {
+            LOG.fatal("Fatal message.");
+            LOG.error("Error message.");
+            LOG.warn("Warning message.");
+            LOG.info("Information message.");
+            LOG.debug("Debug message.");
+            LOG.trace("Trace message.");
+            LOG.error("Error message.", new IOException("test"));
+        } finally {
+            Configurator.shutdown(ctx);
+        }
+    }
+
+}

Propchange: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleLayoutMain.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleLayoutMain.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: logging/log4j/log4j2/trunk/core/src/test/resources/log4j2-console-style-ansi.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/resources/log4j2-console-style-ansi.xml?rev=1404452&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/resources/log4j2-console-style-ansi.xml (added)
+++ logging/log4j/log4j2/trunk/core/src/test/resources/log4j2-console-style-ansi.xml Thu Nov  1 02:20:36 2012
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+
+-->
+<configuration status="OFF">
+  <appenders>
+    <Console name="Console" target="SYSTEM_OUT">
+      <PatternLayout pattern="%style{%d{ ISO8601 }}{black} %style{[%t]}{blue} %style{%-5level:}{yellow} %style{%msg%n%throwable}{green}" />
+    </Console>
+  </appenders>
+  <loggers>
+    <logger name="org.foo" level="DEBUG" />
+    <root level="TRACE">
+      <appender-ref ref="Console" />
+    </root>
+  </loggers>
+</configuration>
\ No newline at end of file

Propchange: logging/log4j/log4j2/trunk/core/src/test/resources/log4j2-console-style-ansi.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/log4j2/trunk/core/src/test/resources/log4j2-console-style-ansi.xml
------------------------------------------------------------------------------
    svn:keywords = Id