2014-02-15 09:21:40 +01:00
/ * *
* Copyright ( c ) 2011 - 2014 , SpaceToad and the BuildCraft Team
2013-10-26 03:11:10 +02:00
* http : //www.mod-buildcraft.com
2014-02-15 09:21:40 +01:00
*
2014-12-09 21:09:14 +01:00
* The BuildCraft API is distributed under the terms of the MIT License .
* Please check the contents of the license , which should be located
* as " LICENSE.API " in the BuildCraft source code distribution .
2013-10-26 03:11:10 +02:00
* /
2014-04-27 11:03:18 +02:00
package buildcraft.api.core ;
2013-10-26 03:11:10 +02:00
2014-04-30 14:46:04 +02:00
import java.lang.reflect.Method ;
2014-08-02 17:32:04 +02:00
import org.apache.logging.log4j.Level ;
import org.apache.logging.log4j.LogManager ;
import org.apache.logging.log4j.Logger ;
2013-10-26 03:11:10 +02:00
2014-05-03 18:59:52 +02:00
public final class BCLog {
2013-10-26 03:11:10 +02:00
2014-08-02 17:32:04 +02:00
public static final Logger logger = LogManager . getLogger ( " BuildCraft " ) ;
2013-10-26 03:11:10 +02:00
2014-05-03 18:59:52 +02:00
/ * *
* Deactivate constructor
* /
private BCLog ( ) {
}
2013-10-26 03:11:10 +02:00
public static void initLog ( ) {
2014-05-03 18:59:52 +02:00
2014-04-30 14:46:04 +02:00
logger . info ( " Starting BuildCraft " + getVersion ( ) ) ;
2014-08-02 17:32:04 +02:00
logger . info ( " Copyright (c) SpaceToad, 2011-2014 " ) ;
2013-10-26 03:11:10 +02:00
logger . info ( " http://www.mod-buildcraft.com " ) ;
}
2014-06-15 19:27:17 +02:00
public static void logErrorAPI ( String mod , Throwable error , Class < ? > classFile ) {
2013-10-26 03:11:10 +02:00
StringBuilder msg = new StringBuilder ( mod ) ;
msg . append ( " API error, please update your mods. Error: " ) . append ( error ) ;
StackTraceElement [ ] stackTrace = error . getStackTrace ( ) ;
2014-05-03 18:59:52 +02:00
if ( stackTrace . length > 0 ) {
2013-10-26 03:11:10 +02:00
msg . append ( " , " ) . append ( stackTrace [ 0 ] ) ;
2014-05-03 18:59:52 +02:00
}
2014-08-02 17:32:04 +02:00
logger . log ( Level . ERROR , msg . toString ( ) ) ;
2013-10-26 03:11:10 +02:00
if ( classFile ! = null ) {
msg = new StringBuilder ( mod ) ;
msg . append ( " API error: " ) . append ( classFile . getSimpleName ( ) ) . append ( " is loaded from " ) . append ( classFile . getProtectionDomain ( ) . getCodeSource ( ) . getLocation ( ) ) ;
2014-08-02 17:32:04 +02:00
logger . log ( Level . ERROR , msg . toString ( ) ) ;
2013-10-26 03:11:10 +02:00
}
}
2014-04-30 14:46:04 +02:00
public static String getVersion ( ) {
try {
Class < ? > clazz = Class . forName ( " buildcraft.core.Version " ) ;
Method method = clazz . getDeclaredMethod ( " getVersion " ) ;
return String . valueOf ( method . invoke ( null ) ) ;
} catch ( Exception e ) {
return " UNKNOWN VERSION " ;
}
}
2013-10-26 03:11:10 +02:00
}