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.

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

mercurial