java.util.logging.LogRecord#getParameters ( )源码实例Demo

下面列出了java.util.logging.LogRecord#getParameters ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: Installer.java
private static File getHeapDump(List<LogRecord> recs, boolean isAfterRestart) {
    LogRecord thrownLog = getThrownLog(recs);
    if (isAfterRestart) {
        Object[] parameters = thrownLog.getParameters();
        if (parameters != null && parameters.length > 0) {
            String heapDumpPath = (String) parameters[parameters.length - 1];
            File hdf = new File(heapDumpPath);
            if (!hdf.exists()) {
                heapDumpPath += ".old";
                hdf = new File(heapDumpPath);
            }
            return hdf;
        }
    }
    return getHeapDump();
}
 
@Override
public void publish(LogRecord record) {
    Runnable r = null;
    synchronized (this) {
        String message = record.getMessage();
        if (message != null) {
            final Object[] params = record.getParameters();
            if (params != null && params.length > 0) {
                message = MessageFormat.format(message, params);
            }
            if (message.equals(expected.peek())) {
                if (VERBOSE) {
                    System.out.println(message);
                }
                expected.remove();
            }
            r = actions.get(message);
        }
    }
    if (r != null) {
        r.run();
    }
}
 
源代码3 项目: netbeans   文件: JsParsingPerformanceTest.java
@Override
public void publish(LogRecord record) {
    String message = record.getMessage();
    if (message != null && message.startsWith(MSG_PARSING_ALL)) {
        message = ((String)record.getParameters()[1]);
        if (message.contains("real2k")) {
            JsParsingPerformanceTest.parsingReal2k += getLongFromLogRecord(record);
        } else if (message.contains("real500")) {
            JsParsingPerformanceTest.parsingReal500 += getLongFromLogRecord(record);
        } else if (message.contains("syntheticDoc10k")) {
            JsParsingPerformanceTest.parsingSyntheticDoc10k += getLongFromLogRecord(record);
        }
    } else if (message != null && message.startsWith(MSG_PARSING_DOC)) {
        message = ((String)record.getParameters()[1]);
        if (message.contains("real2k")) {
            JsParsingPerformanceTest.parsingReal2kComment += getLongFromLogRecord(record);
        } else if (message.contains("real500")) {
            JsParsingPerformanceTest.parsingReal500Comment += getLongFromLogRecord(record);
        } else if (message.contains("syntheticDoc10k")) {
            JsParsingPerformanceTest.parsingSyntheticDoc10kComment += getLongFromLogRecord(record);
        }
    }
}
 
源代码4 项目: netbeans   文件: StartLog.java
@Override
public void publish(LogRecord rec) {
    Object[] args = rec.getParameters();
    String msg = (args.length >= 1 && args[0] instanceof String) ? (String)args[0] : ""; // NOI18N
    long time = System.nanoTime()/1000000;
    if ("start".equals(rec.getMessage())) { // NOI18N
        start(msg, time);
        return;
    }
    if ("end".equals(rec.getMessage())) { // NOI18N
        end(msg, time);
        return;
    }
    if ("progress".equals(rec.getMessage())) { // NOI18N
        progress(msg, time);
        return;
    }
}
 
源代码5 项目: scheduling   文件: JulToLog4jHandler.java
private String toLog4jMessage(LogRecord record) {
    String message = record.getMessage();
    // Format message
    try {
        Object parameters[] = record.getParameters();
        if (parameters != null && parameters.length != 0) {
            // Check for the first few parameters ?
            if (message.contains("{0}") || message.contains("{1}") || message.contains("{2}") ||
                message.contains("{3}")) {
                message = MessageFormat.format(message, parameters);
            }
        }
    } catch (Exception ex) {
        // ignore Exception
    }
    return message;
}
 
源代码6 项目: L2jBrasil   文件: ChatLogFormatter.java
@Override
public String format(LogRecord record)
{
	Object[] params = record.getParameters();
       StringBuilder output = new StringBuilder();
	output.append('[');
	output.append(dateFmt.format(new Date(record.getMillis())));
	output.append(']');
	output.append(' ');
	if (params != null)
	{
		for (Object p : params)
		{
			output.append(p);
			output.append(' ');
		}
	}
	output.append(record.getMessage());
	output.append(CRLF);

	return output.toString();
}
 
源代码7 项目: dragonwell8_jdk   文件: TestLogrbResourceBundle.java
@Override
public void publish(LogRecord record) {
    lastBundle = record.getResourceBundle();
    lastBundleName = record.getResourceBundleName();
    lastParams = record.getParameters();
    lastThrown = record.getThrown();
    lastMessage = record.getMessage();
}
 
