本文整理匯總了Java中java.util.logging.LogRecord類的典型用法代碼示例。如果您正苦於以下問題:Java LogRecord類的具體用法?Java LogRecord怎麽用?Java LogRecord使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
LogRecord類屬於java.util.logging包,在下文中一共展示了LogRecord類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: format
import java.util.logging.LogRecord; //導入依賴的package包/類
@Override
@SuppressWarnings("ThrowableResultIgnored")
public String format(LogRecord record) {
StringBuilder formatted = new StringBuilder();
formatted.append("[");
formatted.append(date.format(record.getMillis()));
formatted.append(" ");
formatted.append(record.getLevel().getName());
formatted.append("] ");
formatted.append(stripColors ? ConsoleColor.stripColors(formatMessage(record)) : formatMessage(record));
formatted.append('\n');
if(record.getThrown() != null) {
StringWriter writer = new StringWriter();
record.getThrown().printStackTrace(new PrintWriter(writer));
formatted.append(writer);
}
return formatted.toString();
}
示例2: LogWrapper
import java.util.logging.LogRecord; //導入依賴的package包/類
private LogWrapper() {
logger = Logger.getLogger(this.getClass().getCanonicalName());
Cache cache = CliUtil.getCacheIfExists();
if (cache != null && !cache.isClosed()) {
// TODO - Abhishek how to set different log levels for different handlers???
logger.addHandler(cache.getLogger().getHandler());
CommandResponseWriterHandler handler = new CommandResponseWriterHandler();
handler.setFilter(new Filter() {
@Override
public boolean isLoggable(LogRecord record) {
return record.getLevel().intValue() >= Level.FINE.intValue();
}
});
handler.setLevel(Level.FINE);
logger.addHandler(handler);
}
logger.setUseParentHandlers(false);
}
示例3: format
import java.util.logging.LogRecord; //導入依賴的package包/類
/**
* Format the given LogRecord.
*
* @param record
* the log record to be formatted.
* @return a formatted log record
*/
@Override
public String format(LogRecord record) {
StringBuilder sb = new StringBuilder();
LocalDateTime time = Instant.ofEpochMilli(record.getMillis()).atZone(ZoneId.systemDefault()).toLocalDateTime();
sb.append(TIME_FORMAT.format(time)).append(" [")
.append(record.getLevel())
.append("] ")
.append(record.getSourceClassName())
.append(".")
.append(record.getSourceMethodName())
.append(" ")
.append(record.getMessage())
.append("\n");
return sb.toString();
}
示例4: addConsoleLogging
import java.util.logging.LogRecord; //導入依賴的package包/類
public static void addConsoleLogging() {
Logger log = Logger.getAnonymousLogger();
while (log != null) {
if (log.getParent() == null) {
log.addHandler(new Handler() {
@Override
public void close() throws SecurityException {
}
@Override
public void flush() {
}
@Override
public void publish(LogRecord record) {
System.out.println("[" + record.getLevel() + "] " + record.getMessage());
}
});
}
log = log.getParent();
}
}
示例5: format
import java.util.logging.LogRecord; //導入依賴的package包/類
@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();
}
示例6: format
import java.util.logging.LogRecord; //導入依賴的package包/類
@Override
public String format(LogRecord record)
{
StringBuilder output = new StringBuilder();
return output
.append(dateFmt.format(new Date(record.getMillis())))
.append(underscore)
.append(record.getLevel().getName())
.append(underscore)
.append(record.getThreadID())
.append(underscore)
.append(record.getLoggerName())
.append(underscore)
.append(record.getMessage())
.append(CRLF)
.toString();
}
示例7: appendToFile
import java.util.logging.LogRecord; //導入依賴的package包/類
/**
* Helper that configures java.util.logging to sanely log messages at FINE level without additional
* formatting.
*/
public JavaLogger appendToFile(String logfile) {
logger.setLevel(java.util.logging.Level.FINE);
try {
FileHandler handler = new FileHandler(logfile, true);
handler.setFormatter(new SimpleFormatter() {
@Override
public String format(LogRecord record) {
return String.format("%s%n", record.getMessage()); // NOPMD
}
});
logger.addHandler(handler);
} catch (IOException e) {
throw new IllegalStateException("Could not add file handler.", e);
}
return this;
}
示例8: changeCount
import java.util.logging.LogRecord; //導入依賴的package包/類
/**
* Sets the quantity of the item.<BR><BR>
* <U><I>Remark :</I></U> If loc and loc_data different from database, say datas not up-to-date
* @param process : String Identifier of process triggering this action
* @param count : int
* @param creator : L2PcInstance Player requesting the item creation
* @param reference : L2Object Object referencing current action like NPC selling item or previous item in transformation
*/
public void changeCount(String process, int count, L2PcInstance creator, L2Object reference)
{
if (count == 0) return;
if ( count > 0 && _count > Integer.MAX_VALUE - count) _count = Integer.MAX_VALUE;
else _count += count;
if (_count < 0) _count = 0;
_storedInDb = false;
if (Config.LOG_ITEMS)
{
LogRecord record = new LogRecord(Level.INFO, "CHANGE:" + process);
record.setLoggerName("item");
record.setParameters(new Object[]{this, creator, reference});
_logItems.log(record);
}
}
示例9: logNetBeansAPIUsage
import java.util.logging.LogRecord; //導入依賴的package包/類
/** Sends info to UI handler about NetBeans APIs in use
*/
private static void logNetBeansAPIUsage(String msg, Collection<ModuleDependency> deps) {
List<String> cnbs = new ArrayList<String>();
for (ModuleDependency moduleDependency : deps) {
String cnb = moduleDependency.getModuleEntry().getCodeNameBase();
// observe just NetBeans API module usage
if (cnb.startsWith("org.openide") || cnb.startsWith("org.netbeans")) { // NOI18N
cnbs.add(cnb);
}
}
if (cnbs.isEmpty()) {
return;
}
LogRecord rec = new LogRecord(Level.CONFIG, msg);
rec.setParameters(cnbs.toArray(new String[0]));
rec.setResourceBundleName(SingleModuleProperties.class.getPackage().getName() + ".Bundle"); // NOI18N
rec.setResourceBundle(NbBundle.getBundle(SingleModuleProperties.class));
rec.setLoggerName(UI_LOG.getName());
UI_LOG.log(rec);
}
示例10: testLoggingMessageWithBundleAndArg
import java.util.logging.LogRecord; //導入依賴的package包/類
public void testLoggingMessageWithBundleAndArg() throws Exception {
FileObject dir = TimesCollectorPeerTest.makeScratchDir(this);
Logger LOG = Logger.getLogger("TIMER.instance.of.my.object");
LogRecord rec = new LogRecord(Level.FINE, "LOG_ProjectWithArg"); // NOI18N
rec.setParameters(new Object[] { dir, dir, "Lovely" });
rec.setResourceBundle(ResourceBundle.getBundle(HandlerTest.class.getName()));
LOG.log(rec);
Collection<Object> files = TimesCollectorPeer.getDefault().getFiles();
assertEquals("One object " + files, 1, files.size());
Description descr = TimesCollectorPeer.getDefault().getDescription(files.iterator().next(), "LOG_ProjectWithArg");
assertNotNull(descr);
if (descr.getMessage().indexOf("My Lovely Project") == -1) {
fail("Localized msg should contain 'My Lovely Project': " + descr.getMessage());
}
}
示例11: format
import java.util.logging.LogRecord; //導入依賴的package包/類
@Override
public String format(LogRecord record) {
// %d [%t] %p %c - %m%n
StringBuilder buf = new StringBuilder(256);
buf.append(new Date(record.getMillis()));
buf.append(" [");
buf.append(
Thread.currentThread().getId() == record.getThreadID() ? Thread.currentThread().getName() : "Unknown");
buf.append("] ");
buf.append(record.getLevel().getName());
buf.append(' ');
buf.append(record.getLoggerName());
buf.append(" - ");
if (record.getParameters() == null) {
buf.append(record.getMessage());
} else {
buf.append(String.format(record.getMessage(), record.getParameters()));
}
buf.append('\n');
return buf.toString();
}
示例12: createData
import java.util.logging.LogRecord; //導入依賴的package包/類
private void createData(final File file2Create) throws IOException {
boolean isSupported = new FileInfo(file2Create).isSupportedFile();
ProvidedExtensions extensions = getProvidedExtensions();
if (!isSupported) {
extensions.createFailure(this, file2Create.getName(), false);
FSException.io("EXC_CannotCreateData", file2Create.getName(), getPath());// NOI18N
} else if (FileChangedManager.getInstance().exists(file2Create)) {
extensions.createFailure(this, file2Create.getName(), false);
SyncFailedException sfe = new SyncFailedException(file2Create.getAbsolutePath()); // NOI18N
String msg = NbBundle.getMessage(FileBasedFileSystem.class, "EXC_CannotCreateData", file2Create.getName(), getPath()); // NOI18N
Exceptions.attachLocalizedMessage(sfe, msg);
throw sfe;
} else if (!file2Create.createNewFile()) {
extensions.createFailure(this, file2Create.getName(), false);
FSException.io("EXC_CannotCreateData", file2Create.getName(), getPath());// NOI18N
}
LogRecord r = new LogRecord(Level.FINEST, "DataCreated: "+ file2Create.getAbsolutePath());
r.setParameters(new Object[] {file2Create});
Logger.getLogger("org.netbeans.modules.masterfs.filebasedfs.fileobjects.FolderObj").log(r);
}
示例13: MockConstrainedIndexer
import java.util.logging.LogRecord; //導入依賴的package包/類
MockConstrainedIndexer() {
h = new Handler() {
@Override
public void publish(LogRecord record) {
if (record.getMessage().equals("RootsWork-finished")) {
sem.release();
}
}
@Override
public void flush() {
}
@Override
public void close() throws SecurityException {
}
};
final Logger log = Logger.getLogger(RepositoryUpdater.class.getName() + ".tests"); //NOI18N
log.setLevel(Level.FINEST);
log.addHandler(h);
}
示例14: setUp
import java.util.logging.LogRecord; //導入依賴的package包/類
@Override
protected void setUp() throws Exception {
EntrySupportLazy.LOGGER.addHandler(new java.util.logging.Handler() {
{
setLevel(Level.FINER);
EntrySupportLazy.LOGGER.setLevel(Level.FINER);
}
@Override
public void publish(LogRecord record) {
if (record.getMessage().startsWith("setEntries():")) {
notifyRecordIsHere();
}
}
@Override
public void flush() {
}
@Override
public void close() throws SecurityException {
throw new UnsupportedOperationException("Not supported yet.");
}
});
}
示例15: logRecords
import java.util.logging.LogRecord; //導入依賴的package包/類
private void logRecords(Appendable a) {
List<LogRecord> r = records;
if (r == null) {
return;
}
try {
for (LogRecord log : r) {
if (log.getMessage() != null) {
a.append(log.getMessage()).append("\n");;
}
if (log.getThrown() != null) {
StringWriter w = new StringWriter();
log.getThrown().printStackTrace(new PrintWriter(w));
a.append(w.toString()).append("\n");
}
}
} catch (IOException ex) {
ex.printStackTrace();
}
}