📄 logconfigcommandgroup.java
字号:
full_name, short_name + ".jar"), 8) + short_name); names.add(full_name); } } HashMap filters = configuration.getFilters(); // If a full path is given if (((comparable_name.lastIndexOf("/") != -1 || comparable_name .lastIndexOf("\\") != -1)) && filters.containsKey(comparable_name) && !names.contains(comparable_name)) { out.println(" - " + LogUtil.fromLevel(getLevel(configuration, comparable_name, ""), 8) + getFullName(comparable_name) + " (Bundle not yet installed)"); names.add(comparable_name); } // A short name is supplied else { if (filters.containsKey(comparable_name) && !names.contains(comparable_name)) { out.println(" - " + LogUtil.fromLevel(getLevel(configuration, "", comparable_name), 8) + getShortName(comparable_name) + " (default)"); names.add(comparable_name); } for (Iterator it = filters.keySet().iterator(); it .hasNext();) { name = (String) it.next(); if (name.endsWith(comparable_name) && !names.contains(name)) { out.println(" - " + LogUtil.fromLevel(getLevel( configuration, name, ""), 8) + getFullName(name) + " (Bundle not yet installed)"); names.add(name); } } } } } } } private int getLevel(LogConfig configuration, String full_name, String short_name) { HashMap filters = configuration.getFilters(); Integer level_to_use = (Integer) filters.get(full_name); if (level_to_use == null) { level_to_use = (Integer) filters.get(short_name); } return (level_to_use != null) ? level_to_use.intValue() : configuration .getFilter(); } private String getFullName(String bundle) { return fillName(new StringBuffer(bundle), 30); } private String getShortName(String bundle) { return fillName(new StringBuffer(bundle.substring(0, bundle .indexOf(".jar"))), 17); } private String fillName(StringBuffer sb, int length) { while (sb.length() < length) { sb.append(' '); } return sb.toString(); } // // Set out command // public final static String USAGE_OUT = "[-on | -off]"; public final static String[] HELP_OUT = new String[] { "Configures logging to standard out", "-on Turns on writing of log entries to standard out.", "-off Turns off writing of log entries to standard out.", }; public int cmdOut(Dictionary opts, Reader in, PrintWriter out, Session session) { // Get log configuration service LogConfig configuration = (LogConfig) LogCommands.logConfigTracker .getService(); if (configuration == null) { out.println("Unable to get a LogConfigService"); return 1; } if (!configuration.isDefaultConfig()) { out .println(" This command is no persistent. (No valid configuration has been received)"); } boolean optionFound = false; // System.out logging on/off if (opts.get("-on") != null) { optionFound = true; configuration.setOut(true); } else if (opts.get("-off") != null) { optionFound = true; configuration.setOut(false); } // Show current config if (!optionFound) { boolean isOn = configuration.getOut(); out.println(" Logging to standard out is " + (isOn ? "on" : "off") + "."); } return 0; } // // Set file command // public final static String USAGE_FILE = "[-on | -off] [-size #size#] [-gen #gen#] [-flush | -noflush]"; public final static String[] HELP_FILE = new String[] { "Configures the file logging (the no argument version prints the current settings)", "-on Turns on writing of log entries to file.", "-off Turns off writing of log entries to file.", "-size #size# Set the maximum size of one log file (characters).", "-gen #gen# Set the number of log file generations that are kept.", "-flush Turns on log file flushing after each log entry.", "-noflush Turns off log file flushing after each log entry.", }; public int cmdFile(Dictionary opts, Reader in, PrintWriter out, Session session) { // Get log configuration service LogConfig configuration = (LogConfig) LogCommands.logConfigTracker .getService(); if (configuration == null) { out.println("Unable to get a LogConfigService"); return 1; } if (!configuration.isDefaultConfig()) { out.println(" This command is not persistent. " + "(No valid configuration has been received)"); } if (configuration.getDir() != null) { boolean optionFound = false; // File logging on/off if (opts.get("-on") != null) { optionFound = true; configuration.setFile(true); } else if (opts.get("-off") != null) { optionFound = true; configuration.setFile(false); } // Flush if (opts.get("-flush") != null) { optionFound = true; if (!configuration.getFile()) { out .println("Cannot activate flush (file logging disabled)."); } else { configuration.setFlush(true); } } else if (opts.get("-noflush") != null) { optionFound = true; if (!configuration.getFile()) { out .println("Cannot deactivate flush (file logging disabled)."); } else { configuration.setFlush(false); } } // Log size String value = (String) opts.get("-size"); if (value != null) { optionFound = true; if (!configuration.getFile()) { out.println("Cannot set log size (file logging disabled)."); } else { try { configuration.setFileSize(Integer.parseInt(value)); } catch (NumberFormatException nfe1) { out.println("Cannot set log size (" + nfe1 + ")."); } } } // Log generations value = (String) opts.get("-gen"); if (value != null) { optionFound = true; if (!configuration.getFile()) { out .println("Cannot set generation count (file logging disabled)."); } else { try { configuration.setMaxGen(Integer.parseInt(value)); } catch (NumberFormatException nfe2) { out.println("Cannot set generation count (" + nfe2 + ")."); } } } // Update configuration only once if (optionFound) configuration.commit(); // Show current config if (!optionFound) { boolean isOn = configuration.getFile(); out.println(" file logging is " + (isOn ? "on" : "off") + "."); if (isOn) { out.println(" file size: " + configuration.getFileSize()); out.println(" generations: " + configuration.getMaxGen()); out.println(" flush: " + configuration.getFlush()); out.println(" log location: " + configuration.getDir()); } } return 0; } out.println(" This command is disabled. " + "(No filesystem support is available. )"); return 0; } /*************************************************************************** * Utility methods **************************************************************************/ private String getCommonLocation(String location) { if (location.endsWith(".jar")) { return location; } return location + ".jar"; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -