admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
fanli/src/main/java/com/yeshi/fanli/log/PushLogHelper.java
@@ -1,98 +1,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 com.yeshi.fanli.util.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 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();
      }
   }
}
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();
      }
   }
}