Github user lizhanhui commented on a diff in the pull request:

    https://github.com/apache/incubator-rocketmq/pull/85#discussion_r111167855
  
    --- Diff: 
common/src/main/java/org/apache/rocketmq/common/utils/LogUtils.java ---
    @@ -0,0 +1,96 @@
    +/*
    + * 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.rocketmq.common.utils;
    +
    +import java.lang.reflect.InvocationTargetException;
    +import java.lang.reflect.Method;
    +import java.net.URL;
    +import org.slf4j.ILoggerFactory;
    +import org.slf4j.LoggerFactory;
    +
    +public class LogUtils {
    +
    +    /**
    +     * config logback dymatically from provided file path, otherwise try 
to config from resource file
    +     * @param logConfigFilePath specified logback configuration file path
    +     * @param logbackResourceFile specified logback configuration resource 
file, which will only be respected when logConfigFilePath is null
    +     * @param iLoggerFactory
    +     * @throws ClassNotFoundException
    +     * @throws InstantiationException
    +     * @throws IllegalAccessException
    +     * @throws NoSuchMethodException
    +     * @throws InvocationTargetException
    +     */
    +    public static void configLogback(String logConfigFilePath, String 
logbackResourceFile, ILoggerFactory iLoggerFactory) throws 
ClassNotFoundException, InstantiationException, IllegalAccessException, 
NoSuchMethodException, InvocationTargetException {
    +        Class<?> joranConfigurator;
    +        Class<?> context = Class.forName("ch.qos.logback.core.Context");
    +        Object joranConfiguratoroObj;
    +        joranConfigurator = 
Class.forName("ch.qos.logback.classic.joran.JoranConfigurator");
    +        joranConfiguratoroObj = joranConfigurator.newInstance();
    +        Method setContext = 
joranConfiguratoroObj.getClass().getMethod("setContext", context);
    +        setContext.invoke(joranConfiguratoroObj, iLoggerFactory);
    +        if (null == logConfigFilePath) {
    +            if (logbackResourceFile != null) {
    +                URL url = 
LogUtils.class.getClassLoader().getResource(logbackResourceFile);
    +                Method doConfigure = 
joranConfiguratoroObj.getClass().getMethod("doConfigure", URL.class);
    +                doConfigure.invoke(joranConfiguratoroObj, url);
    +            }
    +        } else {
    +            Method doConfigure = 
joranConfiguratoroObj.getClass().getMethod("doConfigure", String.class);
    +            doConfigure.invoke(joranConfiguratoroObj, logConfigFilePath);
    +        }
    +    }
    +
    +    /**
    +     * config log4j dymatically from provided file path, otherwise try to 
config from resource file. Notice that the log4j configuration file should be 
in xml format
    --- End diff --
    
    dymatically same as above.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to