源代码8 项目: netbeans   文件: Log.java
@Override
public void publish(LogRecord record) {
    Object[] param = record.getParameters();
    if (param == null) {
        return;
    }
    if (msg != null && !msg.equals(record.getMessage())) {
        return;
    }
    cnt++;
    for (Object o : param) {
        instances.put(o, record.getMessage());
    }
}
 
源代码9 项目: jdk8u60   文件: TestLogrbResourceBundle.java
@Override
public void publish(LogRecord record) {
    lastBundle = record.getResourceBundle();
    lastBundleName = record.getResourceBundleName();
    lastParams = record.getParameters();
    lastThrown = record.getThrown();
    lastMessage = record.getMessage();
}
 
源代码10 项目: jdk8u60   文件: TestLoggerBundleSync.java
@Override
public synchronized void publish(LogRecord record) {
    Object[] params = record.getParameters();
    // Each GetRB thread has its own handler, but since they
    // log into the same logger, each handler may receive
    // messages emitted by other threads.
    // This means that GetRB#2.handler may receive a message
    // emitted by GetRB#1 at a time where the resource bundle
    // was still null.
    // To avoid falling into this trap, the GetRB thread passes
    // 'this' as argument to the messages it logs - which does
    // allow us here to ignore messages that where not emitted
    // by our own GetRB.this thread...
    if (params.length == 1) {
        if (params[0] == GetRB.this) {
            // The message was emitted by our thread.
            count++;
            rb = record.getResourceBundle();
            rbName = record.getResourceBundleName();
        } else {
            // The message was emitted by another thread: just
            // ignore it, as it may have been emitted at a time
            // where the resource bundle was still null, and
            // processing it may overwrite the 'rb' and 'rbName'
            // recorded from the message emitted by our own thread.
            if (VERBOSE) {
                System.out.println("Ignoring message logged by " + params[0]);
            }
            ignoreLogCount.incrementAndGet();
        }
    } else {
        ignoreLogCount.incrementAndGet();
        System.err.println("Unexpected message received");
    }
}
 
源代码11 项目: openjdk-jdk8u   文件: TestLoggerBundleSync.java
@Override
public synchronized void publish(LogRecord record) {
    Object[] params = record.getParameters();
    // Each GetRB thread has its own handler, but since they
    // log into the same logger, each handler may receive
    // messages emitted by other threads.
    // This means that GetRB#2.handler may receive a message
    // emitted by GetRB#1 at a time where the resource bundle
    // was still null.
    // To avoid falling into this trap, the GetRB thread passes
    // 'this' as argument to the messages it logs - which does
    // allow us here to ignore messages that where not emitted
    // by our own GetRB.this thread...
    if (params.length == 1) {
        if (params[0] == GetRB.this) {
            // The message was emitted by our thread.
            count++;
            rb = record.getResourceBundle();
            rbName = record.getResourceBundleName();
        } else {
            // The message was emitted by another thread: just
            // ignore it, as it may have been emitted at a time
            // where the resource bundle was still null, and
            // processing it may overwrite the 'rb' and 'rbName'
            // recorded from the message emitted by our own thread.
            if (VERBOSE) {
                System.out.println("Ignoring message logged by " + params[0]);
            }
            ignoreLogCount.incrementAndGet();
        }
    } else {
        ignoreLogCount.incrementAndGet();
        System.err.println("Unexpected message received");
    }
}
 
源代码12 项目: L2jBrasil   文件: ItemLogFormatter.java
@Override
public String format(LogRecord record)
{
       StringBuilder output = new StringBuilder();
	output.append('[');
	output.append(dateFmt.format(new Date(record.getMillis())));
	output.append(']');
	output.append(' ');
	output.append(record.getMessage());
	for (Object p : record.getParameters())
	{
		if (p == null) continue;
		output.append(',');
		output.append(' ');
		if (p instanceof L2ItemInstance)
		{
			L2ItemInstance item = (L2ItemInstance)p;
			output.append("item " + item.getObjectId() + ":");
			if (item.getEnchantLevel() > 0) output.append("+" + item.getEnchantLevel() + " ");
			output.append(item.getItem().getName());
			output.append("(" + item.getCount() + ")");
		}
		//else if (p instanceof L2PcInstance)
		//	output.append(((L2PcInstance)p).getName());
		else output.append(p.toString()/* + ":" + ((L2Object)p).getObjectId()*/);
	}
	output.append(CRLF);

	return output.toString();
}
 
源代码13 项目: hottub   文件: TestLogrbResourceBundle.java
@Override
public void publish(LogRecord record) {
    lastBundle = record.getResourceBundle();
    lastBundleName = record.getResourceBundleName();
    lastParams = record.getParameters();
    lastThrown = record.getThrown();
    lastMessage = record.getMessage();
}
 
源代码14 项目: netbeans   文件: UINode.java
static Node create(LogRecord r) {
    Children ch;
    if (r.getThrown() != null) {
        ch = new StackTraceChildren(r.getThrown());
    } else if ("UI_ENABLED_MODULES".equals(r.getMessage()) || 
        "UI_DISABLED_MODULES".equals(r.getMessage())) {
        ch = new ModulesChildren(r.getParameters());
    } else {
        ch = Children.LEAF;
    }
    
    
    return new UINode(r, ch);
}
 
源代码15 项目: openjdk-jdk9   文件: TestLoggerBundleSync.java
@Override
public synchronized void publish(LogRecord record) {
    Object[] params = record.getParameters();
    // Each GetRB thread has its own handler, but since they
    // log into the same logger, each handler may receive
    // messages emitted by other threads.
    // This means that GetRB#2.handler may receive a message
    // emitted by GetRB#1 at a time where the resource bundle
    // was still null.
    // To avoid falling into this trap, the GetRB thread passes
    // 'this' as argument to the messages it logs - which does
    // allow us here to ignore messages that where not emitted
    // by our own GetRB.this thread...
    if (params.length == 1) {
        if (params[0] == GetRB.this) {
            // The message was emitted by our thread.
            count++;
            rb = record.getResourceBundle();
            rbName = record.getResourceBundleName();
        } else {
            // The message was emitted by another thread: just
            // ignore it, as it may have been emitted at a time
            // where the resource bundle was still null, and
            // processing it may overwrite the 'rb' and 'rbName'
            // recorded from the message emitted by our own thread.
            if (VERBOSE) {
                System.out.println("Ignoring message logged by " + params[0]);
            }
            ignoreLogCount.incrementAndGet();
        }
    } else {
        ignoreLogCount.incrementAndGet();
        System.err.println("Unexpected message received");
    }
}
 
源代码16 项目: ProjectAres   文件: Logging.java
public static void addParam(LogRecord record, Object param) {
    Object[] params = record.getParameters();
    if(params == null) {
        params = new Object[]{ param };
    } else {
        Object[] oldParams = params;
        params = new Object[oldParams.length + 1];
        System.arraycopy(oldParams, 0, params, 0, oldParams.length);
        params[oldParams.length] = param;
    }
    record.setParameters(params);
}
 
源代码17 项目: cloudsync   文件: LogfileHandler.java
@Override
public void publish(LogRecord record)
{
	if (record.getParameters() != null) return;

	super.publish(record);
}
 
@Override
public void publish(LogRecord record) {
    if (Boolean.getBoolean("counting.off")) {
        return;
    }
    final String m = record.getMessage();
    if (m != null && m.startsWith("Initialize data")) {
        Object[] params = record.getParameters();
        assertNotNull("There are parameters", params);
        assertEquals("There is just one parameter: " + Arrays.toString(params), 1, params.length);
        if (params[0] == null) {
            // fixed modules are OK
            return;
        }
        if (isPlatformOrIde((File)params[0])) {
            return;
        }
        
        String prev = System.getProperty("manifestParsing");
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        if (prev != null) {
            pw.append(prev).append("\n");
        }
        final String msg = m + ": " + params[0];
        if (Boolean.getBoolean("no.stacks")) {
            pw.print(msg);
        } else { 
            new Exception(msg).printStackTrace(pw);
        }
        pw.flush();
        System.setProperty("manifestParsing", sw.toString());
    }
}
 
源代码19 项目: netbeans   文件: LogFormatter.java
/**
 * Format the given message to XML.
 * @param record the log record to be formatted.
 * @return a formatted log record
 */
public @Override String format(LogRecord record) {
    StringBuffer sb = new StringBuffer(1000);
    sb.append("<record>\n");// NOI18N
    
    sb.append("  <date>");// NOI18N
    appendISO8601(sb, record.getMillis());
    sb.append("</date>\n");// NOI18N
    
    sb.append("  <millis>");// NOI18N
    sb.append(record.getMillis());
    sb.append("</millis>\n");// NOI18N
    
    sb.append("  <sequence>");// NOI18N
    sb.append(record.getSequenceNumber());
    sb.append("</sequence>\n");// NOI18N
    
    String name = record.getLoggerName();
    if (name != null) {
        sb.append("  <logger>");// NOI18N
        escape(sb, name);
        sb.append("</logger>\n");// NOI18N
    }
    
    sb.append("  <level>");// NOI18N
    String level = Integer.toString(record.getLevel().intValue());
    escape(sb, level);
    sb.append("</level>\n");// NOI18N
    
    if (record.getSourceClassName() != null) {
        sb.append("  <class>");// NOI18N
        escape(sb, record.getSourceClassName());
        sb.append("</class>\n");// NOI18N
    }
    
    if (record.getSourceMethodName() != null) {
        sb.append("  <method>");// NOI18N
        escape(sb, record.getSourceMethodName());
        sb.append("</method>\n");// NOI18N
    }
    
    sb.append("  <thread>");// NOI18N
    sb.append(record.getThreadID());
    sb.append("</thread>\n");// NOI18N
    
    String message = record.getMessage();
    if (message != null) {
        sb.append("  <message>");// NOI18N
        escape(sb, message);
        sb.append("</message>\n");// NOI18N
    }
            
    // If the message is being localized, output the key, resource
    // bundle name, and params.
    ResourceBundle bundle = record.getResourceBundle();
    try {
        if (bundle != null && bundle.getString(message) != null) {
            sb.append("  <key>");// NOI18N
            escape(sb, message);
            sb.append("</key>\n");// NOI18N
            sb.append("  <catalog>");// NOI18N
            escape(sb, record.getResourceBundleName());
            sb.append("</catalog>\n");// NOI18N
        }
    } catch (Exception exc) {
        // The message is not in the catalog.  Drop through.
        Logger.getLogger(LogFormatter.class.getName()).log(Level.FINE, "Catalog loading error", exc);// NOI18N
    }

    Object parameters[] = record.getParameters();
    //  Check to see if the parameter was not a messagetext format
    //  or was not null or empty
    if ( parameters != null && parameters.length != 0
            && (message == null || message.indexOf("{") == -1) ) {
        for (int i = 0; i < parameters.length; i++) {
            sb.append("  <param>");// NOI18N
            try {
                escape(sb, paramToString(parameters[i]));
            } catch (Exception ex) {
                sb.append("???");// NOI18N
            }
            sb.append("</param>\n");// NOI18N
        }
    }
    
    if (record.getThrown() != null) {
        printThrown(record.getThrown(), sb);
    }
    
    sb.append("</record>\n");// NOI18N
    return sb.toString();
}
 
源代码20 项目: netbeans   文件: Log.java
private Logger getPackageLogger() {
      if (logger == null) {
          String prop = System.getProperty(packageName, DEFAULT_NAME);
          for (int i = 1; i < LEVELS.length; i++) {
              if (prop.toLowerCase().equals(LEVEL_NAMES[i].toLowerCase())) {
                  level = LEVELS[i];
                  break;
              }
          }
          LogManager.getLogManager().addLogger(new Logger(packageName, null)
{});
          logger = LogManager.getLogManager().getLogger(packageName);
          if (logger == null) {
              System.out.println(packageName + ": "
		   + rb.getString("CANT_GET_LOGGER"));
              return Logger.getLogger("global");
          }
          try {
              logger.setLevel(level);
              Handler handler = new ConsoleHandler();
              handler.setLevel(level);
// Default handlers don't provide class name or method name, so roll our own
logger.setUseParentHandlers(false);
Formatter formatter = new Formatter() {
	public String format(LogRecord record) {
	    StringBuffer s = new StringBuffer();
	    s.append(record.getLevel().getLocalizedName());
	    s.append(' ');
	    if (record.getLoggerName() != null) {
		s.append('[');
		s.append(record.getLoggerName());
		s.append("]: ");
	    }
	    if (record.getSourceClassName() != null) {
		s.append("| ");
		if (record.getLevel().equals(Level.FINEST)) {
		    String className = record.getSourceClassName();
		    s.append(className.substring(Math.max(className.lastIndexOf('.')+1,0)));
		} else {
		    s.append(record.getSourceClassName());
		}
		s.append(' ');
	    }
	    if (record.getSourceMethodName() != null) {
		s.append("|  ");
		s.append(record.getSourceMethodName());
		s.append("( ");
		Object[] parms = record.getParameters();
		if (parms != null) {
		    for (int i = 0; i < parms.length; i++) {
			if (i != 0) {
			    s.append(", ");
			}
			s.append(parms[i]);
		    }
		}
		s.append(" ) ");
	    }
	    if (record.getThrown() != null) {
		s.append("| ");
		s.append(record.getThrown());
	    }
	    if (record.getMessage() != null) {
		s.append('|');
		s.append(record.getMessage());
	    }
	    s.append('\n');
	    return s.toString();
	}
                  };
              handler.setFormatter(formatter);
              logger.addHandler(handler);
          }
          catch (SecurityException e) {
          }
      }

      return logger;
  }