wangting
2025-01-16 18c43123b51a1688ab4ae01fe3d171c7d92e619b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.vci.server.volume.uitls;
 
import java.io.File;
import java.io.FileInputStream;
import java.net.URL;
 
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
//import org.apache.logging.log4j.PropertyConfigurator;
import org.apache.logging.log4j.core.config.ConfigurationSource;
import org.apache.logging.log4j.core.config.Configurator;
 
import com.vci.common.log.ServerWithLog4j;
 
 
public class VolumeWithLog4j {
    private static String log4j_properties_dev = "properties/VolumnLog4j2.xml";
    private static String log4j_Properties = "/" + log4j_properties_dev;
    private static URL log4j_properties_url = null;
 
    public static Logger logger = null;//LogManager.getLogger("VolumnLog");
 
    static {
        try {
            File file =  new File(log4j_properties_dev);
            String loadFrom = "";
            
            if(file.exists()){
                loadFrom = file.getAbsolutePath();
            } else {
                log4j_properties_url = ServerWithLog4j.class.getResource(log4j_Properties);
                loadFrom = log4j_properties_url.toString();
            }
            
            ConfigurationSource source = new ConfigurationSource(new FileInputStream(loadFrom));
            Configurator.initialize(null, source);
            
            logger = LogManager.getLogger("VolumnLog");
            
            logger.debug("log4j init completed. use properties file is " + loadFrom);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}