Esempio n. 1
1
  public ConsoleManager(GlowServer server) {
    this.server = server;

    // install Ansi code handler, which makes colors work on Windows
    AnsiConsole.systemInstall();

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

    // used until/unless gui is created
    consoleHandler = new FancyConsoleHandler();
    // consoleHandler.setFormatter(new DateOutputFormatter(CONSOLE_DATE));
    logger.addHandler(consoleHandler);

    // todo: why is this here?
    Runtime.getRuntime().addShutdownHook(new ServerShutdownThread());

    // reader must be initialized before standard streams are changed
    try {
      reader = new ConsoleReader();
    } catch (IOException ex) {
      logger.log(Level.SEVERE, "Exception initializing console reader", ex);
    }
    reader.addCompleter(new CommandCompleter());

    // set system output streams
    System.setOut(new PrintStream(new LoggerOutputStream(Level.INFO), true));
    System.setErr(new PrintStream(new LoggerOutputStream(Level.WARNING), true));
  }
Esempio n. 2
0
  public static synchronized void createLoggers(boolean reinit) {

    if (m_initialized == true && reinit == false) {
      return;
    }

    if (!m_initialized) {
      Logger.getLogger("").removeHandler(Logger.getLogger("").getHandlers()[0]);
    }

    if (m_initialized) {
      m_severeLogger.removeHandler(m_severeLogger.getHandlers()[0]);
      m_nonSevereLogger.removeHandler(m_nonSevereLogger.getHandlers()[0]);
    }

    Handler severeHandler = new AMyConsoleHandler(System.err);
    severeHandler.setFormatter(new SingleLineFormatter());
    m_severeLogger.addHandler(severeHandler);
    m_severeLogger.setLevel(getLoggingLevel());

    Handler nonSevereHandler = new AMyConsoleHandler(System.out);
    nonSevereHandler.setFormatter(new SingleLineFormatter());
    m_nonSevereLogger.addHandler(nonSevereHandler);
    m_nonSevereLogger.setLevel(getLoggingLevel());

    m_initialized = true;
  }
Esempio n. 3
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();
    }
  }
  @Test
  public void testCMSAdaptiveSizePolicyPrintHeapAtGC() throws Exception {
    TestLogHandler handler = new TestLogHandler();
    handler.setLevel(Level.WARNING);
    IMP_LOGGER.addHandler(handler);
    DATA_READER_FACTORY_LOGGER.addHandler(handler);

    ByteArrayInputStream in =
        new ByteArrayInputStream(
            ("2012-04-18T14:48:31.855+0200: 29.592: [GC 29.592: [ASParNew: 52825K->6499K(59008K), 0.0268761 secs] 120805K->120749K(517760K), 0.0269605 secs] [Times: user=0.05 sys=0.00, real=0.03 secs]"
                    + "\nHeap"
                    + "\nadaptive size par new generation total 59008K, used 15368K [0x00000000d8000000, 0x00000000dc000000, 0x00000000dc000000)"
                    + "\n eden space 52480K,  16% used [0x00000000d8000000, 0x00000000d88a95a0, 0x00000000db340000)"
                    + "\n from space 6528K,  99% used [0x00000000db340000, 0x00000000db998cb0, 0x00000000db9a0000)"
                    + "\n to   space 6528K,   0% used [0x00000000db9a0000, 0x00000000db9a0000, 0x00000000dc000000)"
                    + "\nconcurrent mark-sweep generation total 458752K, used 259541K [0x00000000dc000000, 0x00000000f8000000, 0x00000000f8000000)"
                    + "\nconcurrent-mark-sweep perm gen total 65536K, used 2621K [0x00000000f8000000, 0x00000000fc000000, 0x0000000100000000)")
                .getBytes());
    final DataReader reader = new DataReaderSun1_6_0(in, GcLogType.SUN1_6);
    GCModel model = reader.read();

    assertEquals("GC count", 1, model.size());
    assertEquals("GC pause", 0.0269605, model.getGCPause().getMin(), 0.000000001);
    assertEquals("number of errors", 0, handler.getCount());
  }
