1 /* 2 * This file is part of Waarp Project (named also Waarp or GG). 3 * 4 * Copyright (c) 2019, Waarp SAS, and individual contributors by the @author 5 * tags. See the COPYRIGHT.txt in the distribution for a full listing of 6 * individual contributors. 7 * 8 * All Waarp Project is free software: you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or (at your 11 * option) any later version. 12 * 13 * Waarp is distributed in the hope that it will be useful, but WITHOUT ANY 14 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 15 * A PARTICULAR PURPOSE. See the GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License along with 18 * Waarp . If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 package org.waarp.common.logging; 22 23 /** 24 * Utility class to be used only in classes where WaarpLogger is not allowed 25 */ 26 public final class SysErrLogger { 27 /** 28 * FAKE LOGGER used where no LOG could be done 29 */ 30 public static final SysErrLogger FAKE_LOGGER = new SysErrLogger(); 31 32 private SysErrLogger() { 33 // Empty 34 } 35 36 /** 37 * Utility method to log nothing 38 * <p> 39 * Used only in classes where WaarpLogger is not allowed 40 * 41 * @param throwable to log ignore 42 */ 43 public final void ignoreLog(final Throwable throwable) {// NOSONAR 44 // Nothing to do 45 } 46 47 /** 48 * Utility method to log through System.out 49 * <p> 50 * Used only in classes where WaarpLogger is not allowed 51 */ 52 public final void sysout() { 53 System.out.println(); // NOSONAR 54 } 55 56 /** 57 * Utility method to log through System.out 58 * <p> 59 * Used only in classes where WaarpLogger is not allowed 60 * 61 * @param message to write for no error log 62 */ 63 public final void sysout(final Object message) { 64 System.out.println(message); // NOSONAR 65 } 66 67 /** 68 * Utility method to log through System.out 69 * 70 * @param format 71 * @param args 72 */ 73 public final void sysoutFormat(final String format, final Object... args) { 74 System.out.format(format, args); // NOSONAR 75 } 76 77 /** 78 * Utility method to log through System.err 79 * <p> 80 * Used only in classes where WaarpLogger is not allowed 81 * 82 * @param message to write for error 83 */ 84 public final void syserrNoLn(final Object message) { 85 System.err.print("ERROR " + message); // NOSONAR 86 } 87 88 /** 89 * Utility method to log through System.err 90 * <p> 91 * Used only in classes where WaarpLogger is not allowed 92 * 93 * @param message to write for error 94 */ 95 public final void syserr(final Object message) { 96 System.err.println("ERROR " + message); // NOSONAR 97 } 98 99 /** 100 * Utility method to log through System.err the current Stacktrace 101 * <p> 102 * Used only in classes where WaarpLogger is not allowed 103 */ 104 public final void syserr() { 105 new RuntimeException("ERROR Stacktrace").printStackTrace(); // NOSONAR 106 } 107 108 /** 109 * Utility method to log through System.err the current Stacktrace 110 * <p> 111 * Used only in classes where WaarpLogger is not allowed 112 * 113 * @param message to write for error 114 * @param e throw to write as error 115 */ 116 public final void syserr(final String message, final Throwable e) { 117 System.err.print("ERROR " + message + ": "); // NOSONAR 118 e.printStackTrace(); // NOSONAR 119 } 120 121 /** 122 * Utility method to log through System.err the current Stacktrace 123 * <p> 124 * Used only in classes where WaarpLogger is not allowed 125 * 126 * @param e throw to write as error 127 */ 128 public final void syserr(final Throwable e) { 129 System.err.print("ERROR: "); // NOSONAR 130 e.printStackTrace(); // NOSONAR 131 } 132 }