package u8c.log; import nc.bs.framework.common.RuntimeEnv; import org.apache.log4j.Logger; import java.io.IOException; import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStreamWriter; import java.text.SimpleDateFormat; import java.util.Date; /** * nclog * @author YY * @datetime 2021-9-29 */ public class NcLog { private static final Logger logger = Logger.getLogger(NcLog.class); private static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private static SimpleDateFormat format$ = new SimpleDateFormat("yyyy-MM-dd"); public static void info(String str) { String logFilePath = getLogFile(); File file = new File(logFilePath); BufferedWriter fos = null; try { fos = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, true))); str = format.format(new Date()) + " " + str + "\r\n"; fos.write(str + "\r\n"); fos.flush(); } catch (Exception localException) { if (fos != null) try { fos.close(); } catch (IOException localIOException) { } } finally { if (fos != null) try { fos.close(); } catch (IOException localIOException2) { } } } private static String getLogFile() { String destFileFolder = RuntimeEnv.getInstance().getNCHome() + File.separator + "mancLog" + File.separator + format$.format(new Date()); String destFilePath = destFileFolder + File.separator + "org.log"; File destFolder = new File(destFileFolder); if (!destFolder.exists()) { destFolder.mkdirs(); } File destFile = new File(destFilePath); if (!destFile.exists()) { try { destFile.createNewFile(); } catch (Exception e) { logger.info(e); } } return destFilePath; } }