Esempio n. 5
0
  public void handleInit(QuickServer quickserver) throws Exception {
    Logger logger = null;
    FileHandler xmlLog = null;
    File log = new File("./log/");
    if (!log.canRead()) log.mkdir();
    try {
      logger = Logger.getLogger("");
      logger.setLevel(Level.FINEST);

      logger = Logger.getLogger("org.quickserver.net.qsadmin");
      xmlLog = new FileHandler("log/FtpServer_QSAdmin%u%g.xml", 1024 * 1024, 20, true);
      xmlLog.setLevel(Level.FINEST);
      logger.addHandler(xmlLog);

      logger = Logger.getLogger("org.quickserver");
      xmlLog = new FileHandler("log/FtpServer_QuickServer%u%g.xml", 1024 * 1024, 20, true);
      xmlLog.setLevel(Level.FINEST);
      logger.addHandler(xmlLog);

      logger = Logger.getLogger("ftpserver");
      xmlLog = new FileHandler("log/FtpServer%u%g.xml", 1024 * 1024, 20, true);
      xmlLog.setLevel(Level.FINEST);
      logger.addHandler(xmlLog);

      quickserver.setAppLogger(logger); // img
    } catch (IOException e) {
      System.err.println("Could not create txtLog FileHandler : " + e);
      throw e;
    }
  }
  /**
   * Test parsing of a malformed type. The test just expects an INFO to be logged - nothing else.
   */
  @Test
  public void testMalformedType() throws Exception {
    TestLogHandler handler = new TestLogHandler();
    handler.setLevel(Level.INFO);
    IMP_LOGGER.addHandler(handler);
    DATA_READER_FACTORY_LOGGER.addHandler(handler);

    ByteArrayInputStream in =
        new ByteArrayInputStream(
            ("[memory ][Thu Feb 21 15:06:38 2013][11844] 6.290-6.424: GC-malformed 3128161K->296406K (3145728K), sum of pauses 59.084 ms")
                .getBytes());

    DataReader reader = new DataReaderJRockit1_5_0(in);
    reader.read();

    // 3 INFO events:
    // Reading JRockit ... format
    // Failed to determine type ...
    // Reading done.
    assertEquals("number of infos", 3, handler.getCount());

    List<LogRecord> logRecords = handler.getLogRecords();
    assertEquals(
        "should start with 'Failed to determine type'",
        0,
        logRecords.get(1).getMessage().indexOf("Failed to determine type"));
  }
  /**
   * 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);
    }
  }
 // init logger
 public CommandParser() {
   try {
     FileHandler fileHandler = new FileHandler(LOGGERNAME);
     logger.addHandler(fileHandler);
     SimpleFormatter formatter = new SimpleFormatter();
     fileHandler.setFormatter(formatter);
     logger.addHandler(fileHandler);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Esempio n. 9
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);
  }
Esempio n. 10
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);
  }
Esempio n. 11
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);
  }
 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!");
   }
 }
Esempio n. 13
0
  @Test
  public void testPrintHeapAtGC() throws Exception {
    TestLogHandler handler = new TestLogHandler();
    handler.setLevel(Level.WARNING);
    IMP_LOGGER.addHandler(handler);
    DATA_READER_FACTORY_LOGGER.addHandler(handler);

    final InputStream in = getClass().getResourceAsStream("SampleSun1_6_0PrintHeapAtGC.txt");
    final DataReader reader = new DataReaderSun1_6_0(in, GcLogType.SUN1_6);
    GCModel model = reader.read();

    assertEquals("GC count", 2, model.size());
    assertEquals("GC pause", 0.0134287, model.getGCPause().getMin(), 0.000000001);
    assertEquals("number of errors", 0, handler.getCount());
  }
 {
   logger.setUseParentHandlers(false);
   logger.setLevel(Level.INFO);
   ConsoleHandler handler = new ConsoleHandler();
   handler.setLevel(Level.INFO);
   logger.addHandler(handler);
 }
Esempio n. 15
0
  public void testReset() throws SecurityException, IOException {
    // mock LogManager
    mockManager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
    assertNotNull(mockManager.getProperty("handlers"));
    Logger foo = new MockLogger(FOO, null);
    assertNull(foo.getLevel());
    assertEquals(0, foo.getHandlers().length);
    foo.setLevel(Level.ALL);
    foo.addHandler(new ConsoleHandler());
    assertTrue(mockManager.addLogger(foo));
    assertEquals(Level.WARNING, foo.getLevel());
    assertEquals(2, foo.getHandlers().length);

    // reset
    mockManager.reset();

    // properties is cleared
    assertNull(mockManager.getProperty("handlers"));

    // level is null
    assertNull(foo.getLevel());
    // handlers are all closed
    assertEquals(0, foo.getHandlers().length);

    // for root logger
    manager.reset();
    assertNull(manager.getProperty("handlers"));
    Logger root = manager.getLogger("");
    // level reset to info
    assertEquals(Level.INFO, root.getLevel());
    // also close root's handler
    assertEquals(0, root.getHandlers().length);
  }
Esempio n. 16
0
  @Command(
      aliases = {"reload"},
      desc = "Reload WorldGuard configuration",
      max = 0)
  @CommandPermissions({"worldguard.reload"})
  public void reload(CommandContext args, CommandSender sender) throws CommandException {

    LoggerToChatHandler handler = null;
    Logger minecraftLogger = null;

    if (sender instanceof Player) {
      handler = new LoggerToChatHandler(sender);
      handler.setLevel(Level.ALL);
      minecraftLogger = Logger.getLogger("Minecraft");
      minecraftLogger.addHandler(handler);
    }

    try {
      plugin.getGlobalStateManager().unload();
      plugin.getGlobalRegionManager().unload();
      plugin.getGlobalStateManager().load();
      plugin.getGlobalRegionManager().preload();
      WGBukkit.cleanCache();
      sender.sendMessage("WorldGuard configuration reloaded.");
    } catch (Throwable t) {
      sender.sendMessage("Error while reloading: " + t.getMessage());
    } finally {
      if (minecraftLogger != null) {
        minecraftLogger.removeHandler(handler);
      }
    }
  }
Esempio n. 17
0
  void initLogger() {
    final boolean VERBOSE_LOGGING = true;
    final int LOG_SIZE = 512 * 1024; // max log file size (in bytes)

    Logger globalLogger = Logger.getLogger("");
    // Logger logger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); // doesn't work on os x
    if (VERBOSE_LOGGING) {
      globalLogger.setLevel(Level.INFO);
    } else {
      globalLogger.setLevel(Level.WARNING);
    }

    // enable logging to file
    try {
      // settings is writable for built-in modes, mode folder is not writable
      File logFolder = Base.getSettingsFile("debug");
      if (!logFolder.exists()) {
        logFolder.mkdir();
      }
      File logFile = new File(logFolder, "DebugMode.%g.log");
      Handler handler = new FileHandler(logFile.getAbsolutePath(), LOG_SIZE, 10, false);
      globalLogger.addHandler(handler);

    } catch (IOException ex) {
      Logger.getLogger(JavaMode.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
      Logger.getLogger(JavaMode.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
  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);
  }
Esempio n. 19
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;
 }
Esempio n. 20
0
  private synchronized void enterSimulationLog(int simulationID) {
    exitSimulationLog();

    if (rootFileHandler != null) {
      LogFormatter.separator(log, Level.FINE, "Entering log for simulation " + simulationID);
      try {
        Logger root = Logger.getLogger("");
        String name = logSimPrefix + "_SIM_" + simulationID + ".log";
        simLogHandler = new FileHandler(name, true);
        simLogHandler.setFormatter(formatter);
        simLogHandler.setLevel(rootFileHandler.getLevel());
        simLogName = name;
        root.addHandler(simLogHandler);
        root.removeHandler(rootFileHandler);
        LogFormatter.separator(
            log,
            Level.FINE,
            "Log for simulation "
                + simulationID
                + " at "
                + serverHost
                + ':'
                + serverPort
                + " started");
      } catch (Exception e) {
        log.log(Level.SEVERE, "could not open log file for simulation " + simulationID, e);
      }
    }
  }
Esempio n. 21
0
 @Override
 public void close() {
   Logger l = this.logger;
   if (getLevel() != Level.OFF && l != null) {
     l.addHandler(this);
   }
 }
  /** Construct a new BasicWMSRenderer */
  public BasicWMSRenderer2() {
    ClassLoader current = Thread.currentThread().getContextClassLoader();
    try {
      Thread.currentThread().setContextClassLoader(WebMapServer.class.getClassLoader());
      Logger logger = Logger.getLogger("org.geotools.data.ows"); // $NON-NLS-1$
      if (WMSPlugin.isDebugging(Trace.RENDER)) {
        logger.setLevel(Level.FINE);
        logger.addHandler(
            new Handler() {

              @Override
              public void publish(LogRecord record) {
                System.err.println(record.getMessage());
              }

              @Override
              public void flush() {
                System.err.flush();
              }

              @Override
              public void close() throws SecurityException {}
            });
      } else {
        logger.setLevel(Level.SEVERE);
      }
    } finally {
      Thread.currentThread().setContextClassLoader(current);
    }
  }
