--- /dev/null
+/*--------------------------------------------------------------------------\r
+ * Copyright 2009 Taro L. Saito\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *--------------------------------------------------------------------------*/\r
+//--------------------------------------\r
+// XerialJ\r
+//\r
+// SilkLogWriter.java\r
+// Since: Oct 13, 2009 3:35:01 PM\r
+//\r
+// $URL$\r
+// $Author$\r
+//--------------------------------------\r
+package org.xerial.util.log;\r
+\r
+import java.io.IOException;\r
+import java.io.OutputStreamWriter;\r
+import java.io.Writer;\r
+\r
+import org.xerial.silk.SilkWriter;\r
+import org.xerial.util.StringUtil;\r
+\r
+/**\r
+ * Generating log in Silk format\r
+ * \r
+ * @author leo\r
+ * \r
+ */\r
+public class SilkLogWriter implements LogWriter {\r
+\r
+ private Writer logOut = new OutputStreamWriter(System.err);\r
+\r
+ public SilkLogWriter() {\r
+\r
+ }\r
+\r
+ public SilkLogWriter(Writer out) {\r
+ this.logOut = out;\r
+ }\r
+\r
+ public void log(Logger logger, LogLevel logLevel, Object message) throws IOException {\r
+\r
+ if (logOut == null)\r
+ return; // no output is specified\r
+\r
+ synchronized (this) {\r
+ logOut.write(String.format("-%s(name:%s)", logLevel, logger.getLoggerShortName()));\r
+\r
+ if (message != null) {\r
+ logOut.write(StringUtil.NEW_LINE);\r
+ String m = SilkWriter.escapeText(message.toString());\r
+ logOut.write(m);\r
+ }\r
+\r
+ logOut.write(StringUtil.newline());\r
+ logOut.flush();\r
+ }\r
+\r
+ }\r
+\r
+}\r