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