Path: blob/main/src/lwjgl/java/paulscode/sound/SoundSystemLogger.java
8644 views
package paulscode.sound;12/**3* The SoundSystemLogger class handles all status messages, warnings, and error4* messages for the SoundSystem library. This class can be extended and5* methods overriden to change how messages are handled. To do this, the6* overridden class should be instantiated, and a call should be made to method7* SoundSystemConfig.setLogger() BEFORE creating the SoundSystem object. If8* the setLogger() method is called after the SoundSystem has been created,9* there will be handles floating around to two different message loggers, and10* the results will be undesirable.11* See {@link paulscode.sound.SoundSystemConfig SoundSystemConfig} for more12* information about changing default settings. If an alternate logger is not13* set by the user, then an instance of this base class will be automatically14* created by default when the SoundSystem class is instantiated.15*<br><br>16*<b><i> SoundSystem License:</b></i><br><b><br>17* You are free to use this library for any purpose, commercial or otherwise.18* You may modify this library or source code, and distribute it any way you19* like, provided the following conditions are met:20*<br>21* 1) You may not falsely claim to be the author of this library or any22* unmodified portion of it.23*<br>24* 2) You may not copyright this library or a modified version of it and then25* sue me for copyright infringement.26*<br>27* 3) If you modify the source code, you must clearly document the changes28* made before redistributing the modified source code, so other users know29* it is not the original code.30*<br>31* 4) You are not required to give me credit for this library in any derived32* work, but if you do, you must also mention my website:33* http://www.paulscode.com34*<br>35* 5) I the author will not be responsible for any damages (physical,36* financial, or otherwise) caused by the use if this library or any part37* of it.38*<br>39* 6) I the author do not guarantee, warrant, or make any representations,40* either expressed or implied, regarding the use of this library or any41* part of it.42* <br><br>43* Author: Paul Lamb44* <br>45* http://www.paulscode.com46* </b>47*/48public class SoundSystemLogger49{50/**51* Prints a message.52* @param message Message to print.53* @param indent Number of tabs to indent the message.54*/55public void message( String message, int indent )56{57String messageText;58// Determine how many spaces to indent:59String spacer = "";60for( int x = 0; x < indent; x++ )61{62spacer += " ";63}64// indent the message:65messageText = spacer + message;6667// Print the message:68System.out.println( messageText );69}7071/**72* Prints an important message.73* @param message Message to print.74* @param indent Number of tabs to indent the message.75*/76public void importantMessage( String message, int indent )77{78String messageText;79// Determine how many spaces to indent:80String spacer = "";81for( int x = 0; x < indent; x++ )82{83spacer += " ";84}85// indent the message:86messageText = spacer + message;8788// Print the message:89System.out.println( messageText );90}9192/**93* Prints the specified message if error is true.94* @param error True or False.95* @param classname Name of the class checking for an error.96* @param message Message to print if error is true.97* @param indent Number of tabs to indent the message.98* @return True if error is true.99*/100public boolean errorCheck( boolean error, String classname, String message,101int indent )102{103if( error )104errorMessage( classname, message, indent );105return error;106}107108/**109* Prints the classname which generated the error, followed by the error110* message.111* @param classname Name of the class which generated the error.112* @param message The actual error message.113* @param indent Number of tabs to indent the message.114*/115public void errorMessage( String classname, String message, int indent )116{117String headerLine, messageText;118// Determine how many spaces to indent:119String spacer = "";120for( int x = 0; x < indent; x++ )121{122spacer += " ";123}124// indent the header:125headerLine = spacer + "Error in class '" + classname + "'";126// indent the message one more than the header:127messageText = " " + spacer + message;128129// Print the error message:130System.out.println( headerLine );131System.out.println( messageText );132}133134/**135* Prints an exception's error message followed by the stack trace.136* @param e Exception containing the information to print.137* @param indent Number of tabs to indent the message and stack trace.138*/139public void printStackTrace( Exception e, int indent )140{141printExceptionMessage( e, indent );142importantMessage( "STACK TRACE:", indent );143if( e == null )144return;145146StackTraceElement[] stack = e.getStackTrace();147if( stack == null )148return;149150StackTraceElement line;151for( int x = 0; x < stack.length; x++ )152{153line = stack[x];154if( line != null )155message( line.toString(), indent + 1 );156}157}158159/**160* Prints an exception's error message.161* @param e Exception containing the message to print.162* @param indent Number of tabs to indent the message.163*/164public void printExceptionMessage( Exception e, int indent )165{166importantMessage( "ERROR MESSAGE:", indent );167if( e.getMessage() == null )168message( "(none)", indent + 1 );169else170message( e.getMessage(), indent + 1 );171}172}173174175