/** 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);
   }
 }
 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();
 }
Beispiel #3
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;
 }
Beispiel #4
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;
  }
  private final void initialize() {
    this.setLevel(Level.ALL);
    try {
      LoggerFormat lForm = new LoggerFormat();

      fhand = new FileHandler(ControlRoom.getAppData("vimcsl.%g.log"), 1966080, 5, true);
      fhand.setLevel(Level.ALL);
      fhand.setFormatter(lForm);
      this.addHandler(fhand);

      ConsoleHandler chand = new ConsoleHandler();
      chand.setLevel(Level.ALL);
      chand.setFormatter(lForm);
      this.addHandler(chand);
    } catch (IOException e) {
    }
  }
  public static void main(String[] args) throws IOException {
    for (Handler handler : LogManager.getLogManager().getLogger("").getHandlers()) {
      if (handler instanceof ConsoleHandler) {
        ConsoleHandler ch = (ConsoleHandler) handler;
        ch.setFormatter(new ShellFormatter());
        break;
      }
    }

    int commandPort = Integer.parseInt(args[0]);
    int[] ports = new int[args.length - 1];
    for (int i = 0; i < ports.length; i++) {
      ports[i] = Integer.parseInt(args[i + 1]);
    }

    new DeviceReversePortForwarder(commandPort, ports).run();
  }
Beispiel #7
0
  private static void initLogging() {
    log.setUseParentHandlers(false);

    for (Handler handler : log.getHandlers()) {
      log.removeHandler(handler);
    }

    ConsoleHandler console_handler = new ConsoleHandler();
    console_handler.setFormatter(new ConsoleFormatter());

    if (verbose) {
      console_handler.setLevel(Level.ALL);
    } else {
      console_handler.setLevel(Level.WARNING);
    }

    log.addHandler(console_handler);

    if (log_pattern != null) {
      FileHandler file_handler = null;

      try {
        file_handler = new FileHandler(log_pattern, 1000, 5);
        file_handler.setFormatter(new ConsoleFormatter());
      } catch (IOException ex) {
        log.log(Level.SEVERE, "I/O exception", ex);
        return;
      } catch (SecurityException ex) {
        log.log(Level.SEVERE, "Security exception", ex);
        return;
      }

      file_handler.setLevel(Level.WARNING);
      log.addHandler(file_handler);
    }

    LogManager.getLogManager().addLogger(log);
  }
Beispiel #8
0
  private void initLogger() {
    ConsoleHandler consoleHandler = null;

    Logger rootLogger = LogManager.getLogManager().getLogger("");
    Handler[] handlers = rootLogger.getHandlers();
    for (Handler handler : handlers) {
      if (handler instanceof ConsoleHandler) {
        consoleHandler = (ConsoleHandler) handler;
        rootLogger.removeHandler(handler);
      }
    }

    logger = Logger.getLogger(contextId);
    logger.setLevel(logLevel);
    if (!logLevel.equals(Level.OFF)) {
      LogFormatter formatter = new LogFormatter();
      if (consoleLog) {
        if (consoleHandler == null) {
          consoleHandler = new ConsoleHandler();
        }
        consoleHandler.setFormatter(formatter);
        consoleHandler.setLevel(logLevel);
        logger.addHandler(consoleHandler);
      }
      String userHomePath = getProperty("user.home", ".");
      File logDir = new File(userHomePath, '.' + contextId + "/log");
      logDir.mkdirs();
      String logFilePattern = new File(logDir, contextId + "-%g.log").getPath();
      try {
        FileHandler fileHandler = new FileHandler(logFilePattern);
        fileHandler.setFormatter(formatter);
        fileHandler.setLevel(logLevel);
        logger.addHandler(fileHandler);
      } catch (IOException e) {
        System.err.println("Error: Failed to create log file: " + logFilePattern);
      }
    }
  }
Beispiel #9
0
  /**
   * Initializes the FileHandler. For the name of the log file, a timestamp is used. When the file
   * reaches the size given as the parameter, writing restarts at the beginning of the file.
   *
   * @param maxFilesizeMB the maximum size allowed for the log file (in MB).
   */
  private void initializeHandler(int maxFilesizeMB) {

    if (logFolder.isDirectory()) {

      DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss-SSS");
      File logFile = new File(logFolder, formatter.format(new Date()) + ".txt");

      try {
        mFHandler =
            new FileHandler(logFile.getAbsolutePath(), 1024 * 1024 * maxFilesizeMB, 1, true);
        mFHandler.setFormatter(
            new SimpleFormatter() {
              @Override
              public String format(LogRecord record) {
                return super.format(record) + System.getProperty("line.separator");
              }
            });
        mFHandler.setLevel(Level.ALL);
        mLogger.addHandler(mFHandler);

      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    mCHandler = new ConsoleHandler();
    mCHandler.setFormatter(
        new SimpleFormatter() {
          @Override
          public String format(LogRecord record) {
            return super.format(record) + System.getProperty("line.separator");
          }
        });
    mCHandler.setLevel(Level.ALL);
    mLogger.addHandler(mCHandler);
  }
Beispiel #10
0
  public Logging(final TwitchClient client) {
    createLogDir();

    // Remove default handlers
    LogManager.getLogManager().reset();

    // Add console handler with custom formatter
    ConsoleHandler c = new ConsoleHandler();
    c.setFormatter(new TextFormatter());
    c.setFilter(
        new Filter() {

          @Override
          public boolean isLoggable(LogRecord record) {
            return record.getLevel() != USERINFO;
          }
        });
    Logger.getLogger("").addHandler(c);

    // Add file handler with custom formatter
    try {
      FileHandler file = new FileHandler(LOG_FILE, MAX_LOG_SIZE, MAX_LOG_FILES, true);
      file.setFormatter(new TextFormatter());
      file.setLevel(Level.INFO);
      file.setFilter(new FileFilter());
      Logger.getLogger("").addHandler(file);

      FileHandler fileSession = new FileHandler(LOG_FILE_SESSION, MAX_SESSION_LOG_SIZE, 1);
      fileSession.setFormatter(new TextFormatter());
      fileSession.setLevel(Level.INFO);
      fileSession.setFilter(new FileFilter());
      Logger.getLogger("").addHandler(fileSession);
    } catch (IOException | SecurityException ex) {
      Logger.getLogger(Logging.class.getName()).log(Level.WARNING, null, ex);
    }

    // Add handler for the GUI (display errors, log into debug window)
    Logger.getLogger("")
        .addHandler(
            new Handler() {

              @Override
              public void publish(LogRecord record) {
                if (record.getLevel() != USERINFO) {
                  client.debug(record.getMessage());
                  // WebsocketClient/WebsocketManager
                  if (record.getSourceClassName().startsWith("chatty.util.ffz.Websocket")) {
                    client.debugFFZ(record.getMessage());
                  }
                }
                if (record.getLevel() == Level.SEVERE) {
                  if (client.g != null) {
                    client.g.error(record, lastMessages.getItems());
                  }
                } else if (record.getLevel() == USERINFO) {
                  client.warning(record.getMessage());
                } else {
                  lastMessages.add(record);
                }
              }

              @Override
              public void flush() {}

              @Override
              public void close() throws SecurityException {}
            });
  }
Beispiel #11
0
  /**
   * Causes the classloader to run the static initiliasre block above Negates need for
   * Class.forName();
   */
  public static void initialise(Configuration config) {
    try {
      System.out.println("Initialising SystemManager");
      SystemManager.SYSTEMCHANGELISTENER = new SystemConfigChangeListener();
      String[] GROUPS =
          (String[]) config.getEntry("org.jini.projects.athena", "groups", String[].class);
      ldm = new LookupDiscoveryManager(GROUPS, null, null, config);
      sdm = new ServiceDiscoveryManager(ldm, null, config);
      ServiceTemplate temp = new ServiceTemplate(null, new Class[] {ErosService.class}, null);

      ServiceItem svc = sdm.lookup(temp, new ErosFilter(), 3000);
      if (svc != null) {
        if (svc.service != null && svc.service instanceof ErosService) {

          try {
            ProxyPreparer preparer =
                (ProxyPreparer)
                    config.getEntry(
                        "org.jini.projects.athena",
                        "proxyPreparer",
                        ProxyPreparer.class,
                        new BasicProxyPreparer());
            eros = (ErosService) preparer.prepareProxy(svc.service);
            eLogger = eros.getLogger();
            eLogger.initialise("Athena");
            logHandler = (Handler) eLogger.getLoggingHandler();

            int Kb = 1024;
            FileHandler fhandler = new FileHandler("logs/athena", 500 * Kb, 40);
            fhandler.setFormatter(new LogFormatter());

            String consoleLogLevel =
                (String)
                    config.getEntry("org.jini.projects.athena", "consoleLogLevel", String.class);
            String fileLogLevel =
                (String) config.getEntry("org.jini.projects.athena", "fileLogLevel", String.class);
            stdLogger = java.util.logging.Logger.getLogger("org.jini.projects.athena");
            stdLogger.setLevel(Level.parse(fileLogLevel));

            stdLogger.setUseParentHandlers(false);
            fhandler.setLevel(Level.parse(fileLogLevel));
            logHandler.setLevel(Level.parse(consoleLogLevel));
            stdLogger.addHandler(fhandler);
            stdLogger.addHandler(logHandler);
            stdLogger.info("Eros Logging enabled");

          } catch (RemoteException e) {
            System.err.println("Exception occured whilst interacting with Eros");
            e.printStackTrace();
          } catch (SecurityException e) {
            System.err.println("Security Exception occured whilst interacting with Eros");
            e.printStackTrace();
          } catch (Exception e) {
            System.err.println("Exception occured whilst interacting with Eros");
            e.printStackTrace();
          }
        }
      } else {
        System.out.println("Eros could not be found....default logging will be provided");
        int Kb = 1024;
        File logDir = new File("logs");
        if (!logDir.exists()) logDir.mkdir();
        FileHandler fhandler = new FileHandler("logs/athena", 500 * Kb, 40);
        fhandler.setFormatter(new LogFormatter());

        String consoleLogLevel =
            (String) config.getEntry("org.jini.projects.athena", "consoleLogLevel", String.class);
        String fileLogLevel =
            (String) config.getEntry("org.jini.projects.athena", "fileLogLevel", String.class);
        stdLogger = java.util.logging.Logger.getLogger("org.jini.projects.athena");
        stdLogger.setLevel(Level.parse(fileLogLevel));

        ConsoleHandler logHandler = new ConsoleHandler();
        logHandler.setFormatter(new LogFormatter());
        stdLogger.setUseParentHandlers(false);
        fhandler.setLevel(Level.parse(fileLogLevel));
        logHandler.setLevel(Level.parse(consoleLogLevel));
        stdLogger.addHandler(fhandler);
        stdLogger.addHandler(logHandler);
      }
    } catch (IOException e) {
      System.out.println("System cannot perform lookup for Eros");
      e.printStackTrace();
    } catch (Exception e) {
      System.out.println("System cannot perform lookup for Eros");
      e.printStackTrace();
    }
    stdLogger.info("Initialised SystemManager");
  }
Beispiel #12
0
  REplican(String arguments[]) {
    JCLO jclo = new JCLO(args);

    if (arguments.length == 0) {
      System.out.println("Arguments:\n" + jclo.usage() + "URLs...");
      System.exit(1);
    }

    try {
      jclo.parse(arguments);
    } catch (IllegalArgumentException IAE) {
      System.err.println(IAE);
      System.err.println("Arguments:\n" + jclo.usage() + "URLs...");
      System.exit(0);
    }

    String logLevel = args.LogLevel;
    ConsoleHandler ch = new ConsoleHandler();

    if (logLevel != null) {
      Level level = JavaLN.getLevel(logLevel);
      ch.setLevel(level);
      ch.setFormatter(new LineNumberFormatter());
      logger.setLevel(level);
    } else {
      ch.setFormatter(new NullFormatter());
    }

    logger.addHandler(ch);
    logger.setUseParentHandlers(false);

    if (args.Version) {
      System.out.println(Version.getVersion());
      System.exit(0);
    }

    if (args.Help) {
      System.out.println("Arguments:\n" + jclo.usage() + "URLs...");
      System.exit(0);
    }

    cookies = new Cookies();

    setDefaults();

    if (args.LoadCookies != null) {
      for (int i = 0; i < args.LoadCookies.length; i++) {
        logger.config("Loading cookies from " + args.LoadCookies[i]);
        cookies.loadCookies(args.LoadCookies[i]);
      }
    }

    if (args.PlistCookies != null) {
      for (int i = 0; i < args.PlistCookies.length; i++) {
        logger.config("Loading cookies from " + args.PlistCookies[i]);
        new Plist("file:" + args.PlistCookies[i], cookies);
      }
    }

    if (args.CheckpointEvery != 0) {
      logger.config("Loading urls from " + args.CheckpointFile);

      try {
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream(args.CheckpointFile));
        urls = (Hashtable) ois.readObject();
        ois.close();
      } catch (IOException ioe) {
        logger.throwing(ioe);
      } catch (ClassNotFoundException cnfe) {
        logger.throwing(cnfe);
      }
    }

    if (args.FollowRedirects) HttpURLConnection.setFollowRedirects(false);
  }