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)); }
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; } }
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); }
public void startFile(String logfile) { File parent = new File(logfile).getParentFile(); if (!parent.isDirectory() && !parent.mkdirs()) { logger.warning("Could not create log folder: " + parent); } Handler fileHandler = new RotatingFileHandler(logfile); fileHandler.setFormatter(new DateOutputFormatter(FILE_DATE)); logger.addHandler(fileHandler); }
/** 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; }
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); } } }
public void startGui() { JTerminalListener listener = new JTerminalListener(); jFrame = new JFrame("Glowstone"); jTerminal = new JTerminal(); jInput = new JTextField(80) { @Override public void setBorder(Border border) {} }; jInput.paint(null); jInput.setFont(new Font("Monospaced", Font.PLAIN, 12)); jInput.setBackground(Color.BLACK); jInput.setForeground(Color.WHITE); jInput.setMargin(new Insets(0, 0, 0, 0)); jInput.addKeyListener(listener); JLabel caret = new JLabel("> "); caret.setFont(new Font("Monospaced", Font.PLAIN, 12)); caret.setForeground(Color.WHITE); JPanel ipanel = new JPanel(); ipanel.add(caret, BorderLayout.WEST); ipanel.add(jInput, BorderLayout.EAST); ipanel.setBorder(BorderFactory.createEmptyBorder()); ipanel.setBackground(Color.BLACK); ipanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); ipanel.setSize(jTerminal.getWidth(), ipanel.getHeight()); jFrame.getContentPane().add(jTerminal, BorderLayout.NORTH); jFrame.getContentPane().add(ipanel, BorderLayout.SOUTH); jFrame.addWindowListener(listener); jFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); jFrame.setLocationRelativeTo(null); jFrame.pack(); jFrame.setVisible(true); sender = new ColoredCommandSender(); logger.removeHandler(consoleHandler); logger.addHandler( new StreamHandler(new TerminalOutputStream(), new DateOutputFormatter(CONSOLE_DATE))); }
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); } // add log handler which writes to console logger.addHandler(new FancyConsoleHandler()); // 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)); // set up colorization replacements replacements.put( ChatColor.BLACK, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLACK).boldOff().toString()); replacements.put( ChatColor.DARK_BLUE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLUE).boldOff().toString()); replacements.put( ChatColor.DARK_GREEN, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.GREEN).boldOff().toString()); replacements.put( ChatColor.DARK_AQUA, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.CYAN).boldOff().toString()); replacements.put( ChatColor.DARK_RED, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.RED).boldOff().toString()); replacements.put( ChatColor.DARK_PURPLE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.MAGENTA).boldOff().toString()); replacements.put( ChatColor.GOLD, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.YELLOW).boldOff().toString()); replacements.put( ChatColor.GRAY, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.WHITE).boldOff().toString()); replacements.put( ChatColor.DARK_GRAY, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLACK).bold().toString()); replacements.put( ChatColor.BLUE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLUE).bold().toString()); replacements.put( ChatColor.GREEN, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.GREEN).bold().toString()); replacements.put( ChatColor.AQUA, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.CYAN).bold().toString()); replacements.put( ChatColor.RED, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.RED).bold().toString()); replacements.put( ChatColor.LIGHT_PURPLE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.MAGENTA).bold().toString()); replacements.put( ChatColor.YELLOW, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.YELLOW).bold().toString()); replacements.put( ChatColor.WHITE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.WHITE).bold().toString()); replacements.put(ChatColor.MAGIC, Ansi.ansi().a(Ansi.Attribute.BLINK_SLOW).toString()); replacements.put(ChatColor.BOLD, Ansi.ansi().a(Ansi.Attribute.UNDERLINE_DOUBLE).toString()); replacements.put( ChatColor.STRIKETHROUGH, Ansi.ansi().a(Ansi.Attribute.STRIKETHROUGH_ON).toString()); replacements.put(ChatColor.UNDERLINE, Ansi.ansi().a(Ansi.Attribute.UNDERLINE).toString()); replacements.put(ChatColor.ITALIC, Ansi.ansi().a(Ansi.Attribute.ITALIC).toString()); replacements.put(ChatColor.RESET, Ansi.ansi().a(Ansi.Attribute.RESET).toString()); }
public void addHandler(Handler h) { initializeGlobalHandlers(); super.addHandler(h); }
public static void main(String[] args) { log = Logger.getLogger(Main.class.getName()); try { // Setting up logging Logger packageLog = Logger.getLogger(ChatBot.class.getPackage().getName()); File logFile = new File(LOGFILE + ".log"); if (logFile.exists()) { Calendar cal = Calendar.getInstance(); File backup = new File( String.format( "%s_%d_%d_%d.log", LOGFILE, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH))); if (backup.exists()) try (BufferedReader reader = new BufferedReader(new FileReader(logFile)); PrintWriter writer = new PrintWriter(new FileWriter(backup, true))) { char buff[] = new char[1024]; int n; while ((n = reader.read(buff)) > 0) { writer.write(buff, 0, n); } log.info("Appened log to backup " + backup.getName()); } catch (IOException e) { log.log(Level.SEVERE, "Couldn't append log to " + backup.getName(), e); } else { try { FileUtils.moveFile(logFile, backup); log.info("Moved log to backup " + backup.getName()); } catch (IOException e) { log.log(Level.SEVERE, "Couldn't move log to " + backup.getName(), e); } } } //noinspection ResultOfMethodCallIgnored // logFile.delete(); Handler handler = new FileHandler(LOGFILE + ".log"); handler.setFormatter(new SimpleFormatter()); packageLog.setLevel(Level.FINE); packageLog.addHandler(handler); // Starting up XMPPCraft Main main = new Main(); PipeInputStream stdinPipe = new PipeInputStream(1048576); PipeOutputStream stdoutPipe = new PipeOutputStream(); main.init( System.in, new PipeOutputStream(stdinPipe), new PipeInputStream(stdoutPipe, 1048576)); System.setIn(stdinPipe); System.setOut(new PrintStream(new TeeOutputStream(System.out, stdoutPipe))); main.start(); // Starting up Minecraft MinecraftServer.main(args); // DummyMinecraftServer.main(args); } catch (KeyManagementException | NoSuchAlgorithmException | SmackException | XMPPException | IOException e) { String filename = String.format( "crashreport_%s_%s.log", e.getClass().getSimpleName(), new SimpleDateFormat("MM_dd.HH_mm").format(new Date())); File f = new File(filename); try { if (f.createNewFile()) { PrintWriter out = new PrintWriter(f); out.println("Error on startup :"); out.printf( "JVM: %s %s on %s\n", System.getProperty("java.vm.name"), System.getProperty("java.runtime.version"), System.getProperty("os.name")); e.printStackTrace(out); out.flush(); out.close(); } } catch (IOException ignore) { } // lol what can you do log.severe("Crash detected. Generating report."); } }