Example #1
0
 @Override
 public synchronized void publish(LogRecord record) {
   if (!isLoggable(record)) {
     return;
   }
   checkRotate();
   super.publish(record);
   super.flush();
 }
Example #2
0
 private void walkDir(String s, File dir, FileStreamOpener current) throws IOException {
   for (File file : dir.listFiles()) {
     if (file.isDirectory()) {
       handler.handle(true, s + file.getName() + '/', null, file);
       walkDir(s + file.getName() + '/', file, current);
     } else {
       current.setFile(file);
       try {
         handler.handle(false, s + file.getName(), current, file);
       } finally {
         IOUtils.closeQuietly(current);
       }
     }
   }
 }
 // Initialize the socket connection and prepare the output stream
 private void initSocket(String host, String port) throws IOException {
   // check the validity of the host name
   if (null == host || "".equals(host)) { // $NON-NLS-1$
     // logging.C=Illegal host argument.
     throw new IllegalArgumentException(Messages.getString("logging.C")); // $NON-NLS-1$
   }
   // check the validity of the port number
   int p = 0;
   try {
     p = Integer.parseInt(port);
   } catch (NumberFormatException e) {
     // logging.D=Illegal port argument.
     throw new IllegalArgumentException(Messages.getString("logging.D")); // $NON-NLS-1$
   }
   if (p <= 0) {
     // logging.D=Illegal port argument.
     throw new IllegalArgumentException(Messages.getString("logging.D")); // $NON-NLS-1$
   }
   // establish the network connection
   try {
     this.socket = new Socket(host, p);
   } catch (IOException e) {
     // logging.E=Failed to establish the network connection.
     getErrorManager()
         .error(
             Messages.getString("logging.E"),
             e, //$NON-NLS-1$
             ErrorManager.OPEN_FAILURE);
     throw e;
   }
   // BEGIN android-modified
   super.internalSetOutputStream(new BufferedOutputStream(this.socket.getOutputStream(), 8192));
   // END android-modified
 }
 /**
  * Format and publish a <tt>LogRecord</tt>.
  *
  * @param record description of the log event. A null record is silently ignored and is not
  *     published
  */
 public synchronized void publish(LogRecord record) {
   if (!isLoggable(record)) {
     return;
   }
   super.publish(record);
   flush();
 }
Example #5
0
  /** Set up reflection methods required by the loader */
  @SuppressWarnings("unchecked")
  private boolean prepareLoader() {
    try {
      // addURL method is used by the class loader to
      mAddUrl = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
      mAddUrl.setAccessible(true);

      Formatter minecraftLogFormatter = null;

      try {
        Class<? extends Formatter> formatterClass =
            (Class<? extends Formatter>)
                Minecraft.class
                    .getClassLoader()
                    .loadClass(
                        ModUtilities.getObfuscatedFieldName(
                            "net.minecraft.src.ConsoleLogFormatter", "em"));
        Constructor<? extends Formatter> defaultConstructor =
            formatterClass.getDeclaredConstructor();
        defaultConstructor.setAccessible(true);
        minecraftLogFormatter = defaultConstructor.newInstance();
      } catch (Exception ex) {
        ConsoleLogManager.init();
        minecraftLogFormatter = ConsoleLogManager.loggerLogManager.getHandlers()[0].getFormatter();
      }

      logger.setUseParentHandlers(false);

      StreamHandler consoleHandler = new ConsoleHandler();
      if (minecraftLogFormatter != null) consoleHandler.setFormatter(minecraftLogFormatter);
      logger.addHandler(consoleHandler);

      FileHandler logFileHandler =
          new FileHandler(
              new File(Minecraft.getMinecraftDir(), "LiteLoader.txt").getAbsolutePath());
      if (minecraftLogFormatter != null) logFileHandler.setFormatter(minecraftLogFormatter);
      logger.addHandler(logFileHandler);
    } catch (Throwable th) {
      logger.log(Level.SEVERE, "Error initialising LiteLoader", th);
      return false;
    }

    return true;
  }
Example #6
0
 private void checkRotate() {
   if (rotate) {
     String newFilename = calculateFilename();
     if (!filename.equals(newFilename)) {
       filename = newFilename;
       // note that the console handler doesn't see this message
       super.publish(new LogRecord(Level.INFO, "Log rotating to: " + filename));
       updateOutput();
     }
   }
 }
 /**
  * Close this output stream.
  *
  * @exception SecurityException if a security manager exists and if the caller does not have
  *     <tt>LoggingPermission("control")</tt>.
  */
 public synchronized void close() throws SecurityException {
   super.close();
   if (sock != null) {
     try {
       sock.close();
     } catch (IOException ix) {
       // drop through.
     }
   }
   sock = null;
 }
Example #8
0
 @Override
 public synchronized void flush() {
   if (rotate) {
     String newFilename = calculateFilename();
     if (!filename.equals(newFilename)) {
       filename = newFilename;
       logger.log(Level.INFO, "Log rotating to {0}...", filename);
       updateOutput();
     }
   }
   super.flush();
 }
 /**
  * Closes this handler. The network connection to the host is also closed.
  *
  * @throws SecurityException If a security manager determines that the caller does not have the
  *     required permission to control this handler.
  */
 @Override
 public void close() {
   try {
     super.close();
     if (null != this.socket) {
       this.socket.close();
       this.socket = null;
     }
   } catch (Exception e) {
     // logging.F=Exception occurred when closing the socket handler.
     getErrorManager()
         .error(
             Messages.getString("logging.F"),
             e, //$NON-NLS-1$
             ErrorManager.CLOSE_FAILURE);
   }
 }
Example #10
0
  public void walk(File dirORzip) throws IOException {
    if (dirORzip.isDirectory()) {
      walkDir("", dirORzip, new FileStreamOpener());
    } else {

      final ZipInputStream zis = new ZipInputStream(FileUtils.openInputStream(dirORzip));
      try {
        StreamOpener opener =
            new StreamOpener() {
              public InputStream get() {
                return zis;
              }
            };
        for (ZipEntry entry = zis.getNextEntry(); entry != null; entry = zis.getNextEntry()) {
          handler.handle(
              entry.isDirectory(), entry.getName(), entry.isDirectory() ? null : opener, entry);
          zis.closeEntry();
        }
      } finally {
        IOUtils.closeQuietly(zis);
      }
    }
  }
 public void publish(LogRecord record) {
   super.publish(record);
   flush();
 }
Example #12
0
 /**
  * Logs a record if necessary. A flush operation will be done afterwards.
  *
  * @param record the log record to be logged
  */
 @Override
 public void publish(LogRecord record) {
   super.publish(record);
   super.flush();
 }
Example #13
0
 @Override
 public synchronized void flush() {
   checkRotate();
   super.flush();
 }