Administrator
2018-10-30 7bf6a0582c7c62c90ee2ed8a88654f11d0479092
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
package com.yeshi.fanli.log;
 
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.PrintStream;
 
import org.apache.log4j.Logger;
 
import com.yeshi.fanli.util.TimeUtil;
 
public class LogHelper {
    // log
    private static Logger userLogger = Logger.getLogger("userInfoLog");
 
    private static Logger orderLogger = Logger.getLogger("orderLog");
 
    private static Logger userOrderLogger = Logger.getLogger("userOrderLog");
 
    private static Logger cookieLogger = Logger.getLogger("cookieLog");
 
    private static Logger testLogger = Logger.getLogger("testLog");
 
    private static Logger errorLogger = Logger.getLogger("errorLog");
 
    private static Logger httpLogger = Logger.getLogger("httpLog");
 
    private static Logger taoBaoLinkLog = Logger.getLogger("taoBaoLinkLog");
 
    private static Logger shareGoodsLogger = Logger.getLogger("shareGoodsLog");
 
    public static void userInfo(Object obj) {
        userLogger.info(obj);
    }
 
    public static void userErrorInfo(Object obj) {
        userLogger.error(obj);
    }
 
    public static void orderInfo(Object obj) {
        orderLogger.info(obj);
    }
 
    public static void orderErrorInfo(Object obj) {
        orderLogger.error(obj);
    }
 
    public static void cookieLog(Object obj) {
        cookieLogger.info(obj);
    }
 
    public static void userOrder(Object obj) {
        userOrderLogger.info(obj);
    }
 
    public static void test(Object obj) {
        testLogger.info(obj);
    }
 
    public static void error(Object obj) {
        errorLogger.info(obj);
    }
 
    public static void taoBaoLinkError(Object obj) {
        taoBaoLinkLog.info(obj);
    }
 
    public static void shareGoods(Object obj) {
        shareGoodsLogger.info(obj);
    }
 
    public static void errorDetailInfo(Throwable e) throws Exception {
        e.printStackTrace();
        String date = TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy_MM_dd");
        String os = System.getProperty("os.name");
        String filePath = String.format("/usr/local/tomcat8/logs/error_detail_%s.txt", date);
        if (os.toLowerCase().startsWith("win")) {
            filePath = String.format("C:/logs/error_detail_%s.txt", date);
        } else
            filePath = String.format("/usr/local/tomcat8/logs/error_detail_%s.txt", date);
 
        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();
        }
    }
 
    public static void errorDetailInfo(Throwable e, String params, String url) throws Exception {
        e.printStackTrace();
        String date = TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy_MM_dd");
        String os = System.getProperty("os.name");
        String filePath = String.format("/usr/local/tomcat8/logs/error_detail_%s.txt", date);
        if (os.toLowerCase().startsWith("win")) {
            filePath = String.format("C:/logs/error_detail_%s.txt", date);
        } else
            filePath = String.format("/usr/local/tomcat8/logs/error_detail_%s.txt", date);
 
        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");
            ps.print("链接:" + url);
            ps.print("\n");
            ps.print("参数:" + params);
            ps.print("\n");
            e.printStackTrace(ps);
            ps.flush();
            ps.close();
        } finally {
            out.close();
        }
    }
 
    public static void httpInfo(String url, String params, String response) {
        String msg = url + "\n" + params + "\n" + response;
        httpLogger.info(msg);
    }
}