0N/A/*
2362N/A * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.awt.X11;
0N/A
0N/Aimport java.util.logging.*;
0N/Aimport java.text.*;
0N/Aimport java.util.*;
0N/Aimport java.io.*;
0N/A
0N/A/**
0N/A * Formatter class providing ANSI output. Based on java.util.logging.SimpleFormatter sources.
0N/A */
0N/A
0N/Apublic class XAWTFormatter extends java.util.logging.Formatter {
0N/A Date dat = new Date();
0N/A private final static String format = "{0,date} {0,time}";
0N/A private MessageFormat formatter;
0N/A
0N/A private Object args[] = new Object[1];
0N/A
0N/A // Line separator string. This is the value of the line.separator
0N/A // property at the moment that the SimpleFormatter was created.
0N/A private String lineSeparator = (String) java.security.AccessController.doPrivileged(
0N/A new sun.security.action.GetPropertyAction("line.separator"));
0N/A
0N/A boolean displayFullRecord = false;
0N/A boolean useANSI = false;
0N/A boolean showDate = true;
0N/A boolean showLevel = true;
0N/A boolean swapMethodClass = false;
0N/A public XAWTFormatter() {
0N/A displayFullRecord = "true".equals(LogManager.getLogManager().getProperty("XAWTFormatter.displayFullRecord"));
0N/A useANSI = "true".equals(LogManager.getLogManager().getProperty("XAWTFormatter.useANSI"));
0N/A showDate = !"false".equals(LogManager.getLogManager().getProperty("XAWTFormatter.showDate"));
0N/A showLevel = !"false".equals(LogManager.getLogManager().getProperty("XAWTFormatter.showLevel"));
0N/A swapMethodClass = "true".equals(LogManager.getLogManager().getProperty("XAWTFormatter.swapMethodClass"));
0N/A }
0N/A
0N/A /**
0N/A * Format the given LogRecord.
0N/A * @param record the log record to be formatted.
0N/A * @return a formatted log record
0N/A */
0N/A public synchronized String format(LogRecord record) {
0N/A StringBuffer sb = new StringBuffer();
0N/A if (useANSI) {
0N/A Level lev = record.getLevel();
0N/A if (Level.FINEST.equals(lev)) {
0N/A sb.append("[36m");
0N/A } else if (Level.FINER.equals(lev)) {
0N/A sb.append("[32m");
0N/A } else if (Level.FINE.equals(lev)) {
0N/A sb.append("[34m");
0N/A }
0N/A }
0N/A if (displayFullRecord) {
0N/A if (showDate) {
0N/A // Minimize memory allocations here.
0N/A dat.setTime(record.getMillis());
0N/A args[0] = dat;
0N/A StringBuffer text = new StringBuffer();
0N/A if (formatter == null) {
0N/A formatter = new MessageFormat(format);
0N/A }
0N/A formatter.format(args, text, null);
0N/A sb.append(text);
0N/A sb.append(" ");
0N/A } else {
0N/A sb.append(" ");
0N/A }
0N/A if (swapMethodClass) {
0N/A if (record.getSourceMethodName() != null) {
0N/A sb.append(" [35m");
0N/A sb.append(record.getSourceMethodName());
0N/A sb.append("[30m ");
0N/A }
0N/A if (record.getSourceClassName() != null) {
0N/A sb.append(record.getSourceClassName());
0N/A } else {
0N/A sb.append(record.getLoggerName());
0N/A }
0N/A } else {
0N/A if (record.getSourceClassName() != null) {
0N/A sb.append(record.getSourceClassName());
0N/A } else {
0N/A sb.append(record.getLoggerName());
0N/A }
0N/A if (record.getSourceMethodName() != null) {
0N/A sb.append(" [35m");
0N/A sb.append(record.getSourceMethodName());
0N/A sb.append("[30m");
0N/A }
0N/A }
0N/A sb.append(lineSeparator);
0N/A }
0N/A if (useANSI) {
0N/A Level lev = record.getLevel();
0N/A if (Level.FINEST.equals(lev)) {
0N/A sb.append("[36m");
0N/A } else if (Level.FINER.equals(lev)) {
0N/A sb.append("[32m");
0N/A } else if (Level.FINE.equals(lev)) {
0N/A sb.append("[34m");
0N/A }
0N/A }
0N/A if (showLevel) {
0N/A sb.append(record.getLevel().getLocalizedName());
0N/A sb.append(": ");
0N/A }
0N/A String message = formatMessage(record);
0N/A sb.append(message);
0N/A sb.append(lineSeparator);
0N/A if (record.getThrown() != null) {
0N/A try {
0N/A StringWriter sw = new StringWriter();
0N/A PrintWriter pw = new PrintWriter(sw);
0N/A record.getThrown().printStackTrace(pw);
0N/A pw.close();
0N/A sb.append(sw.toString());
0N/A } catch (Exception ex) {
0N/A }
0N/A }
0N/A if (useANSI) {
0N/A sb.append("[30m");
0N/A }
0N/A return sb.toString();
0N/A }
0N/A}