+++ /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
-// ConsoleLogWriter.java\r
-// Since: Oct 13, 2009 3:25:28 PM\r
-//\r
-// $URL$\r
-// $Author$\r
-//--------------------------------------\r
-package org.xerial.util.log;\r
-\r
-import java.io.IOException;\r
-import java.io.OutputStream;\r
-import java.io.OutputStreamWriter;\r
-import java.io.Writer;\r
-\r
-import org.xerial.util.StringUtil;\r
-\r
-/**\r
- * Generating log for console output\r
- * \r
- * @author leo\r
- * \r
- */\r
-public class SimpleLogWriter implements LogWriter {\r
-\r
- private Writer logOut;\r
-\r
- public SimpleLogWriter() {\r
- logOut = new OutputStreamWriter(System.err);\r
- }\r
-\r
- public SimpleLogWriter(OutputStream out) {\r
- logOut = new OutputStreamWriter(out);\r
- }\r
-\r
- public SimpleLogWriter(Writer out) {\r
- logOut = out;\r
- }\r
-\r
- private static String[] logPrefix = { "", // ALL\r
- "\033[0;32m", // TRACE\r
- "", // DEBUG\r
- "\033[1;36m", // INFO\r
- "\033[1;33m", // WARN\r
- "\033[1;35m", // ERROR\r
- "\033[1;31m", // FATAL\r
- "", // OFF\r
- "", };\r
-\r
- public void log(Logger logger, LogLevel logLevel, Object message) {\r
-\r
- if (logOut == null)\r
- return; // no output is specified\r
-\r
- try {\r
- synchronized (this) {\r
- if (logger.isColorEnabled())\r
- logOut.write(logPrefix[logLevel.ordinal()]);\r
-\r
- logOut.write(String.format("[%s] %s", logger.getLoggerShortName(),\r
- message != null ? message.toString() : ""));\r
- if (logger.isColorEnabled())\r
- logOut.write("\033[0m");\r
-\r
- logOut.write(StringUtil.newline());\r
-\r
- logOut.flush();\r
- }\r
- }\r
- catch (IOException e) {\r
- e.printStackTrace();\r
- }\r
-\r
- }\r
-\r
-}\r