📄 log.java
字号:
/* * USE - UML based specification environment * Copyright (C) 1999-2004 Mark Richters, University of Bremen * * 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 2 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, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *//* $ProjectHeader: use 2-3-0-release.1 Mon, 12 Sep 2005 20:18:33 +0200 green $ */package org.tzi.use.util;import java.io.*;import java.util.Date;import java.text.DateFormat;/** * Class Log provides a set of static methods for writing log messages * on output streams. * * @version $ProjectVersion: 2-3-0-release.1 $ * @author Mark Richters */public final class Log { private static PrintStream fOut = System.out; private static PrintStream fErr = System.err; private static DateFormat fDateFormat = null; private static boolean fVerbose = false; private static boolean fPrintTime = false; private static boolean fTrace = false; private static boolean fPrintStackTraces = true; private static boolean fDidOutput = false; // utility class private Log() {} /** * Sets verbose flag. Determines whether verbose messages are * printed. */ public static void setVerbose(boolean onOff) { fVerbose = onOff; } public static boolean isVerbose() { return fVerbose; } /** * Sets print time flag. Determines whether messages are prefixed * with the current time. */ public static void setPrintTime(boolean onOff) { fPrintTime = onOff; } public static boolean isPrintingTime() { return fPrintTime; } /** * Sets trace flag. Determines whether trace messages are * printed. */ public static void setTrace(boolean onOff) { fTrace = onOff; } public static boolean isTracing() { return fTrace; } /** * Turns printing of stack traces on/off. */ public static void setPrintStackTrace(boolean onOff) { fPrintStackTraces = onOff; } public static boolean isPrintingStackTraces() { return fPrintStackTraces; } /** * Resets flag indicating that output occurred. Flag is set by * output methods. After some complex operations clients can ask * if some output occurred without bothering about verbosity * settings. */ public static void resetOutputFlag() { fDidOutput = false; } public static boolean didOutput() { return fDidOutput; } public static PrintStream out() { return fOut; } /** * Output routines. */ public static void println(String s) { if (fPrintTime ) { if (fDateFormat == null ) fDateFormat = DateFormat.getTimeInstance(DateFormat.MEDIUM); fOut.print(fDateFormat.format(new Date()) + ": "); } fOut.println(s); fDidOutput = true; } public static void print(String s) { fOut.print(s); fDidOutput = true; } public static void println() { fOut.println(); fDidOutput = true; } /** * Print messages only if verbose flag is on. */ public static void verbose(String s) { if (fVerbose ) println(s); } /** * Print messages only if trace flag is on. */ public static void trace(String msg) { if (fTrace ) println("* " + msg); } public static void trace(Object location, String msg) { trace(location, msg, false); } public static void trace(Object location, String msg, boolean flush) { if (fTrace ) { String className = location.getClass().getName(); if (className.startsWith("org.tzi.use") ) className = className.substring("org.tzi.use".length()); println("* " + className + ": " + msg); if (flush ) fOut.flush(); } } /** * Print error messages. */ public static void error(String s) { fErr.println("Error: " + s); fDidOutput = true; } public static void error(Object location, String msg) { String className = location.getClass().getName(); fErr.println("error in " + className + ": " + msg); } public static void error(Exception e) { String className = e.getClass().getName(); fErr.println("exception " + className + ": " + e.getMessage()); if (fPrintStackTraces ) e.printStackTrace(); fDidOutput = true; } public static void error(String s, Exception e) { String className = e.getClass().getName(); fErr.println("exception " + className + ": " + s + " reason: " + e.getMessage()); if (fPrintStackTraces ) e.printStackTrace(); fDidOutput = true; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -