![JAR search and dependency download from the Maven repository](/logo.png)
com.github.sdnwiselab.sdnwise.mote.logger.MoteFormatter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sdn-wise-data Show documentation
Show all versions of sdn-wise-data Show documentation
Emulated SDN-WISE Java Nodes
The newest version!
/*
* Copyright (C) 2015 SDN-WISE
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package com.github.sdnwiselab.sdnwise.mote.logger;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;
/**
* Representation of the formatter used by the loggers of the nodes.
*
* @author Sebastiano Milardo
*/
public class MoteFormatter extends Formatter {
/**
* Format the given LogRecord.
*
* @param record the log record to be formatted.
* @return a formatted log record
*/
@Override
public final synchronized String format(final LogRecord record) {
StringBuilder sb = new StringBuilder();
String message = formatMessage(record);
sb.append(message);
if (record.getThrown() != null) {
try {
StringWriter sw = new StringWriter();
try (PrintWriter pw = new PrintWriter(sw)) {
record.getThrown().printStackTrace(pw);
}
sb.append(sw.toString());
} catch (Exception ex) {
System.err.println(ex.getLocalizedMessage());
}
}
return sb.append("\n").toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy