public static void log(
     String level,
     String clazz,
     String clazzSimpleName,
     String packageName,
     String method,
     String signature,
     String fileName,
     String relativeFileName,
     int line,
     Object[] args) {
   Throwable throwable = null;
   String pattern = "";
   if (args[0] instanceof Throwable) {
     throwable = (Throwable) args[0];
     pattern = (String) args[1];
   } else {
     pattern = (String) args[0];
   }
   pattern = stringFormatPrefix + pattern;
   Object[] betterLogsArgs = new Object[argsPrefix.size()];
   int i = 0;
   for (String argName : argsPrefix) {
     if ("class".equals(argName)) betterLogsArgs[i] = clazz;
     if ("simpleClass".equals(argName)) betterLogsArgs[i] = clazzSimpleName;
     if ("package".equals(argName)) betterLogsArgs[i] = packageName;
     if ("method".equals(argName)) betterLogsArgs[i] = method;
     if ("file".equals(argName)) betterLogsArgs[i] = fileName;
     if ("line".equals(argName)) betterLogsArgs[i] = line;
     if ("relativeFile".equals(argName)) betterLogsArgs[i] = relativeFileName;
     if ("signature".equals(argName)) betterLogsArgs[i] = signature;
     i++;
   }
   if ("trace".equals(level)) {
     Logger.trace(pattern, handleLogArgs(betterLogsArgs, args, 1));
   } else if ("debug".equals(level)) {
     if (throwable != null)
       Logger.debug(throwable, pattern, handleLogArgs(betterLogsArgs, args, 2));
     else Logger.debug(pattern, handleLogArgs(betterLogsArgs, args, 1));
   } else if ("info".equals(level)) {
     if (throwable != null)
       Logger.info(throwable, pattern, handleLogArgs(betterLogsArgs, args, 2));
     else Logger.info(pattern, handleLogArgs(betterLogsArgs, args, 1));
   } else if ("warn".equals(level)) {
     if (throwable != null)
       Logger.warn(throwable, pattern, handleLogArgs(betterLogsArgs, args, 2));
     else Logger.warn(pattern, handleLogArgs(betterLogsArgs, args, 1));
   } else if ("error".equals(level)) {
     if (throwable != null)
       Logger.error(throwable, pattern, handleLogArgs(betterLogsArgs, args, 2));
     else Logger.error(pattern, handleLogArgs(betterLogsArgs, args, 1));
   } else if ("fatal".equals(level)) {
     if (throwable != null)
       Logger.fatal(throwable, pattern, handleLogArgs(betterLogsArgs, args, 2));
     else Logger.fatal(pattern, handleLogArgs(betterLogsArgs, args, 1));
   }
 }
 public static void fatal(String msg, Object... args) {
   Logger.fatal(msg_(msg, args));
 }
 public static void fatal(Throwable t, String msg, Object... args) {
   Logger.fatal(t, msg_(msg, args));
 }
Exemple #4
0
  private static Properties readOneConfigurationFile(String filename) {
    Properties propsFromFile = null;

    VirtualFile appRoot = VirtualFile.open(applicationPath);

    VirtualFile conf = appRoot.child("conf/" + filename);
    if (confs.contains(conf)) {
      throw new RuntimeException(
          "Detected recursive @include usage. Have seen the file " + filename + " before");
    }

    try {
      propsFromFile = IO.readUtf8Properties(conf.inputstream());
    } catch (RuntimeException e) {
      if (e.getCause() instanceof IOException) {
        Logger.fatal("Cannot read " + filename);
        fatalServerErrorOccurred();
      }
    }
    confs.add(conf);

    // OK, check for instance specifics configuration
    Properties newConfiguration = new OrderSafeProperties();
    Pattern pattern = Pattern.compile("^%([a-zA-Z0-9_\\-]+)\\.(.*)$");
    for (Object key : propsFromFile.keySet()) {
      Matcher matcher = pattern.matcher(key + "");
      if (!matcher.matches()) {
        newConfiguration.put(key, propsFromFile.get(key).toString().trim());
      }
    }
    for (Object key : propsFromFile.keySet()) {
      Matcher matcher = pattern.matcher(key + "");
      if (matcher.matches()) {
        String instance = matcher.group(1);
        if (instance.equals(id)) {
          newConfiguration.put(matcher.group(2), propsFromFile.get(key).toString().trim());
        }
      }
    }
    propsFromFile = newConfiguration;
    // Resolve ${..}
    pattern = Pattern.compile("\\$\\{([^}]+)}");
    for (Object key : propsFromFile.keySet()) {
      String value = propsFromFile.getProperty(key.toString());
      Matcher matcher = pattern.matcher(value);
      StringBuffer newValue = new StringBuffer(100);
      while (matcher.find()) {
        String jp = matcher.group(1);
        String r;
        if (jp.equals("application.path")) {
          r = Play.applicationPath.getAbsolutePath();
        } else if (jp.equals("play.path")) {
          r = Play.frameworkPath.getAbsolutePath();
        } else {
          r = System.getProperty(jp);
          if (r == null) {
            r = System.getenv(jp);
          }
          if (r == null) {
            Logger.warn("Cannot replace %s in configuration (%s=%s)", jp, key, value);
            continue;
          }
        }
        matcher.appendReplacement(newValue, r.replaceAll("\\\\", "\\\\\\\\"));
      }
      matcher.appendTail(newValue);
      propsFromFile.setProperty(key.toString(), newValue.toString());
    }
    // Include
    Map<Object, Object> toInclude = new HashMap<Object, Object>(16);
    for (Object key : propsFromFile.keySet()) {
      if (key.toString().startsWith("@include.")) {
        try {
          String filenameToInclude = propsFromFile.getProperty(key.toString());
          toInclude.putAll(readOneConfigurationFile(filenameToInclude));
        } catch (Exception ex) {
          Logger.warn("Missing include: %s", key);
        }
      }
    }
    propsFromFile.putAll(toInclude);

    return propsFromFile;
  }