File Writing optimizations - FileOutputStream vs Writers I'm using a simple logger on a server, which uses a method that looks like this:

@Override
public synchronized void write(String logtag, String reason, int severity) {

    long logtime = System.currentTimeMillis();
    String message = "";

    switch (severity) {
        case DEBUG:
            if (!debug) return;
            message = "[" + logtime + "] {DEBUG} " + logtag + "% " + reason + "\n$";
            break;
        case INFO:
            message = "[" + logtime + "] {INFO} " + logtag + "% " + reason + "\n$";
            break;
        case ERROR:
            message = "[" + logtime + "] {ERROR} " + logtag + "% " + reason + "\n$";
            break;
        case FATAL:
            message = "[" + logtime + "] {FATAL} " + logtag + "% " + reason + "\n$";
           break;
        case EXCEPTION:
            message = "[" + logtime + "] {EXCEPTION} " + logtag + "% " + reason + "\n$";
            break;
        default:
            message = "Anthrazit error! Invalid severity: " + severity;
    } 

    try {
        out.write(message.getBytes(StandardCharsets.UTF_8));
    } catch (IOException e) {
        errorOnInit(e);
    }

    if (exitOnFatal &amp;&amp; severity == FATAL) {
        System.err.println("Anthrazit exit on fatal: " + message + ". Please check the logs.");
        close();
        System.exit(1);
    }

}


After doing some research I found some classes designed to to this, like PrintWriter and others. Is there any performance difference between my approach and the PrintWriters?
According to its javadoc:


  FileOutputStream is meant for writing streams of raw bytes such as image data. For writing streams of characters, consider using FileWriter.


See also: https://stackoverflow.com/questions/11371154/outputstreamwriter-vs-filewriter

You could also use a StringBuilder instead of doing manually a string concatenation.

Also, the whole method is sychronized. The message probably does not need to be constructed in the sychronized block. Only concrete write to the Stream/File should be sychronized:

long logtime = System.currentTimeMillis();
// construct string etc

sychronized(this){
    out.write(message.getBytes(StandardCharsets.UTF_8));
}


You could also try to read the code of "real" logging frameworks to get ideas how they work.