Java Log Exception logError(String s, Throwable e)

Here you can find the source of logError(String s, Throwable e)

Description

log Error

License

Open Source License

Declaration

static String logError(String s, Throwable e) 

Method Source Code


//package com.java2s;
/*//ww  w. ja v  a  2s . com
Copyright (c) 2016 Steven Phillips, Miro Dudik and Rob Schapire
    
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions: 
    
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software. 
    
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
*/

import java.io.*;

public class Main {
    public static boolean verbose = false, visible = true;
    static PrintStream logOut = null;
    static long startTime, lastReportedTime;

    static String logError(String s, Throwable e) {
        String msg = s + (e == null ? "" : ": " + e.toString());
        echoln(msg);
        if (e != null) {
            if (verbose)
                e.printStackTrace(System.out);
            if (logOut != null) {
                e.printStackTrace(logOut);
                logOut.flush();
            }
        } else if (logOut != null)
            new Exception().printStackTrace(logOut);
        return msg;
    }

    static void echoln() {
        echoln("");
    }

    static void echoln(String s) {
        if (logOut != null) {
            long time = System.currentTimeMillis();
            if (time > lastReportedTime + 1000) {
                logOut.println("Time since start: " + (time - startTime) / 1000.0);
                lastReportedTime = time;
            }
            logOut.println(s);
            logOut.flush();
        }
    }
}

Related

  1. logError(Exception e)
  2. logException(Exception e, Logger logger)
  3. LogException(Exception ex)
  4. logException(final Throwable exception)
  5. logException(int type, String RID, String subRID, String propIndication, String error)