dangsn
2025-01-16 d6e9b6f11fd8f36895eb70f092bdd8c412750111
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
package com.vci.dbsync.log;
 
import java.io.File;
import java.net.URL;
 
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
 
/**
 * <p>Title: </p>
 * <p>Description: use log4j to note some meaningful info.
 * the info has four kinds: INFO, DEBUG, WARN and ERROR.
 * it display log infos in console and save them into a
 * log file. Programeers can lookup useful info from them.
 * And programeers can set the level in 
 * properties/ServerWithLog4j.properties to decide which info
 * they want to save.</p>
 */
public class SyncLog {
    private static String log4j_properties_file_path_for_developer = "properties/dbSynclog4j.properties";
    private static String log4j_properties_file_path = "/" + log4j_properties_file_path_for_developer;
    private static URL log4j_properties_url = null;
    
    public static Logger logger = Logger.getLogger("SyncLog");
    
    static {
        File file =  new File(log4j_properties_file_path_for_developer);
        //log4j_properties_url = SyncLog.class.getResource(log4j_properties_file_path);
        String loadFrom = "";
        
        if(file.exists()){
            loadFrom = file.getAbsolutePath();
            PropertyConfigurator.configure(file.getAbsolutePath());
        } else {
            log4j_properties_url = SyncLog.class.getResource(log4j_properties_file_path);
            loadFrom = log4j_properties_url.toString();
            PropertyConfigurator.configure(log4j_properties_url);
        }
        
        logger.debug("log4j init completed. use properties file is " + loadFrom);
    }
    
}