mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-04-01 00:06:58 +00:00
Remove ILogger facade
Just use global Log4j logger on the ComputerCraft class.
This commit is contained in:
parent
44ba4069c1
commit
a0b6cbb671
@ -20,8 +20,6 @@ import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||
import dan200.computercraft.core.filesystem.ComboMount;
|
||||
import dan200.computercraft.core.filesystem.FileMount;
|
||||
import dan200.computercraft.core.filesystem.JarMount;
|
||||
import dan200.computercraft.core.logger.Log4JLogger;
|
||||
import dan200.computercraft.core.logger.Logger;
|
||||
import dan200.computercraft.shared.common.DefaultBundledRedstoneProvider;
|
||||
import dan200.computercraft.shared.computer.blocks.BlockCommandComputer;
|
||||
import dan200.computercraft.shared.computer.blocks.BlockComputer;
|
||||
@ -70,6 +68,7 @@ import net.minecraftforge.fml.common.network.FMLEventChannel;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.common.network.internal.FMLProxyPacket;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -209,6 +208,9 @@ public class ComputerCraft
|
||||
// Creative
|
||||
public static CreativeTabMain mainCreativeTab;
|
||||
|
||||
// Logging
|
||||
public static Logger log;
|
||||
|
||||
// API users
|
||||
private static List<IPeripheralProvider> peripheralProviders = new ArrayList<IPeripheralProvider>();
|
||||
private static List<IBundledRedstoneProvider> bundledRedstoneProviders = new ArrayList<IBundledRedstoneProvider>();
|
||||
@ -233,7 +235,7 @@ public class ComputerCraft
|
||||
@Mod.EventHandler
|
||||
public void preInit( FMLPreInitializationEvent event )
|
||||
{
|
||||
Logger.setInstance( new Log4JLogger( event.getModLog() ) );
|
||||
log = event.getModLog();
|
||||
|
||||
// Load config
|
||||
Config.config = new Configuration( event.getSuggestedConfigurationFile() );
|
||||
@ -609,7 +611,7 @@ public class ComputerCraft
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
Logger.error( "Peripheral provider " + peripheralProvider + " errored.", e );
|
||||
ComputerCraft.log.error( "Peripheral provider " + peripheralProvider + " errored.", e );
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -653,7 +655,7 @@ public class ComputerCraft
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
Logger.error( "Bundled redstone provider " + bundledRedstoneProvider + " errored.", e );
|
||||
ComputerCraft.log.error( "Bundled redstone provider " + bundledRedstoneProvider + " errored.", e );
|
||||
}
|
||||
}
|
||||
return combinedSignal;
|
||||
@ -677,7 +679,7 @@ public class ComputerCraft
|
||||
catch( Exception e )
|
||||
{
|
||||
// mod misbehaved, ignore it
|
||||
Logger.error( "Media provider " + mediaProvider + " errored.", e );
|
||||
ComputerCraft.log.error( "Media provider " + mediaProvider + " errored.", e );
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -14,7 +14,6 @@ import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import dan200.computercraft.core.apis.*;
|
||||
import dan200.computercraft.core.filesystem.FileSystem;
|
||||
import dan200.computercraft.core.filesystem.FileSystemException;
|
||||
import dan200.computercraft.core.logger.Logger;
|
||||
import dan200.computercraft.core.lua.ILuaMachine;
|
||||
import dan200.computercraft.core.lua.LuaJLuaMachine;
|
||||
import dan200.computercraft.core.terminal.Terminal;
|
||||
@ -470,7 +469,7 @@ public class Computer
|
||||
}
|
||||
catch( FileSystemException e )
|
||||
{
|
||||
Logger.error( "Cannot mount rom", e );
|
||||
ComputerCraft.log.error( "Cannot mount rom", e );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
package dan200.computercraft.core.computer;
|
||||
|
||||
import dan200.computercraft.core.logger.Logger;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
@ -108,7 +108,7 @@ public class ComputerThread
|
||||
try {
|
||||
task.execute();
|
||||
} catch( Throwable e ) {
|
||||
Logger.error( "Error running task", e );
|
||||
ComputerCraft.log.error( "Error running task", e );
|
||||
}
|
||||
}
|
||||
} );
|
||||
@ -140,7 +140,7 @@ public class ComputerThread
|
||||
// Step 3: abandon
|
||||
if( worker.isAlive() )
|
||||
{
|
||||
Logger.warn( "Failed to abort Computer " + computer.getID() + ". Dangling lua thread could cause errors." );
|
||||
ComputerCraft.log.warn( "Failed to abort Computer " + computer.getID() + ". Dangling lua thread could cause errors." );
|
||||
worker.interrupt();
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +0,0 @@
|
||||
package dan200.computercraft.core.logger;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
public interface ILogger
|
||||
{
|
||||
void log( Level level, String message );
|
||||
|
||||
void log( Level level, String message, Throwable t );
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
package dan200.computercraft.core.logger;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class Log4JLogger implements ILogger
|
||||
{
|
||||
private final org.apache.logging.log4j.Logger logger;
|
||||
|
||||
public Log4JLogger( Logger logger )
|
||||
{
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log( Level level, String message )
|
||||
{
|
||||
logger.log( mapLevel( level ), message );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log( Level level, String message, Throwable t )
|
||||
{
|
||||
logger.log( mapLevel( level ), message, t );
|
||||
}
|
||||
|
||||
private static org.apache.logging.log4j.Level mapLevel( Level level )
|
||||
{
|
||||
if( level == Level.SEVERE )
|
||||
{
|
||||
return org.apache.logging.log4j.Level.ERROR;
|
||||
}
|
||||
else if( level == Level.WARNING )
|
||||
{
|
||||
return org.apache.logging.log4j.Level.WARN;
|
||||
}
|
||||
else if( level == Level.INFO )
|
||||
{
|
||||
return org.apache.logging.log4j.Level.INFO;
|
||||
}
|
||||
else if( level == Level.FINE )
|
||||
{
|
||||
return org.apache.logging.log4j.Level.DEBUG;
|
||||
}
|
||||
else if( level == Level.FINER )
|
||||
{
|
||||
return org.apache.logging.log4j.Level.TRACE;
|
||||
}
|
||||
else if( level == Level.ALL )
|
||||
{
|
||||
return org.apache.logging.log4j.Level.ALL;
|
||||
}
|
||||
else
|
||||
{
|
||||
return org.apache.logging.log4j.Level.INFO;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
package dan200.computercraft.core.logger;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class Logger
|
||||
{
|
||||
private static ILogger instance;
|
||||
|
||||
@Nonnull
|
||||
public static ILogger getInstance()
|
||||
{
|
||||
ILogger logger = instance;
|
||||
if( logger == null ) logger = instance = new StdoutLogger();
|
||||
return logger;
|
||||
}
|
||||
|
||||
public static void setInstance( @Nonnull ILogger logger )
|
||||
{
|
||||
if( logger == null ) throw new NullPointerException( "Logger cannot be null" );
|
||||
instance = logger;
|
||||
}
|
||||
|
||||
public static void log( Level level, String message )
|
||||
{
|
||||
getInstance().log( level, message );
|
||||
}
|
||||
|
||||
public static void log( Level level, String message, Throwable t )
|
||||
{
|
||||
getInstance().log( level, message, t );
|
||||
}
|
||||
|
||||
public static void error( String message )
|
||||
{
|
||||
getInstance().log( Level.SEVERE, message );
|
||||
}
|
||||
|
||||
public static void error( String message, Throwable t )
|
||||
{
|
||||
getInstance().log( Level.SEVERE, message, t );
|
||||
}
|
||||
|
||||
public static void warn( String message )
|
||||
{
|
||||
getInstance().log( Level.WARNING, message );
|
||||
}
|
||||
|
||||
public static void warn( String message, Throwable t )
|
||||
{
|
||||
getInstance().log( Level.WARNING, message, t );
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs {@code message} and creates a new {@link RuntimeException} using the same message.
|
||||
*
|
||||
* @param message The message to log.
|
||||
* @return The exception using the same message.
|
||||
*/
|
||||
public static RuntimeException loggedError( String message )
|
||||
{
|
||||
getInstance().log( Level.SEVERE, message );
|
||||
return new RuntimeException( message );
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
package dan200.computercraft.core.logger;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class StdoutLogger implements ILogger
|
||||
{
|
||||
|
||||
@Override
|
||||
public void log( Level level, String message )
|
||||
{
|
||||
System.out.printf( "[%s] %s\n", level.getName(), message );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log( Level level, String message, Throwable t )
|
||||
{
|
||||
System.out.printf( "[%s] %s\n", level.getName(), message );
|
||||
t.printStackTrace( System.out );
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@ import dan200.computercraft.core.apis.ILuaAPI;
|
||||
import dan200.computercraft.core.computer.Computer;
|
||||
import dan200.computercraft.core.computer.ITask;
|
||||
import dan200.computercraft.core.computer.MainThread;
|
||||
import dan200.computercraft.core.logger.Logger;
|
||||
|
||||
import org.luaj.vm2.*;
|
||||
import org.luaj.vm2.lib.OneArgFunction;
|
||||
import org.luaj.vm2.lib.VarArgFunction;
|
||||
@ -184,7 +184,7 @@ public class LuaJLuaMachine implements ILuaMachine
|
||||
}
|
||||
catch( LuaError e )
|
||||
{
|
||||
Logger.warn( "Could not load bios.lua ", e );
|
||||
ComputerCraft.log.warn( "Could not load bios.lua ", e );
|
||||
if( m_mainRoutine != null )
|
||||
{
|
||||
((LuaThread)m_mainRoutine).abandon();
|
||||
@ -415,7 +415,7 @@ public class LuaJLuaMachine implements ILuaMachine
|
||||
}
|
||||
catch( Throwable t )
|
||||
{
|
||||
Logger.error( "Error running task", t);
|
||||
ComputerCraft.log.error( "Error running task", t);
|
||||
m_computer.queueEvent( "task_complete", new Object[] {
|
||||
taskID, false, "Java Exception Thrown: " + t.toString()
|
||||
} );
|
||||
@ -482,7 +482,7 @@ public class LuaJLuaMachine implements ILuaMachine
|
||||
}
|
||||
catch( Throwable t )
|
||||
{
|
||||
Logger.error( "Error calling " + methodName + " on " + apiObject, t );
|
||||
ComputerCraft.log.error( "Error calling " + methodName + " on " + apiObject, t );
|
||||
throw new LuaError( "Java Exception Thrown: " + t.toString(), 0 );
|
||||
}
|
||||
return LuaValue.varargsOf( toValues( results, 0 ) );
|
||||
|
@ -7,11 +7,11 @@
|
||||
package dan200.computercraft.shared.computer.apis;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.lua.ILuaContext;
|
||||
import dan200.computercraft.api.lua.ILuaTask;
|
||||
import dan200.computercraft.api.lua.LuaException;
|
||||
import dan200.computercraft.core.apis.ILuaAPI;
|
||||
import dan200.computercraft.core.logger.Logger;
|
||||
import dan200.computercraft.shared.computer.blocks.TileCommandComputer;
|
||||
import dan200.computercraft.shared.util.WorldUtil;
|
||||
import net.minecraft.block.Block;
|
||||
@ -99,7 +99,7 @@ public class CommandAPI implements ILuaAPI
|
||||
}
|
||||
catch( Throwable t )
|
||||
{
|
||||
Logger.error( "Error running command.", t );
|
||||
ComputerCraft.log.error( "Error running command.", t );
|
||||
return new Object[]{ false, createOutput( "Java Exception Thrown: " + t.toString() ) };
|
||||
}
|
||||
}
|
||||
@ -210,7 +210,7 @@ public class CommandAPI implements ILuaAPI
|
||||
catch( Throwable t )
|
||||
{
|
||||
// Ignore buggy command
|
||||
Logger.error( "Error running command.", t );
|
||||
ComputerCraft.log.error( "Error running command.", t );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@
|
||||
package dan200.computercraft.shared.network;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.core.logger.Logger;
|
||||
import net.minecraft.network.NetHandlerPlayServer;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.network.FMLNetworkEvent;
|
||||
@ -25,7 +24,7 @@ public class PacketHandler
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
Logger.error( "Error handling packet", e );
|
||||
ComputerCraft.log.error( "Error handling packet", e );
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,7 +39,7 @@ public class PacketHandler
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
Logger.error( "Error handling packet", e );
|
||||
ComputerCraft.log.error( "Error handling packet", e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ package dan200.computercraft.shared.proxy;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||
import dan200.computercraft.core.logger.Logger;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.computer.items.ComputerItemFactory;
|
||||
import dan200.computercraft.shared.turtle.blocks.BlockTurtle;
|
||||
@ -84,7 +83,9 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
|
||||
int id = upgrade.getLegacyUpgradeID();
|
||||
if( id >= 0 && id < 64 )
|
||||
{
|
||||
throw Logger.loggedError( "Error registering '" + upgrade.getUnlocalisedAdjective() + " Turtle'. Legacy UpgradeID '" + id + "' is reserved by ComputerCraft" );
|
||||
String message = "Error registering '" + upgrade.getUnlocalisedAdjective() + " Turtle'. Legacy UpgradeID '" + id + "' is reserved by ComputerCraft";
|
||||
ComputerCraft.log.error( message );
|
||||
throw new RuntimeException( message );
|
||||
}
|
||||
|
||||
// Register
|
||||
@ -118,7 +119,7 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
Logger.error("Error checking stackability of items", e);
|
||||
ComputerCraft.log.error("Error checking stackability of items", e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -255,13 +256,17 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
|
||||
{
|
||||
if( legacyID >= Short.MAX_VALUE )
|
||||
{
|
||||
throw Logger.loggedError( "Error registering '" + upgrade.getUnlocalisedAdjective() + " Turtle'. UpgradeID '" + legacyID + "' is out of range" );
|
||||
String message = "Error registering '" + upgrade.getUnlocalisedAdjective() + " Turtle'. UpgradeID '" + legacyID + "' is out of range";
|
||||
ComputerCraft.log.error( message );
|
||||
throw new RuntimeException( message );
|
||||
}
|
||||
|
||||
ITurtleUpgrade existing = m_legacyTurtleUpgrades.get( legacyID );
|
||||
if( existing != null )
|
||||
{
|
||||
throw Logger.loggedError( "Error registering '" + upgrade.getUnlocalisedAdjective() + " Turtle'. UpgradeID '" + legacyID + "' is already registered by '" + existing.getUnlocalisedAdjective() + " Turtle'" );
|
||||
String message = "Error registering '" + upgrade.getUnlocalisedAdjective() + " Turtle'. UpgradeID '" + legacyID + "' is already registered by '" + existing.getUnlocalisedAdjective() + " Turtle'";
|
||||
ComputerCraft.log.error( message );
|
||||
throw new RuntimeException( message );
|
||||
}
|
||||
}
|
||||
|
||||
@ -269,7 +274,9 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
|
||||
ITurtleUpgrade existing = m_turtleUpgrades.get( id );
|
||||
if( existing != null )
|
||||
{
|
||||
throw Logger.loggedError( "Error registering '" + upgrade.getUnlocalisedAdjective() + " Turtle'. UpgradeID '" + id + "' is already registered by '" + existing.getUnlocalisedAdjective() + " Turtle'" );
|
||||
String message = "Error registering '" + upgrade.getUnlocalisedAdjective() + " Turtle'. UpgradeID '" + id + "' is already registered by '" + existing.getUnlocalisedAdjective() + " Turtle'";
|
||||
ComputerCraft.log.error( message );
|
||||
throw new RuntimeException( message );
|
||||
}
|
||||
|
||||
// Register
|
||||
|
@ -1,6 +1,6 @@
|
||||
package dan200.computercraft.shared.util;
|
||||
|
||||
import dan200.computercraft.core.logger.Logger;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
@ -52,7 +52,7 @@ public class IDAssigner
|
||||
}
|
||||
catch( NumberFormatException e )
|
||||
{
|
||||
Logger.error( "Unexpected file '" + content + "' in '" + location.getAbsolutePath() + "'", e );
|
||||
ComputerCraft.log.error( "Unexpected file '" + content + "' in '" + location.getAbsolutePath() + "'", e );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -85,7 +85,7 @@ public class IDAssigner
|
||||
}
|
||||
catch( IOException e )
|
||||
{
|
||||
Logger.error( "Cannot open ID file '" + lastidFile + "'", e );
|
||||
ComputerCraft.log.error( "Cannot open ID file '" + lastidFile + "'", e );
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -95,7 +95,7 @@ public class IDAssigner
|
||||
}
|
||||
catch( NumberFormatException e )
|
||||
{
|
||||
Logger.error( "Cannot parse ID file '" + lastidFile + "', perhaps it is corrupt?", e );
|
||||
ComputerCraft.log.error( "Cannot parse ID file '" + lastidFile + "', perhaps it is corrupt?", e );
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -110,7 +110,7 @@ public class IDAssigner
|
||||
}
|
||||
catch( IOException e )
|
||||
{
|
||||
Logger.error( "An error occured while trying to create the computer folder. Please check you have relevant permissions.", e );
|
||||
ComputerCraft.log.error( "An error occured while trying to create the computer folder. Please check you have relevant permissions.", e );
|
||||
}
|
||||
|
||||
return id;
|
||||
|
Loading…
x
Reference in New Issue
Block a user