Ejemplo n.º 1
0
  @Before
  public void setUp() throws FileNotFoundException, IOException {
    outStream = new FileOutputStream(basedir + "/target/run-junit-embed.log", true);
    Handler handler = new StreamHandler(outStream, new SimpleFormatter());
    logger0.addHandler(handler);
    logger0.setUseParentHandlers(false);
    logger0.setLevel(Level.INFO);
    logger1.setUseParentHandlers(false);
    logger1.addHandler(new ConsoleHandler());
    logger1.setLevel(Level.WARNING);

    writer = new FileWriter(basedir + "/target/run-junit-embed.txt", true);
  }
Ejemplo n.º 2
0
  @Before
  public void setUp() throws FileNotFoundException {
    System.setProperty("org.jruby.embed.localcontext.scope", "threadsafe");

    outStream = new FileOutputStream(basedir + "/build/test-results/run-junit-embed.log", true);
    Handler handler = new StreamHandler(outStream, new SimpleFormatter());
    logger0.addHandler(handler);
    logger0.setUseParentHandlers(false);
    logger0.setLevel(Level.INFO);
    logger1.setUseParentHandlers(false);
    logger1.addHandler(new ConsoleHandler());
    logger1.setLevel(Level.WARNING);
  }
Ejemplo n.º 3
0
 @Override
 public File[] getFiles(uSkyBlock plugin) {
   log = plugin.getLogger();
   try {
     if (handler == null) {
       handler =
           new FileHandler(plugin.getDataFolder() + File.separator + "name2uuid-report.log", true);
       handler.setFormatter(new SimpleFormatter());
     } else {
       log.removeHandler(handler);
     }
     log.addHandler(handler);
     log.setUseParentHandlers(false);
   } catch (IOException e) {
     log.severe("Unable to create file-logging to a report.log file");
   }
   name2uuid.clear();
   this.plugin = plugin;
   File[] playerFiles = new File(plugin.getDataFolder(), "players").listFiles(YML_FILES);
   File[] islandFiles = new File(plugin.getDataFolder(), "islands").listFiles(YML_FILES);
   File[] files = new File[islandFiles.length + playerFiles.length];
   System.arraycopy(playerFiles, 0, files, 0, playerFiles.length);
   System.arraycopy(islandFiles, 0, files, playerFiles.length, islandFiles.length);
   return files;
 }
Ejemplo n.º 4
0
 {
   logger.setUseParentHandlers(false);
   logger.setLevel(Level.INFO);
   ConsoleHandler handler = new ConsoleHandler();
   handler.setLevel(Level.INFO);
   logger.addHandler(handler);
 }
  public void preprocess(Run run) {
    File logFile = new File(getRunDir(run), "genetik.log");

    try {
      SimpleFileHandler fh = new SimpleFileHandler(logFile);
      fh.setFormatter(new CompactFormatter());

      Logger logger = Logger.getLogger(GenetikConstants.LOGGER);
      logger.setLevel(Level.INFO);
      logger.setUseParentHandlers(false);
      Handler handlers[] = logger.getHandlers();

      logger.addHandler(fh);

      for (Handler h : handlers) {
        logger.removeHandler(h);

        if (h instanceof SimpleFileHandler) h.close(); // close our old one
      }
    } catch (Exception exp) {
      throw new IllegalArgumentException(
          "Unable to create log file at " + logFile.getAbsolutePath());
    }

    super.preprocess(run);
  }
