Esempio n. 1
0
  private static String getConfigFile() {
    String pthnam = System.getProperty(SYSPROP_CFGFILE);
    String[] huntpath =
        new String[] {
          "./logging.xml",
          "./conf/logging.xml",
          System.getProperty("user.home", ".") + "/logging.xml"
        };
    java.io.File fh = null;

    if (pthnam == null) {
      for (int idx = 0; idx != huntpath.length; idx++) {
        if (huntpath[idx] == null) continue;
        fh = new java.io.File(huntpath[idx]);
        if (fh.exists()) {
          pthnam = huntpath[idx];
          break;
        }
      }
    }
    if (pthnam == null) return huntpath[0]; // doesn't exist, but gives us a filename to refer to
    if (fh == null) fh = new java.io.File(pthnam);
    try {
      return fh.getCanonicalPath();
    } catch (Exception ex) {
      String msg =
          "GreyLogger: Failed to canonise config="
              + pthnam
              + " - "
              + com.grey.base.GreyException.summary(ex);
      System.out.println(msg);
      throw new RuntimeException(msg, ex);
    }
  }
Esempio n. 2
0
 public static Logger getLoggerNoEx(String name) {
   if (leadingNameParts != 0 && name != null) {
     name = StringOps.keepLeadingParts(name, delimiterNameParts, leadingNameParts);
   }
   try {
     return getLogger(DFLT_CFGFILE, name);
   } catch (Exception ex) {
     throw new RuntimeException(
         "GreyLog-Factory failed to create logger="
             + name
             + " - "
             + com.grey.base.GreyException.summary(ex));
   }
 }
Esempio n. 3
0
 public static Logger getLogger(Parameters params, String name)
     throws com.grey.base.ConfigException, java.io.IOException {
   if (params == null) params = new Parameters();
   params.reconcile();
   Logger log = null;
   try {
     Class<?> clss = DynLoader.loadClass(params.logclass);
     java.lang.reflect.Constructor<?> ctor =
         clss.getDeclaredConstructor(Parameters.class, String.class);
     ctor.setAccessible(true);
     log = Logger.class.cast(ctor.newInstance(params, name));
   } catch (Throwable ex) {
     throw new com.grey.base.ConfigException(
         ex,
         "Failed to create logger="
             + params.logclass
             + " - "
             + com.grey.base.GreyException.summary(ex));
   }
   log.init();
   if (diagtrace) System.out.println("GreyLogger: Created Logger - " + log);
   return log;
 }