blob: fec78c4be00e83dd007e7a7492054a66fc6ccb21 (
plain) (
blame)
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
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.log;
import java.io.*;
/**
* @author lulf
* @since 5.1
*/
public class FileLogTarget implements LogTarget {
private final File file;
private FileOutputStream fileOutputStream;
public FileLogTarget(File target) throws FileNotFoundException {
this.file = target;
this.fileOutputStream = null;
}
public synchronized OutputStream open() {
try {
close();
fileOutputStream = new FileOutputStream(file, true);
} catch (FileNotFoundException e) {
throw new RuntimeException("Unable to open output stream", e);
}
return fileOutputStream;
}
public synchronized void close() {
try {
if (fileOutputStream != null) {
fileOutputStream.close();
fileOutputStream = null;
}
} catch (IOException e) {
throw new RuntimeException("Unable to close output stream", e);
}
}
@Override
public String toString() {
return file.getAbsolutePath();
}
}
|