Ejemplo n.º 6
0
  /** Sets up the file logging for debugging purposes. */
  private static void setUpLogger() {
    try {
      LogManager.getLogManager().reset();
      logger.setUseParentHandlers(false);

      // Log file
      FileHandler loggingFileHandler = new FileHandler("./log" + playerNumber + ".log");
      loggingFileHandler.setLevel(Level.ALL);

      // Console logging
      ConsoleHandler loggingConsoleHandler = new ConsoleHandler();
      loggingConsoleHandler.setLevel(Level.OFF);

      // Remove old handlers
      Handler[] handlers = Logger.getGlobal().getHandlers();

      for (Handler handler : handlers) {
        Logger.getGlobal().removeHandler(handler);
      }

      // Add logging handlers
      logger.addHandler(loggingFileHandler);
      logger.addHandler(loggingConsoleHandler);

      System.setProperty(
          "java.util.logging.SimpleFormatter.format",
          "%1$tb %1$td, %1$tY %1$tl:%1$tM:%1$tS %1$Tp %2$s %4$s: %5$s%n");
      SimpleFormatter simpleFormatter = new SimpleFormatter();
      loggingFileHandler.setFormatter(simpleFormatter);

      logger.setLevel(Level.ALL);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 7
0
  private static void initLogger(Level loglevel) {
    logger.setLevel(loglevel);
    logger.setUseParentHandlers(false);

    Handler handler = new ConsoleHandler();
    handler.setFormatter(
        new Formatter() {
          @Override
          public String format(LogRecord record) {
            GregorianCalendar cal = new GregorianCalendar();
            cal.setTimeInMillis(record.getMillis());

            StringBuilder out = new StringBuilder();
            out.append(
                String.format(
                    "[ %02d:%02d:%02d ] ",
                    cal.get(Calendar.HOUR_OF_DAY),
                    cal.get(Calendar.MINUTE),
                    cal.get(Calendar.SECOND)));
            out.append(record.getLevel().getName()).append(": ").append(record.getMessage());
            if (logger.getLevel().intValue() <= Level.FINE.intValue()) {
              out.append("  [ ")
                  .append(record.getSourceClassName())
                  .append(".")
                  .append(record.getSourceMethodName())
                  .append("() ]");
            }
            out.append(System.getProperty("line.separator"));

            return out.toString();
          }
        });
    logger.addHandler(handler);
  }
  /**
   * Private constructor
   *
   * @throws SimulatorException
   */
  private SimulatorLogger() throws SimulatorException {
    try {
      config = SimulatorConfig.getInstance();
      logger = Logger.getLogger("it.univaq.mancoosi.simulator");

      if (config.isConsoleLog() || config.isSaveFileLog()) {

        if (config.isConsoleLog()) {
          logger.setUseParentHandlers(false);
          Handler ch = new MyHandler();
          logger.addHandler(ch);
        }

        if (config.isSaveFileLog()) {
          fh = new FileHandler(config.getDirLog() + "log_" + getTime() + ".txt");

          fh.setFormatter(new SimpleFormatter());
          logger.addHandler(fh);
        }

        logger.setLevel(Level.ALL);

      } else {
        logger.setLevel(Level.OFF);
      }

    } catch (SecurityException e) {
      throw new SimulatorException("Error logger security ", e);
    } catch (IOException e) {
      throw new SimulatorException("IO error in logger", e);
    }
  }
  private void initLogger() {
    log = Logger.getLogger(this.getClass().getName());
    log.setUseParentHandlers(false);
    log.setLevel(Level.ALL);

    try {
      new File(LOG_FILENAME).getParentFile().mkdirs();
      StreamHandler handle =
          new StreamHandler(new FileOutputStream(LOG_FILENAME), new SimpleFormatter()) {
            @Override
            public boolean isLoggable(LogRecord record) {
              return true; // record.getLevel() == ENLevels.ERROR;
            }

            @Override
            public void publish(LogRecord record) {
              super.publish(record);
            }
          };

      log.addHandler(handle);

    } catch (IOException e) {

    }
  }
Ejemplo n.º 10
0
  /** Creates a new LogClass instance with its own FileHandler. */
  public LogClass() {
    // name = empty String: RootLogger, also logs messages from MobilisServer
    // should only be on top of the XHuntService Logger hierarchy
    mLogger = Logger.getLogger("de.tudresden.inf.rn.mobilis.services.xhunt");
    mLogger.setLevel(Level.INFO);
    mLogger.setUseParentHandlers(false);

    String os = System.getProperty("os.name").toLowerCase();

    if (os.contains("win")) {
      if (new File("E:/").exists()) logFolder = new File("E:/XHuntServiceLogs");
      else logFolder = new File("C:/XHuntServiceLogs");
    } else {
      logFolder = new File("logs/XHuntServiceLogs");
    }

    if (!logFolder.isDirectory()) {
      try {
        logFolder.mkdirs();
      } catch (SecurityException e) {
        e.printStackTrace();
      }
    }

    deleteOlderLogs(14);
    initializeHandler(200);
  }
 @BeforeClass
 public static void setUp() {
   Logger logger = NanoBench.getLogger();
   logger.setUseParentHandlers(false);
   logger.setLevel(Level.INFO);
   logger.addHandler(new ConsoleHandler());
 }
Ejemplo n.º 12
0
 /** Configure CB4J logger. */
 private void configureCB4JLogger() {
   logger.setUseParentHandlers(false);
   ConsoleHandler consoleHandler = new ConsoleHandler();
   consoleHandler.setFormatter(new LogFormatter());
   if (logger.getHandlers().length == 0) {
     logger.addHandler(consoleHandler);
   }
 }
Ejemplo n.º 13
0
 public static Logger newLogger(String callingClassName) {
   Logger instance = Logger.getLogger(callingClassName);
   instance.setLevel(Level.CONFIG);
   Handler handler = new ConsoleHandler();
   instance.addHandler(handler);
   instance.setUseParentHandlers(false);
   return instance;
 }
 public void setup() throws IOException {
   LOGGER.setLevel(Level.INFO);
   fileTxt = new FileHandler(ContextManager.getSuccessloggerFile(), true);
   simpleTextFormatter = new SimpleTextFormatter();
   fileTxt.setFormatter(simpleTextFormatter);
   LOGGER.addHandler(fileTxt);
   LOGGER.setUseParentHandlers(false);
 }
  public static Logger getLogger(String className) {
    Logger logger = Logger.getLogger(className);

    logger.setUseParentHandlers(false);
    logger.addHandler(fileHandler);
    logger.setLevel(Constants.getLogLevel());

    return logger;
  }
Ejemplo n.º 16
0
 public static void main(String[] args) {
   String inputFilename = "";
   String version = "";
   for (int i = 0; i < args.length; i++) {
     if (args[i].equals("-i")) {
       if (i == args.length - 1) {
         printUsage();
         System.exit(3);
       }
       inputFilename = args[i + 1];
     }
     if (args[i].equals("-v")) {
       if (i == args.length - 1) {
         printUsage();
         System.exit(3);
       }
       version = args[i + 1];
     }
     if (args[i].equals("-h")) {
       printUsage();
       System.exit(0);
     }
   }
   LOGGER.setLevel(Level.CONFIG);
   LOGGER.setUseParentHandlers(false);
   ConsoleHandler logConsole = new ConsoleHandler();
   logConsole.setLevel(Level.CONFIG);
   LOGGER.addHandler(logConsole);
   MyLogFormatter formatter = new MyLogFormatter();
   logConsole.setFormatter(formatter);
   /*
   try {
   	FileHandler logFile = new FileHandler("serverwiz2.%u.%g.log",20000,2,true);
   	LOGGER.addHandler(logFile);
   	logFile.setFormatter(formatter);
   	logFile.setLevel(Level.CONFIG);
   } catch (IOException e) {
   	System.err.println("Unable to create logfile");
   	System.exit(3);
   }
   */
   LOGGER.config("======================================================================");
   LOGGER.config("ServerWiz2 Starting...");
   TargetWizardController tc = new TargetWizardController();
   SystemModel systemModel = new SystemModel();
   MainDialog view = new MainDialog(null);
   tc.setView(view);
   tc.setModel(systemModel);
   systemModel.addPropertyChangeListener(tc);
   view.setController(tc);
   if (!inputFilename.isEmpty()) {
     view.mrwFilename = inputFilename;
   }
   view.open();
   // d.dispose();
 }
Ejemplo n.º 17
0
  /** Creates a new file handler for writing log messages into {@value #UPGRADELOGNAME} file. */
  static void initLogFileHandler() {
    final Logger logger = Logger.getLogger(UpgradeLog.class.getPackage().getName());

    final String SPACE = " ";

    if (logFile == null) {
      logFile =
          new File(
              UpgradeUtils.getInstancePath()
                  + File.separator
                  + Installation.LOGS_PATH_RELATIVE
                  + File.separator
                  + UPGRADELOGNAME);
    }
    try {
      fileHandler = new FileHandler(logFile.getCanonicalPath(), true);
    } catch (IOException e) {
      logger.severe(e.getMessage());
    }
    fileHandler.setFormatter(
        new Formatter() {
          /** {@inheritDoc} */
          @Override
          public String format(LogRecord record) {
            // Format the log ~like the errors logger.
            StringBuilder sb = new StringBuilder();
            final SimpleDateFormat dateFormat = new SimpleDateFormat("[dd/MMM/yyyy:HH:mm:ss Z]");
            sb.append(dateFormat.format(record.getMillis())).append(SPACE);
            sb.append("category=UPGRADE")
                .append(SPACE)
                .append("sq=")
                .append(record.getSequenceNumber())
                .append(SPACE)
                .append("severity=")
                .append(record.getLevel().toString().toUpperCase());
            sb.append(SPACE)
                .append("src=")
                .append(record.getSourceClassName())
                .append(SPACE)
                .append(record.getSourceMethodName())
                .append(LINE_SEPARATOR);
            sb.append(SPACE).append("msg=").append(record.getMessage()).append(LINE_SEPARATOR);
            return sb.toString();
          }
        });
    logger.setLevel(Level.ALL);
    logger.addHandler(fileHandler);

    logger.setUseParentHandlers(false);
    // Log Config info.
    logger.info("**** Upgrade of OpenDJ started ****");
    logger.info(
        RuntimeMessages.NOTE_INSTALL_DIRECTORY.get(UpgradeUtils.getInstallationPath()).toString());
    logger.info(
        RuntimeMessages.NOTE_INSTANCE_DIRECTORY.get(UpgradeUtils.getInstancePath()).toString());
  }
Ejemplo n.º 18
0
 private static final Logger createLogger() {
   final Logger logger = Logger.getLogger(Log.class.getName());
   logger.setLevel(Level.INFO);
   final ConsoleHandler ch = new ConsoleHandler();
   ch.setLevel(Level.ALL);
   ch.setFormatter(new LogFormatter());
   logger.addHandler(ch);
   logger.setUseParentHandlers(false);
   return logger;
 }
Ejemplo n.º 19
0
  // Use custom string format for logger.
  public static Logger setLogger(Logger logger) {
    ShortFormatter formatter = new ShortFormatter();
    ConsoleHandler handler = new ConsoleHandler();

    logger.setUseParentHandlers(false);
    handler.setFormatter(formatter);
    logger.addHandler(handler);

    return logger;
  }
Ejemplo n.º 20
0
 static {
   if ((System.getProperty("java.util.logging.config.file") == null)
       && (System.getProperty("java.util.logging.config.class") == null)) {
     LOGGER.setUseParentHandlers(false);
     final Handler handler = new ConsoleHandler();
     handler.setFormatter(new PlainFormatter());
     addOrSetHandler(handler);
     LOGGER.setLevel(Level.INFO);
     handler.setLevel(Level.ALL);
   }
 }
Ejemplo n.º 21
0
 static {
   /*
    * Create a Logger just for the launcher that only uses
    * the Handlers we set up.  This makes sure that when
    * we change the log level for the Handler, we don't
    * interfere with subsequent use of the Logger by
    * asadmin.
    */
   logger = Logger.getLogger(LOGGER_NAME, SHARED_LOGMESSAGE_RESOURCE);
   logger.setLevel(Level.INFO);
   logger.setUseParentHandlers(false);
   logger.addHandler(new ConsoleHandler());
 }
  public static Logger getLogger(String className) {

    Logger logger = null;

    try {
      logger = Logger.getLogger(className);
      logger.addHandler(consoleHandler);
      logger.setUseParentHandlers(false);
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    return logger;
  }
Ejemplo n.º 23
0
 private static void initLogger() {
   try {
     File logFile = new File(DATA_SOURCE + "log.log");
     FileHandler fileHandler = new FileHandler(logFile.getCanonicalPath(), true);
     fileHandler.setFormatter(new LogFormatter());
     LOG.addHandler(fileHandler);
     LOG.addHandler(new ConsoleHandler());
     LOG.setLevel(Level.INFO);
     LOG.setUseParentHandlers(false);
   } catch (IOException e) {
     System.err.println("ERROR: Setting the logger failed!");
     throw new ServiceFailureException("Setting the logger failed!");
   }
 }
Ejemplo n.º 24
0
  @SuppressWarnings("unused")
  private void InitializeLogger() {
    logger = Logger.getLogger(getClass().getName());

    // remove root handlers and disable any references to root handlers
    logger.setUseParentHandlers(false);
    Logger globalLogger = Logger.getLogger("global");
    Handler[] handlers = globalLogger.getHandlers();
    for (Handler handler : handlers) {
      globalLogger.removeHandler(handler);
    }

    // add handlers
    try {
      fileHandler = new FileHandler(logFile, 10000, 1);
    } catch (SecurityException e1) {
      System.out.println("FileHandler SecurityException!");
      e1.printStackTrace();
    } catch (IOException e1) {
      System.out.println("FileHandler IOException!");
      e1.printStackTrace();
    }
    try {
      fileHandler.setEncoding("UTF8");
    } catch (SecurityException e1) {
      System.out.println("setEncoding SecurityException!");
      e1.printStackTrace();
    } catch (UnsupportedEncodingException e1) {
      System.out.println("setEncoding IOException!");
      e1.printStackTrace();
    }
    logger.addHandler(fileHandler);

    logger.addHandler(fileHandler);

    if (Debug && Explanation) {
      logLevel = Level.FINEST;
    } else if (Debug && !Explanation) {
      logLevel = Level.FINE;
    } else if (!Debug && Explanation) {
      logLevel = Level.INFO;
    } else if (!Debug && !Explanation) {
      logLevel = Level.SEVERE;
    }

    // set level and formatter
    logger.setLevel(logLevel);
    OysterExplanationFormatter formatter = new OysterExplanationFormatter();
    fileHandler.setFormatter(formatter);
  }
Ejemplo n.º 25
0
 void initialize() {
   // set this as a top level logger, to control console level
   logger = Logger.getLogger("com.jaivox.util.Log");
   logger.setUseParentHandlers(false);
   Handler hConsole = new ConsoleHandler();
   hConsole.setFormatter(new Logformat());
   hConsole.setLevel(Level.FINEST);
   logger.addHandler(hConsole);
   logger.setLevel(Level.FINEST);
   // what is the level of this logger?
   String s = logger.getLevel().toString();
   System.out.println("Logger log level after creating " + s);
   initialized = true;
 }
Ejemplo n.º 26
0
  public Debug(String target) {
    Properties prop = new Properties();
    InputStream input = null;

    try {
      String configProp =
          System.getProperty("config") == null ? "default" : System.getProperty("config");
      input =
          new FileInputStream(
              System.getProperty("user.dir") + "/../config/" + configProp + ".properties");
      prop.load(input);

      debug = Boolean.valueOf(prop.getProperty("debug"));
      logDir = prop.getProperty("logDir");
      logFile = prop.getProperty("logFile");
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      if (input != null) {
        try {
          input.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }

    logger = Logger.getLogger(target);
    try {
      File file = new File(logDir);
      if (!file.exists()) {
        if (file.mkdir()) {
          System.out.println("Log Directory is created!");
        } else {
          System.out.println("Failed to create log directory!");
        }
      }
      fh = new FileHandler(logDir + "/" + logFile, true);
      logger.addHandler(fh);
      logger.setUseParentHandlers(false);
      // this one disables the console log
      SimpleFormatter formatter = new SimpleFormatter();
      fh.setFormatter(formatter);
    } catch (SecurityException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 27
0
  protected static Logger setupLogger() {
    final Logger logger = Utils.getLogger();
    File logDirectory = new File(Utils.getLauncherDirectory(), "logs");
    if (!logDirectory.exists()) {
      logDirectory.mkdir();
    }
    File logs = new File(logDirectory, "lovelauncher_%D.log");
    RotatingFileHandler fileHandler = new RotatingFileHandler(logs.getPath());

    fileHandler.setFormatter(new TechnicLogFormatter());

    for (Handler h : logger.getHandlers()) {
      logger.removeHandler(h);
    }
    logger.addHandler(fileHandler);

    SpoutcraftLauncher.handler = fileHandler;

    if (params != null && !params.isDebugMode()) {
      logger.setUseParentHandlers(false);

      System.setOut(new PrintStream(new LoggerOutputStream(console, Level.INFO, logger), true));
      System.setErr(new PrintStream(new LoggerOutputStream(console, Level.SEVERE, logger), true));
    }

    Thread.setDefaultUncaughtExceptionHandler(
        new Thread.UncaughtExceptionHandler() {
          @Override
          public void uncaughtException(Thread t, Throwable e) {
            logger.log(Level.SEVERE, "Unhandled Exception in " + t, e);

            if (errorDialog == null) {
              LauncherFrame frame = null;

              try {
                frame = Launcher.getFrame();
              } catch (Exception ex) {
                // This can happen if we have a very early crash- before Launcher initializes
              }

              errorDialog = new ErrorDialog(frame, e);
              errorDialog.setVisible(true);
            }
          }
        });

    return logger;
  }
Ejemplo n.º 28
0
 static {
   // set up logger when AtomicWords is statically initialized
   logger.setUseParentHandlers(false);
   ConsoleHandler consoleHandler = new ConsoleHandler();
   consoleHandler.setLevel(Level.SEVERE);
   logger.addHandler(consoleHandler);
   try {
     FileHandler fileHandler = new FileHandler("atomic-words%u.log");
     fileHandler.setLevel(Level.INFO);
     fileHandler.setFormatter(new SimpleFormatter());
     logger.addHandler(fileHandler);
   } catch (IOException e) {
     logger.log(Level.SEVERE, "Can not open log file, file logging disabled!", e);
   }
   logger.fine("Finished setting up logger");
 }
Ejemplo n.º 29
0
  static { // Setup logging file
    try {
      fh = new FileHandler("debug.log", false);
      CloseLogger ch = new CloseLogger(fh);
      Thread t = new Thread(ch);
      Runtime.getRuntime().addShutdownHook(t);

    } catch (SecurityException e) {
      System.err.println(e.getMessage());
    } catch (IOException e) {
      System.err.println(e.getMessage());
    }
    fh.setFormatter(new SimpleFormatter());
    debugLog.addHandler(fh);
    debugLog.setUseParentHandlers(false); // do not use default outputs (console and such)
  }
Ejemplo n.º 30
0
  public static Logger newLogger(String callingClassName, String level) {
    final String[] LEVELS = {"sever", "warning", "info", "config", "fine", "finer", "finest"};
    Logger instance = newLogger(callingClassName);
    instance.setUseParentHandlers(false);

    int i = -1;
    boolean isValid = false;
    for (String str : LEVELS) {
      i++;
      if (level.equals(str)) {
        isValid = true;
        break;
      }
    }
    if (isValid) {
      switch (i) {
        case 0:
          instance.setLevel(Level.SEVERE);
          break;
        case 1:
          instance.setLevel(Level.WARNING);
          break;
        case 2:
          instance.setLevel(Level.INFO);
          break;
        case 3:
          instance.setLevel(Level.CONFIG);
          break;
        case 4:
          instance.setLevel(Level.FINE);
          break;
        case 5:
          instance.setLevel(Level.FINER);
          break;
        case 6:
          instance.setLevel(Level.FINEST);
          break;
        case 7:
          instance.setLevel(Level.ALL);
          break;
        default:
          System.out.println("Invalid level selection");
          return null;
      }
    }
    return instance;
  }