Package org.knopflerfish.service.log

Examples of org.knopflerfish.service.log.LogConfig


                       final Reader in,
                       final PrintWriter out,
                       final Session session) {

    // Get log configuration service
    final LogConfig configuration = (LogConfig)
      LogCommands.logConfigTracker.getService();
    if (configuration == null) {
      out.println("Unable to get a LogConfigService");
      return 1;
    }

    final boolean clear = null != opts.get("-c");

    int newSize = -1;
    final String sizeArg = (String) opts.get("int");
    if (sizeArg != null) {
      try {
        newSize = Integer.parseInt(sizeArg);
      } catch (NumberFormatException nfe) {
        out.println("Can not set log memory size (" + nfe + ").");
        return 2;
      }
    }

    final int curSize = configuration.getMemorySize();
    if (clear) {
      configuration.setMemorySize(1);// This will throw away all old entries
      configuration.setMemorySize(-1<newSize ? newSize : curSize);
    } else if (-1<newSize) {
      configuration.setMemorySize(curSize);
    } else {
      out.println("  log memory size: " + curSize);
    }

    return 0;
View Full Code Here


  public int cmdSetlevel(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;
    }

    String l = (String) opts.get("level");
    int level = LogUtil.toLevel((l.trim()), -1);
    if (level == -1) {
      out.println("Unknown level: " + l);
      return 1;
    }
    String[] selection = (String[]) opts.get("bundle");
    if (selection != null) {
      setValidBundles(configuration, selection, level);
      configuration.commit();
    } else {
      configuration.setFilter(level);
    }
    return 0;
  }
View Full Code Here

  public int cmdShowlevel(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;
    }

    final Bundle[] bundles = LogCommands.bc.getBundles();

    String[] selections = (String[]) opts.get("bundle");
    final boolean showAll = null==selections;
    if (selections == null) {
      HashMap filters = configuration.getFilters();
      selections = (String[])
        filters.keySet().toArray(new String[filters.size()]);
    }
    // Print the default filter level.
    out.println("    *  " + LogUtil.fromLevel(configuration.getFilter(), 8)
                + "(default)");

    final Set matchedSelectors = new HashSet();
    Util.selectBundles(bundles, selections, matchedSelectors);
    Util.sortBundlesId(bundles);
View Full Code Here

  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;
  }
View Full Code Here

  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;
    }
View Full Code Here

TOP

Related Classes of org.knopflerfish.service.log.LogConfig

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.