You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ff...@apache.org on 2020/10/26 18:17:29 UTC

[cxf] branch 3.3.x-fixes updated: [CXF-8360]Configurable property for Apache Velocity logs

This is an automated email from the ASF dual-hosted git repository.

ffang pushed a commit to branch 3.3.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/3.3.x-fixes by this push:
     new 8d35406  [CXF-8360]Configurable property for Apache Velocity logs
8d35406 is described below

commit 8d35406e2a01944096278a422f683d12b969f7e7
Author: Freeman Fang <fr...@gmail.com>
AuthorDate: Mon Oct 26 14:16:13 2020 -0400

    [CXF-8360]Configurable property for Apache Velocity logs
    
    (cherry picked from commit 36e5ef9ba55fe5653cb0709bf2d9c0b991d14e93)
---
 .../org/apache/cxf/tools/common/VelocityGenerator.java  | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/tools/common/src/main/java/org/apache/cxf/tools/common/VelocityGenerator.java b/tools/common/src/main/java/org/apache/cxf/tools/common/VelocityGenerator.java
index 7147b89..59969d7 100644
--- a/tools/common/src/main/java/org/apache/cxf/tools/common/VelocityGenerator.java
+++ b/tools/common/src/main/java/org/apache/cxf/tools/common/VelocityGenerator.java
@@ -22,6 +22,7 @@ package org.apache.cxf.tools.common;
 import java.io.File;
 import java.io.IOException;
 import java.io.Writer;
+import java.lang.reflect.Constructor;
 import java.util.Calendar;
 import java.util.HashMap;
 import java.util.Map;
@@ -71,10 +72,18 @@ public final class VelocityGenerator {
             props.put("resource.loaders", "class");
             props.put("resource.loader.class.class", clzName);
             props.put("runtime.log", getVelocityLogFile("velocity.log"));
-//            if (!log) {
-//                props.put(VelocityEngine.RUNTIME_LOG_INSTANCE,
-//                          "org.apache.velocity.runtime.log.NullLogSystem");
-//            }
+            if (!log) {
+                try {
+                    Class<?> nopLoggerClass = Class.forName("org.slf4j.helpers.NOPLogger");
+                    Constructor<?> cons1 = nopLoggerClass.getDeclaredConstructor();
+                    cons1.setAccessible(true);
+                
+                    props.put(Velocity.RUNTIME_LOG_INSTANCE,
+                          cons1.newInstance());
+                } catch (Exception ex) {
+                    LOG.log(Level.INFO, ex.getMessage());
+                }
+            }
             Velocity.init(props);
         } catch (Exception e) {
             Message msg = new Message("FAIL_TO_INITIALIZE_VELOCITY_ENGINE", LOG);