当前位置: 首页>>代码示例>>Java>>正文


Java LogRecord类代码示例

本文整理汇总了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();
}
 
开发者ID:Superioz,项目名称:MooProject,代码行数:21,代码来源:ConciseFormatter.java

示例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);
}
 
开发者ID:ampool,项目名称:monarch,代码行数:20,代码来源:LogWrapper.java

示例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();
}
 
开发者ID:wfink,项目名称:jboss-eap7.1-playground,代码行数:27,代码来源:PlaygroundFormatter.java

示例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();
	}	
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:25,代码来源:SimpleLogging.java

示例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();
}
 
开发者ID:L2jBrasil,项目名称:L2jBrasil,代码行数:23,代码来源:ChatLogFormatter.java

示例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();
}
 
开发者ID:L2jBrasil,项目名称:L2jBrasil,代码行数:19,代码来源:FileLogFormatter.java

示例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;
}
 
开发者ID:wenwu315,项目名称:XXXX,代码行数:21,代码来源:Logger.java

示例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);
	}
}
 
开发者ID:L2jBrasil,项目名称:L2jBrasil,代码行数:25,代码来源:L2ItemInstance.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:SingleModuleProperties.java

示例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());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:HandlerTest.java

示例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();
}
 
开发者ID:stephenc,项目名称:java-logging-benchmarks,代码行数:22,代码来源:Log4JFormatter.java

示例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);        
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:FolderObj.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:ConstrainedBinaryIndexerTest.java

示例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.");
        }

        
    });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:ChildrenInitializedMeanwhileTest.java

示例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();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:Exceptions.java


注:本文中的java.util.logging.LogRecord类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。