1 /*
   2  * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.javafx.binding;
  27 
  28 import com.sun.javafx.logging.PlatformLogger;
  29 
  30 public class Logging {
  31 
  32     public static ErrorLogger getLogger() {
  33         return ErrorLogger.INSTANCE;
  34     }
  35 
  36     /**
  37      * A PlatformLogger that keeps a record ({@code ErrorLogRecord}) of the last error ({@code Throwable}) logged. 
  38      */
  39     public static class ErrorLogger extends PlatformLogger {
  40 
  41         ErrorLogger() {
  42             super(System.getLogger("javafx.beans"));
  43         }
  44 
  45         private static final ErrorLogger INSTANCE = new ErrorLogger();
  46 
  47         public static class ErrorLogRecord {
  48             private final Level level;
  49             private final Throwable thrown;
  50 
  51             public ErrorLogRecord(Level level, Throwable thrown) {
  52                 this.level = level;
  53                 this.thrown = thrown;
  54             }
  55 
  56             public Throwable getThrown() {
  57                 return thrown;
  58             }
  59 
  60             public Level getLevel() {
  61                 return level;
  62             }
  63         }
  64 
  65         private ErrorLogRecord errorLogRecord;
  66 
  67         public ErrorLogRecord getErrorLogRecord() {
  68             return errorLogRecord;
  69         }
  70 
  71         public void setErrorLogRecord(ErrorLogRecord errorLogRecord) {
  72             this.errorLogRecord = errorLogRecord;
  73         }
  74 
  75 /*        @Override
  76         public void severe(String msg, Throwable t) {
  77             super.severe(msg, t);
  78             errorLogRecord = new ErrorLogRecord(Level.SEVERE, t);
  79         }*/
  80 
  81         @Override
  82         public void warning(String msg, Throwable t) {
  83             super.warning(msg, t);
  84             errorLogRecord = new ErrorLogRecord(Level.WARNING, t);
  85         }
  86 
  87 /*        @Override
  88         public void info(String msg, Throwable t) {
  89             super.info(msg, t);
  90             errorLogRecord = new ErrorLogRecord(Level.INFO, t);
  91         }*/
  92 
  93         @Override
  94         public void fine(String msg, Throwable t) {
  95             super.fine(msg, t);
  96             errorLogRecord = new ErrorLogRecord(Level.FINE, t);
  97         }
  98 
  99 /*        @Override
 100         public void finer(String msg, Throwable t) {
 101             super.finer(msg, t);
 102             errorLogRecord = new ErrorLogRecord(Level.FINER, t);
 103         }*/
 104         
 105 /*        @Override
 106         public void finest(String msg, Throwable t) {
 107             super.finest(msg, t);
 108             errorLogRecord = new ErrorLogRecord(Level.FINEST, t);
 109         }*/
 110     }
 111 }