class WriterMessageRecorder implements MessageRecorder {

    @Override
    public synchronized void recordMessage(NodeID sender, Message message) {
        if (this.filter != null && !this.filter.acceptMessage(message)) {
            return;
        }

        try {
            writer.write(formatter.format(new Date()));

            writer.write(",");
            writer.write(String.valueOf(message.getCode()));
            writer.write(",");
            writer.write(String.valueOf(message.getCommand()));
            writer.write(",");

            if (message instanceof UscMessage) {
                writer.write(String.valueOf(((UscMessage) message).getMessage().getMessageType()));
            }

            writer.write(",");

            writer.write(Hex.toHexString(message.getEncoded()));

            writer.write(",");

            if (sender != null) {
                writer.write(Hex.toHexString(sender.getID()));
            }

            writer.newLine();
            writer.flush();
        }
        catch (IOException ex) {
            logger.error("Exception recording message: ", ex);
        }
    }

    public  WriterMessageRecorder(BufferedWriter writer, MessageFilter filter);

}