admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package com.yeshi.fanli.log;
 
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
 
import org.apache.log4j.Logger;
 
import org.yeshi.utils.TimeUtil;
 
/**
 * 推送日志
 * 
 * @author Administrator
 *
 */
public class PushLogHelper {
    // log
    private static Logger xmLogger = Logger.getLogger("pushXMLog");
 
    private static Logger iosLogger = Logger.getLogger("pushIOSLog");
 
    private static Logger hwLogger = Logger.getLogger("pushHWLog");
 
    public static void xmInfo(Object obj) {
        xmLogger.info(obj);
    }
 
    public static void iosInfo(Object obj) {
        iosLogger.info(obj);
    }
 
    public static void hwInfo(Object obj) {
        hwLogger.info(obj);
    }
 
    public static void xmError(Throwable e) {
        String date = TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy_MM_dd");
        String os = System.getProperty("os.name");
        String filePath = String.format("/usr/local/tomcat8/logs/push/xm_error_detail_%s.txt", date);
        if (os.toLowerCase().startsWith("win")) {
            filePath = String.format("C:/logs/push/xm_error_detail_%s.txt", date);
        }
 
        try {
            saveErrorLog(e, filePath);
        } catch (IOException e1) {
        }
    }
 
    public static void iosError(Throwable e) {
        String date = TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy_MM_dd");
        String os = System.getProperty("os.name");
        String filePath = String.format("/usr/local/tomcat8/logs/push/ios_error_detail_%s.txt", date);
        if (os.toLowerCase().startsWith("win")) {
            filePath = String.format("C:/logs/push/ios_error_detail_%s.txt", date);
        }
 
        try {
            saveErrorLog(e, filePath);
        } catch (IOException e1) {
        }
    }
 
    public static void hwError(Throwable e) {
        String date = TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy_MM_dd");
        String os = System.getProperty("os.name");
        String filePath = String.format("/usr/local/tomcat8/logs/push/hw_error_detail_%s.txt", date);
        if (os.toLowerCase().startsWith("win")) {
            filePath = String.format("C:/logs/push/hw_error_detail_%s.txt", date);
        }
 
        try {
            saveErrorLog(e, filePath);
        } catch (IOException e1) {
        }
    }
    
    
    public static void oppoError(Throwable e) {
        String date = TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy_MM_dd");
        String os = System.getProperty("os.name");
        String filePath = String.format("/usr/local/tomcat8/logs/push/oppo_error_detail_%s.txt", date);
        if (os.toLowerCase().startsWith("win")) {
            filePath = String.format("C:/logs/push/oppo_error_detail_%s.txt", date);
        }
 
        try {
            saveErrorLog(e, filePath);
        } catch (IOException e1) {
        }
    }
    
    
    public static void vivoError(Throwable e) {
        String date = TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy_MM_dd");
        String os = System.getProperty("os.name");
        String filePath = String.format("/usr/local/tomcat8/logs/push/vivo_error_detail_%s.txt", date);
        if (os.toLowerCase().startsWith("win")) {
            filePath = String.format("C:/logs/push/vivo_error_detail_%s.txt", date);
        }
 
        try {
            saveErrorLog(e, filePath);
        } catch (IOException e1) {
        }
    }
 
    public static void saveErrorLog(Throwable e, String filePath) throws IOException {
        // 创建文件夹
        if (!new File(new File(filePath).getParent()).exists())
            new File(new File(filePath).getParent()).mkdirs();
        OutputStream out = new FileOutputStream(new File(filePath), true);
        try {
            PrintStream ps = new PrintStream(out);
            ps.print(TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
            ps.print("\n");
            e.printStackTrace(ps);
            ps.flush();
            ps.close();
        } finally {
            out.close();
        }
    }
 
}