Esempio n. 23
0
  private UnexpectedErrorLogger() throws SecurityException, IOException {
    handler = new FileHandler("UnexpecterErrorLogger");
    formatter = new SimpleFormatter();

    handler.setFormatter(formatter);
    logger.addHandler(handler);
  }
Esempio n. 24
0
  /** Sets the level and the handler of the root-logger. */
  private void configLogger() {
    Logger rootLogger = Logger.getLogger("");
    rootLogger.setLevel(Level.FINE);
    rootLogger.addHandler(LogHandler.get());

    GWT.setUncaughtExceptionHandler(this);
  }
Esempio n. 25
0
  private void setupLogging() throws IOException {
    System.out.println("Setting up logging...");
    Level level = LogHelper.getLogLevel(m_testData.getLogLevel());
    if (level == null) {
      System.err.println("No such log level and will use Level.INFO instead");
      level = Level.INFO;
    }
    fh = new FileHandler(m_testData.getLogFile(), false);
    // have to change the log level of the handler to let log come out as designed
    fh.setLevel(level);

    // change the formatter from default xml to simple text
    fh.setFormatter(new SimpleFormatter());
    theLogger.setLevel(level);
    theLogger.addHandler(fh);

    // close the Console handler so that we only need log in file
    Handler[] handlers = Logger.getLogger("").getHandlers();
    for (Handler handler : handlers) {
      if (handler instanceof ConsoleHandler) {
        handler.setLevel(Level.OFF);
        break;
      }
    }
  }
 @BeforeClass
 public static void setUp() {
   Logger logger = NanoBench.getLogger();
   logger.setUseParentHandlers(false);
   logger.setLevel(Level.INFO);
   logger.addHandler(new ConsoleHandler());
 }
