aboutsummaryrefslogtreecommitdiff
path: root/src/simpleapdu/DirtyLogger.java
blob: c06571b3535c360c343940bd8b415e298740bfc3 (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
45
46
47
48
package simpleapdu;

import java.io.FileOutputStream;
import java.io.IOException;

/**
 *
 * @author xsvenda
 */
public class DirtyLogger {
    FileOutputStream    m_logFile;
    boolean             m_bOutputSystemOut = true;

    public DirtyLogger(FileOutputStream logFile, boolean bOutputSystemOut) {
        m_logFile = logFile;
        m_bOutputSystemOut = bOutputSystemOut;
    }
    public void println() {
        String logLine = "\n";
        print(logLine);
    }
    public void println(String logLine)  {
        logLine += "\n";
        print(logLine);
    }
    public void print(String logLine) {
        if (m_bOutputSystemOut) {
            System.out.print(logLine);
        }
        if (m_logFile != null) {
            try {
                m_logFile.write(logLine.getBytes());
            } catch (IOException ex) {
            }
        }
    }    

    void flush() {
        try {
            m_logFile.flush();
        } catch (IOException ex) {
        }
    }

    void close() throws IOException {
        m_logFile.close();
    }
}