Skip to content

Commit

Permalink
Merge pull request alibaba#20 from tianxiao-ma/master
Browse files Browse the repository at this point in the history
create all dir in the log path if they are not exist
  • Loading branch information
丁宇 committed Aug 5, 2013
2 parents 2f1c1a0 + adf41b4 commit 6fda97a
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/main/java/com/taobao/profile/utils/DailyRollingFileWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public DailyRollingFileWriter(String filePath) {
rolling(now);
}
} else {
createWriter(filePath);
createWriter(file);
}
}

Expand Down Expand Up @@ -164,7 +164,7 @@ private void rolling(Date now) {

File file = new File(fileName);
file.renameTo(target);
createWriter(fileName);
createWriter(new File(fileName));
rollingFileName = datedFilename;
}

Expand All @@ -183,11 +183,16 @@ private void createWriter(String filename, boolean append) {

/**
* 直接覆盖旧文件
* @param filename
* @param file
*/
private void createWriter(String filename) {
private void createWriter(File file) {
try {
bufferedWriter = new BufferedWriter(new FileWriter(filename), 8 * 1024);
file = file.getCanonicalFile();
File parent = file.getParentFile();
if (parent != null && !parent.exists()) {
parent.mkdirs();
}
bufferedWriter = new BufferedWriter(new FileWriter(file), 8 * 1024);
} catch (IOException e) {
e.printStackTrace();
}
Expand Down

0 comments on commit 6fda97a

Please sign in to comment.