Esempio n. 27
0
  @Test
  public void testServiceWithDSLLogger() throws Exception {
    final Logger logger = Logger.getLogger(BaseDslScript.class.getName());
    final DSLLoggerHandler handler = new DSLLoggerHandler();
    logger.addHandler(handler);

    final File dir = new File(TEST_PARSING_RESOURCE_BASE + "logger");
    final Service service = ServiceReader.getServiceFromDirectory(dir).getService();
    Assert.assertNotNull(service);

    Assert.assertTrue(
        "Println logger not found", handler.getMessages().contains("println logger call"));
    Assert.assertTrue(
        "Print logger not found", handler.getMessages().contains("print logger call"));
    Assert.assertTrue(
        "Class println not found", handler.getMessages().contains("Test Class println"));
    Assert.assertTrue("Class print not found", handler.getMessages().contains("Test Class print"));

    Assert.assertFalse(
        "preInstall event message appeared before expected",
        handler.getMessages().contains("This is the preInstall event"));

    final ExecutableDSLEntry preInstall = service.getLifecycle().getPreInstall();
    final ClosureExecutableEntry preInstallClosureEntry = (ClosureExecutableEntry) preInstall;
    preInstallClosureEntry.getCommand().call();

    Assert.assertTrue(
        "preInstall event message not found",
        handler.getMessages().contains("This is the preInstall event"));
  }
Esempio n. 28
0
 /**
  * Creates a fileLogger.
  *
  * @return A Logger named with 'id'.
  * @throws IOException
  * @throws SecurityException
  */
 public static Logger createFileLogger(String id, String filePattern, boolean append)
     throws SecurityException, IOException {
   Logger logger = Logger.getLogger(id);
   Handler handler = new FileHandler(filePattern, append);
   logger.addHandler(handler);
   return logger;
 }
Esempio n. 29
0
  /**
   * Writes log file when tweets sent.
   *
   * @param numberOfTweets Number of tweets sent
   * @param tweetedTrends Trends tweeted about
   */
  public void log(int numberOfTweets, String[] tweetedTrends) {

    String trends = "";

    for (String tweetedTrend : tweetedTrends) {
      if (tweetedTrend.equals("")) break;
      else trends += tweetedTrend + ", ";
    }

    if (!(trends.equals(""))) trends = trends.substring(0, trends.length() - 2) + ".";

    try {
      fh = new FileHandler(PATH_TO_LOG_FILE, LOG_FILE_SIZE_LIMIT, 1, true);
      logger.addHandler(fh);
      SimpleFormatter formatter = new SimpleFormatter();
      fh.setFormatter(formatter);

      if (numberOfTweets == 0) logger.warning("No tweets sent.");
      else logger.info("Tweets sent: " + numberOfTweets + ". Trends tweeted about: " + trends);

    } catch (SecurityException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Esempio n. 30
0
  public static void init() {
    try {
      DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH-mm-ss");
      Calendar cal = Calendar.getInstance();
      String fileName = "log " + dateFormat.format(cal.getTime()) + ".txt";

      File f = new File("logs");
      if (!f.exists()) f.mkdir();

      fh = new FileHandler("logs/" + fileName);

      logger = Logger.getLogger("MyLog");
      logger.addHandler(fh);
      SimpleFormatter formatter = new SimpleFormatter();
      fh.setFormatter(formatter);

      // Comment next line to make logger put into file everything from level INFO
      // Now it will log only errors (severe)
      logger.setLevel(Level.WARNING);

    } catch (SecurityException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }