Пример #1
0
  String getLogDir(Configuration conf) {
    String logDir = conf.get("hive.log.dir");
    if (logDir == null) {
      logDir = System.getProperty("hive.log.dir");
    }
    if (logDir != null) {
      return logDir;
    }

    LoggerContext context = (LoggerContext) LogManager.getContext(false);
    for (Logger logger : context.getLoggers()) {
      for (Appender appender : logger.getAppenders().values()) {
        if (appender instanceof AbstractOutputStreamAppender) {
          OutputStreamManager manager = ((AbstractOutputStreamAppender<?>) appender).getManager();
          if (manager instanceof FileManager) {
            String fileName = ((FileManager) manager).getFileName();
            if (fileName != null) {
              return fileName.substring(0, fileName.lastIndexOf('/'));
            }
          }
        }
      }
    }
    return null;
  }
Пример #2
0
 public final Category getParent() {
   final org.apache.logging.log4j.core.Logger parent = logger.getParent();
   if (parent == null) {
     return null;
   }
   final ConcurrentMap<String, Logger> loggers = getLoggersMap(logger.getContext());
   final Logger l = loggers.get(parent.getName());
   return l == null ? new Category(parent) : l;
 }
Пример #3
0
 private void maybeLog(
     final String fqcn,
     final org.apache.logging.log4j.Level level,
     final Object message,
     final Throwable throwable) {
   if (logger.isEnabled(level, null, message, throwable)) {
     logger.logMessage(FQCN, level, null, new ObjectMessage(message), throwable);
   }
 }
Пример #4
0
  @EventHandler
  public void postInit(FMLPostInitializationEvent event) {
    RegistrationManager.INSTANCE.registerAll(this, "PostInit");

    try {
      Class.forName("ic2.core.IC2");
      try {
        Class.forName("cn.academy.support.ic2.IC2Support").getMethod("init").invoke(this);
        ic2SupportPresent = true;
      } catch (Throwable e) {
        log.error("Failed to initialize IC2 support", e);
      }
    } catch (Throwable e) {
    }

    try {
      Class.forName("cofh.thermalexpansion.ThermalExpansion");
      try {
        Class.forName("cn.academy.support.te.TESupport").getMethod("init").invoke(this);
        teSupportPresent = true;
      } catch (Throwable e) {
        log.error("Failed to initialize TE support", e);
      }
    } catch (Throwable e) {
    }

    recipes.addRecipeFromResourceLocation(new ResourceLocation("academy:recipes/default.recipe"));

    if (DEBUG_MODE) {
      System.out.printf("|-------------------------------------------------------\n");
      System.out.printf("| AC Recipe Name Mappings\n");
      System.out.printf("|--------------------------|----------------------------\n");
      System.out.printf(String.format("| %-25s| Object Name\n", "Recipe Name"));
      System.out.printf("|--------------------------|----------------------------\n");
      for (Entry<String, Object> entry : recipes.nameMapping.entrySet()) {
        Object obj = entry.getValue();
        String str1 = entry.getKey(), str2;
        if (obj instanceof Item) {
          str2 = StatCollector.translateToLocal(((Item) obj).getUnlocalizedName() + ".name");
        } else if (obj instanceof Block) {
          str2 = StatCollector.translateToLocal(((Block) obj).getUnlocalizedName() + ".name");
        } else {
          str2 = obj.toString();
        }
        System.out.printf(String.format("| %-25s| %s\n", str1, str2));
      }
      System.out.printf("|-------------------------------------------------------\n");
    }

    recipes = null; // Doesn't need it after loading
  }
Пример #5
0
 public void forcedLog(
     final String fqcn, final Priority level, final Object message, final Throwable t) {
   final org.apache.logging.log4j.Level lvl =
       org.apache.logging.log4j.Level.toLevel(level.toString());
   final Message msg = message instanceof Message ? (Message) message : new ObjectMessage(message);
   logger.logMessage(fqcn, lvl, null, msg, t);
 }
Пример #6
0
 public ResourceBundle getResourceBundle() {
   if (bundle != null) {
     return bundle;
   }
   String name = logger.getName();
   final ConcurrentMap<String, Logger> loggers = getLoggersMap(logger.getContext());
   while ((name = NameUtil.getSubName(name)) != null) {
     if (loggers.containsKey(name)) {
       final ResourceBundle rb = loggers.get(name).bundle;
       if (rb != null) {
         return rb;
       }
     }
   }
   return null;
 }
Пример #7
0
  @EventHandler
  public void preInit(FMLPreInitializationEvent event) {
    log.info("Starting AcademyCraft");
    log.info("Copyright (c) Lambda Innovation, 2013-2015");
    log.info("http://ac.li-dev.cn/");

    config = new Configuration(event.getSuggestedConfigurationFile());

    script = new ScriptProgram();
    for (String s : scripts) {
      ResourceLocation res = new ResourceLocation("academy:scripts/" + s + ".r");
      ResourceCheck.add(res);
      script.loadScript(res);
    }

    ResourceCheck.add(new ResourceLocation("academy:recipes/default.recipe"));

    RegistrationManager.INSTANCE.registerAll(this, "PreInit");
  }
Пример #8
0
 public final Level getEffectiveLevel() {
   switch (logger.getLevel().getStandardLevel()) {
     case ALL:
       return Level.ALL;
     case TRACE:
       return Level.TRACE;
     case DEBUG:
       return Level.DEBUG;
     case INFO:
       return Level.INFO;
     case WARN:
       return Level.WARN;
     case ERROR:
       return Level.ERROR;
     case FATAL:
       return Level.FATAL;
     case OFF:
       return Level.OFF;
     default:
       // TODO Should this be an IllegalStateException?
       return Level.OFF;
   }
 }
Пример #9
0
 public boolean isTraceEnabled() {
   return logger.isTraceEnabled();
 }
Пример #10
0
 public boolean isInfoEnabled() {
   return logger.isInfoEnabled();
 }
Пример #11
0
 public boolean isFatalEnabled() {
   return logger.isFatalEnabled();
 }
Пример #12
0
 public boolean isWarnEnabled() {
   return logger.isWarnEnabled();
 }
Пример #13
0
 public void setAdditivity(final boolean additivity) {
   logger.setAdditive(additivity);
 }
Пример #14
0
 public void setLevel(final Level level) {
   logger.setLevel(org.apache.logging.log4j.Level.toLevel(level.levelStr));
 }
Пример #15
0
 public final String getName() {
   return logger.getName();
 }
Пример #16
0
  public org.slf4j.Logger getLogger(String name) {
    name = StringUtil2.replace(name.trim(), ' ', "_");
    org.slf4j.Logger result = map.get(name);
    if (result != null) return result;

    try {
      String fileName = dir + "/" + name + ".log";
      String fileNamePattern = dir + "/" + name + "%i.log";

      // create logger in log4j2
      // TODO: There are Builders that make this logger creation less awkward.
      Configuration config =
          new NullConfiguration(); // LOOK: Why are we using this? Why not DefaultConfiguration?
      PatternLayout layout =
          PatternLayout.createLayout(
              "%d{yyyy-MM-dd'T'HH:mm:ss.SSS Z} %-5p - %m%n", // String pattern
              config, // Configuration config
              null, // RegexReplacement replace
              null, // Charset charset
              true, // boolean alwaysWriteExceptions
              false, // boolean noConsoleNoAnsi
              null, // String header
              null // String footer
              );

      RollingFileAppender app =
          RollingFileAppender.createAppender(
              fileName, // String fileName
              fileNamePattern, // String filePattern
              "true", // String append
              name, // String name
              "true", // String bufferedIO
              null, // String bufferSizeStr
              "true", // String immediateFlush
              SizeBasedTriggeringPolicy.createPolicy(
                  Long.toString(maxSize)), // TriggeringPolicy policy
              DefaultRolloverStrategy.createStrategy( // RolloverStrategy strategy
                  Integer.toString(maxBackups), // String max
                  "1", // String min
                  "max", // String fileIndex
                  null, // String compressionLevelStr
                  config // Configuration config
                  ),
              layout, // Layout<? extends Serializable> layout
              null, // Filter filter
              "true", // String ignore
              "false", // String advertise
              null, // String advertiseURI
              config); // Configuration config

      app.start();

      /*LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
      Configuration conf = ctx.getConfiguration();
      LoggerConfig lconf = conf.getLoggerConfig(name);
      lconf.setAdditive(false); // otherwise, it also gets sent to root logger (threddsServlet.log)
      lconf.setLevel(level);
      lconf.addAppender(app, level, null);
      ctx.updateLoggers(conf);  */

      org.apache.logging.log4j.core.Logger log4j =
          (org.apache.logging.log4j.core.Logger) LogManager.getLogger(name);
      log4j.addAppender(app);
      log4j.setLevel(level);
      log4j.setAdditive(false); // otherwise, it also gets sent to root logger (threddsServlet.log)

      startupLog.info("LoggerFactorySpecial add logger= {} file= {}", name, fileName);

      result = org.slf4j.LoggerFactory.getLogger(name); // get wrapper in slf4j
      map.put(name, result);
      return result;

    } catch (Throwable ioe) {
      startupLog.error("LoggerFactorySpecial failed on " + name, ioe);

      // standard slf4j - rely on external configuration
      return org.slf4j.LoggerFactory.getLogger(name);
    }
  }
Пример #17
0
 public boolean getAdditivity() {
   return logger.isAdditive();
 }
Пример #18
0
 public void setPriority(final Priority priority) {
   logger.setLevel(org.apache.logging.log4j.Level.toLevel(priority.levelStr));
 }
Пример #19
0
 public boolean isDebugEnabled() {
   return logger.isDebugEnabled();
 }
Пример #20
0
 public boolean isErrorEnabled() {
   return logger.isErrorEnabled();
 }
Пример #21
0
 private boolean isEnabledFor(final org.apache.logging.log4j.Level level) {
   return logger.isEnabled(level, null, null);
 }
Пример #22
0
  protected boolean init()
      throws java.net.UnknownHostException { // CraftBukkit - throws UnknownHostException
    ThreadCommandReader threadcommandreader =
        new ThreadCommandReader(this, "Server console handler");

    threadcommandreader.setDaemon(true);
    threadcommandreader.start();

    // CraftBukkit start - TODO: handle command-line logging arguments
    java.util.logging.Logger global = java.util.logging.Logger.getLogger("");
    global.setUseParentHandlers(false);
    for (java.util.logging.Handler handler : global.getHandlers()) {
      global.removeHandler(handler);
    }
    global.addHandler(new org.bukkit.craftbukkit.util.ForwardLogHandler());

    final org.apache.logging.log4j.core.Logger logger =
        ((org.apache.logging.log4j.core.Logger) LogManager.getRootLogger());
    for (org.apache.logging.log4j.core.Appender appender : logger.getAppenders().values()) {
      if (appender instanceof org.apache.logging.log4j.core.appender.ConsoleAppender) {
        logger.removeAppender(appender);
      }
    }

    new Thread(new org.bukkit.craftbukkit.util.TerminalConsoleWriterThread(System.out, this.reader))
        .start();

    System.setOut(new PrintStream(new LoggerOutputStream(logger, Level.INFO), true));
    System.setErr(new PrintStream(new LoggerOutputStream(logger, Level.WARN), true));
    // CraftBukkit end

    i.info("Starting minecraft server version 1.7.10");
    if (Runtime.getRuntime().maxMemory() / 1024L / 1024L < 512L) {
      i.warn(
          "To start the server with more ram, launch it as \"java -Xmx1024M -Xms1024M -jar minecraft_server.jar\"");
    }

    i.info("Loading properties");
    this.propertyManager = new PropertyManager(this.options); // CraftBukkit - CLI argument support
    this.n = new EULA(new File("eula.txt"));
    if (!this.n.a()) {
      i.info(
          "You need to agree to the EULA in order to run the server. Go to eula.txt for more info.");
      this.n.b();
      return false;
    } else {
      if (this.N()) {
        this.c("127.0.0.1");
      } else {
        this.setOnlineMode(this.propertyManager.getBoolean("online-mode", true));
        this.c(this.propertyManager.getString("server-ip", ""));
      }

      this.setSpawnAnimals(this.propertyManager.getBoolean("spawn-animals", true));
      this.setSpawnNPCs(this.propertyManager.getBoolean("spawn-npcs", true));
      this.setPvP(this.propertyManager.getBoolean("pvp", true));
      this.setAllowFlight(this.propertyManager.getBoolean("allow-flight", false));
      this.setTexturePack(this.propertyManager.getString("resource-pack", ""));
      this.setMotd(this.propertyManager.getString("motd", "A Minecraft Server"));
      this.setForceGamemode(this.propertyManager.getBoolean("force-gamemode", false));
      this.setIdleTimeout(this.propertyManager.getInt("player-idle-timeout", 0));
      if (this.propertyManager.getInt("difficulty", 1) < 0) {
        this.propertyManager.setProperty("difficulty", Integer.valueOf(0));
      } else if (this.propertyManager.getInt("difficulty", 1) > 3) {
        this.propertyManager.setProperty("difficulty", Integer.valueOf(3));
      }

      this.generateStructures = this.propertyManager.getBoolean("generate-structures", true);
      int gamemode =
          this.propertyManager.getInt(
              "gamemode",
              EnumGamemode.SURVIVAL
                  .getId()); // CraftBukkit - Unique name to avoid stomping on logger

      this.p = WorldSettings.a(gamemode); // CraftBukkit - Use new name
      i.info("Default game type: " + this.p);
      InetAddress inetaddress = null;

      if (this.getServerIp().length() > 0) {
        inetaddress = InetAddress.getByName(this.getServerIp());
      }

      if (this.L() < 0) {
        this.setPort(this.propertyManager.getInt("server-port", 25565));
      }

      i.info("Generating keypair");
      this.a(MinecraftEncryption.b());
      i.info(
          "Starting Minecraft server on "
              + (this.getServerIp().length() == 0 ? "*" : this.getServerIp())
              + ":"
              + this.L());

      try {
        this.ai().a(inetaddress, this.L());
      } catch (Throwable ioexception) { // CraftBukkit - IOException -> Throwable
        i.warn("**** FAILED TO BIND TO PORT!");
        i.warn("The exception was: {}", new Object[] {ioexception.toString()});
        i.warn("Perhaps a server is already running on that port?");
        return false;
      }

      this.a((PlayerList) (new DedicatedPlayerList(this))); // CraftBukkit

      if (!this.getOnlineMode()) {
        i.warn("**** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!");
        i.warn("The server will make no attempt to authenticate usernames. Beware.");
        i.warn(
            "While this makes the game possible to play without internet access, it also opens up the ability for hackers to connect with any username they choose.");
        i.warn("To change this, set \"online-mode\" to \"true\" in the server.properties file.");
      }

      if (this.aE()) {
        this.getUserCache().c();
      }

      if (!NameReferencingFileConverter.a(this.propertyManager)) {
        return false;
      } else {
        // this.a((PlayerList) (new DedicatedPlayerList(this))); // CraftBukkit - moved up
        this.convertable =
            new WorldLoaderServer(
                server.getWorldContainer()); // CraftBukkit - moved from MinecraftServer constructor
        long j = System.nanoTime();

        if (this.O() == null) {
          this.k(this.propertyManager.getString("level-name", "world"));
        }

        String s = this.propertyManager.getString("level-seed", "");
        String s1 = this.propertyManager.getString("level-type", "DEFAULT");
        String s2 = this.propertyManager.getString("generator-settings", "");
        long k = (new Random()).nextLong();

        if (s.length() > 0) {
          try {
            long l = Long.parseLong(s);

            if (l != 0L) {
              k = l;
            }
          } catch (NumberFormatException numberformatexception) {
            k = (long) s.hashCode();
          }
        }

        WorldType worldtype = WorldType.getType(s1);

        if (worldtype == null) {
          worldtype = WorldType.NORMAL;
        }

        this.at();
        this.getEnableCommandBlock();
        this.l();
        this.getSnooperEnabled();
        this.c(this.propertyManager.getInt("max-build-height", 256));
        this.c((this.getMaxBuildHeight() + 8) / 16 * 16);
        this.c(MathHelper.a(this.getMaxBuildHeight(), 64, 256));
        this.propertyManager.setProperty(
            "max-build-height", Integer.valueOf(this.getMaxBuildHeight()));
        i.info("Preparing level \"" + this.O() + "\"");
        this.a(this.O(), this.O(), k, worldtype, s2);
        long i1 = System.nanoTime() - j;
        String s3 = String.format("%.3fs", new Object[] {Double.valueOf((double) i1 / 1.0E9D)});

        i.info("Done (" + s3 + ")! For help, type \"help\" or \"?\"");
        if (this.propertyManager.getBoolean("enable-query", false)) {
          i.info("Starting GS4 status listener");
          this.k = new RemoteStatusListener(this);
          this.k.a();
        }

        if (this.propertyManager.getBoolean("enable-rcon", false)) {
          i.info("Starting remote control listener");
          this.l = new RemoteControlListener(this);
          this.l.a();
          this.remoteConsole =
              new org.bukkit.craftbukkit.command.CraftRemoteConsoleCommandSender(); // CraftBukkit
        }

        // CraftBukkit start
        if (this.server.getBukkitSpawnRadius() > -1) {
          i.info(
              "'settings.spawn-radius' in bukkit.yml has been moved to 'spawn-protection' in server.properties. I will move your config for you.");
          this.propertyManager.properties.remove("spawn-protection");
          this.propertyManager.getInt("spawn-protection", this.server.getBukkitSpawnRadius());
          this.server.removeBukkitSpawnRadius();
          this.propertyManager.savePropertiesFile();
        }
        // CraftBukkit end

        return true;
      }
    }
  }