mobile/android/base/background/common/log/writers/PrintLogWriter.java

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 package org.mozilla.gecko.background.common.log.writers;
michael@0 6
michael@0 7 import java.io.PrintWriter;
michael@0 8
michael@0 9 /**
michael@0 10 * Log to a <code>PrintWriter</code>.
michael@0 11 */
michael@0 12 public class PrintLogWriter extends LogWriter {
michael@0 13 protected final PrintWriter pw;
michael@0 14 protected boolean closed = false;
michael@0 15
michael@0 16 public static final String ERROR = " :: E :: ";
michael@0 17 public static final String WARN = " :: W :: ";
michael@0 18 public static final String INFO = " :: I :: ";
michael@0 19 public static final String DEBUG = " :: D :: ";
michael@0 20 public static final String VERBOSE = " :: V :: ";
michael@0 21
michael@0 22 public PrintLogWriter(PrintWriter pw) {
michael@0 23 this.pw = pw;
michael@0 24 }
michael@0 25
michael@0 26 protected void log(String tag, String message, Throwable error) {
michael@0 27 if (closed) {
michael@0 28 return;
michael@0 29 }
michael@0 30
michael@0 31 pw.println(tag + message);
michael@0 32 if (error != null) {
michael@0 33 error.printStackTrace(pw);
michael@0 34 }
michael@0 35 }
michael@0 36
michael@0 37 @Override
michael@0 38 public void error(String tag, String message, Throwable error) {
michael@0 39 log(tag, ERROR + message, error);
michael@0 40 }
michael@0 41
michael@0 42 @Override
michael@0 43 public void warn(String tag, String message, Throwable error) {
michael@0 44 log(tag, WARN + message, error);
michael@0 45 }
michael@0 46
michael@0 47 @Override
michael@0 48 public void info(String tag, String message, Throwable error) {
michael@0 49 log(tag, INFO + message, error);
michael@0 50 }
michael@0 51
michael@0 52 @Override
michael@0 53 public void debug(String tag, String message, Throwable error) {
michael@0 54 log(tag, DEBUG + message, error);
michael@0 55 }
michael@0 56
michael@0 57 @Override
michael@0 58 public void trace(String tag, String message, Throwable error) {
michael@0 59 log(tag, VERBOSE + message, error);
michael@0 60 }
michael@0 61
michael@0 62 @Override
michael@0 63 public boolean shouldLogVerbose(String tag) {
michael@0 64 return true;
michael@0 65 }
michael@0 66
michael@0 67 public void close() {
michael@0 68 if (closed) {
michael@0 69 return;
michael@0 70 }
michael@0 71 if (pw != null) {
michael@0 72 pw.close();
michael@0 73 }
michael@0 74 closed = true;
michael@0 75 }
michael@0 76 }

mercurial