当前位置:   article > 正文

java 异步写文件_java异步写日志到文件中实现代码

java 异步写入文件

java异步写日志到文件中详解

实现代码:

package com.tydic.ESUtil;

import java.io.File;

import java.io.FileWriter;

import java.io.IOException;

import java.io.InputStream;

import java.io.PrintWriter;

import java.util.Properties;

public class LogWriter {

// 日志的配置文件

public static final String LOG_CONFIGFILE_NAME = "log.properties";

// 日志文件名在配置文件中的标签

public static final String LOGFILE_TAG_NAME = "logfile";

// 默认的日志文件的路径和文件名称

private final String DEFAULT_LOG_FILE_NAME = "./logtext.log";

// 该类的唯一的实例

private static LogWriter logWriter;

// 文件输出流

private PrintWriter writer;

// 日志文件名

private String logFileName;

/**

* 默认构造函数

*/

private LogWriter() throws LogException{

this.init();

}

private LogWriter(String fileName) throws LogException{

this.logFileName = fileName;

this.init();

}

/**

* 获取LogWriter的唯一实例。

* @return

* @throws LogException

*/

public synchronized static LogWriter getLogWriter()throws LogException{

if (logWriter == null){

logWriter = new LogWriter();

}

return logWriter;

}

public synchronized static LogWriter getLogWriter(String logFileName)throws LogException{

if (logWriter == null){

logWriter = new LogWriter(logFileName);

}

return lo

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/空白诗007/article/detail/954227
推荐阅读
相关标签
  

闽ICP备14008679号