public static void setLogLevel(Logger log) { int level = 7; // E_DEFAULT switch (log.getEffectiveLevel().toInt()) { case Level.ALL_INT: level = 7; // E_FORCE break; case Level.TRACE_INT: level = 6; // E_TRACE break; case Level.DEBUG_INT: level = 5; // E_DEBUG break; case Level.INFO_INT: level = 4; // E_INFO break; case Level.WARN_INT: level = 3; // E_WARN break; case Level.ERROR_INT: level = 2; // E_ERROR break; case Level.FATAL_INT: level = 1; // E_FATAL break; case Level.OFF_INT: level = 0; // E_OFF break; } setLogLevel(level); }
public String debug() { if (logger.getEffectiveLevel().equals(Level.ALL)) { return ""; } // otherwise we want output StringBuilder sb = new StringBuilder(); sb.append("remove "); sb.append(m_from.printContour(m_removed)); sb.append("\n"); sb.append(" from "); sb.append(m_from.debugAsSentence()); sb.append("\n"); sb.append(" to "); sb.append(m_to.debugAsSentence()); sb.append("\n"); sb.append(" zonesMoved: "); Set<Map.Entry<AbstractBasicRegion, AbstractBasicRegion>> entries = m_zones_moved.entrySet(); for (Map.Entry<AbstractBasicRegion, AbstractBasicRegion> z_map : entries) { sb.append("<"); sb.append(z_map.getKey().debug()); sb.append("->"); sb.append(z_map.getValue().debug()); sb.append(">"); } return sb.toString(); }
/** 获取Logger的日志级别. */ @ManagedOperation(description = "Get logging level of the logger") @ManagedOperationParameters({ @ManagedOperationParameter(name = "loggerName", description = "Logger name") }) public String getLoggerLevel(String loggerName) { Logger logger = Logger.getLogger(loggerName); return logger.getEffectiveLevel().toString(); }
private void displayLoggerLevel(Logger logger, PrintStream out, PrintStream err) { if (logger == null) { out.println("Logger not found"); return; } Level level = logger.getEffectiveLevel(); out.println(levelToString(level)); }
/** * Write our internal representation to output stream <code>os</code>, in the appropriate way as * determined by our <code>type</code>. * * @param os os * @throws TransformerConfigurationException TransformerConfigurationException * @throws FileNotFoundException FileNotFoundException * @throws TransformerException TransformerException * @throws IOException IOException * @throws Exception Exception */ public void writeTo(OutputStream os) throws TransformerConfigurationException, FileNotFoundException, TransformerException, IOException, Exception { if (type.isXMLType()) { if (writer == null) writer = new MaryNormalisedWriter(); if (logger.getEffectiveLevel().equals(Level.DEBUG)) { ByteArrayOutputStream debugOut = new ByteArrayOutputStream(); writer.output(xmlDocument, debugOut); logger.debug(debugOut.toString()); } writer.output(xmlDocument, new BufferedOutputStream(os)); } else if (type.isTextType()) { // caution: XML types are text types! writeTo(new OutputStreamWriter(os, "UTF-8")); } else { // audio logger.debug("Writing audio output, frame length " + audio.getFrameLength()); AudioSystem.write(audio, audioFileFormat.getType(), os); os.flush(); os.close(); } }
/** Returns the level for this logger. */ public Level getLevel() { return toJavaLevel(logger.getEffectiveLevel()); }
/** * Atomic write of a single block for a file version. * * @author <a href="mailto:[email protected]">Bryan Thompson</a> */ public class AtomicBlockWriteProc implements ISimpleIndexProcedure<Object>, Externalizable { private static final long serialVersionUID = 4982851251684333327L; protected static transient Logger log = Logger.getLogger(AtomicBlockWriteProc.class); /** True iff the {@link #log} level is INFO or less. */ public static final transient boolean INFO = log.getEffectiveLevel().toInt() <= Level.INFO.toInt(); /** True iff the {@link #log} level is DEBUG or less. */ public static final transient boolean DEBUG = log.getEffectiveLevel().toInt() <= Level.DEBUG.toInt(); private String id; private int version; private long block; private int off; private int len; private byte[] b; @Override public final boolean isReadOnly() { return false; } /** * @param id The file identifier. * @param version The file version. * @param block The block identifier. * @param b The buffer containing the data to be written. * @param off The offset in the buffer of the first byte to be written. * @param len The #of bytes to be written. */ public AtomicBlockWriteProc( BigdataFileSystem repo, String id, int version, long block, byte[] b, int off, int len) { assert id != null && id.length() > 0; assert version >= 0; assert block >= 0 && block <= BigdataFileSystem.MAX_BLOCK; assert b != null; assert off >= 0 : "off=" + off; assert len >= 0 && off + len <= b.length; assert len <= repo.getBlockSize() : "len=" + len + " exceeds blockSize=" + repo.getBlockSize(); this.id = id; this.version = version; this.block = block; this.off = off; this.len = len; this.b = b; } /** * This procedure runs on the unisolated index. The raw data is written directly onto the {@link * Journal} and the index is added/updated using the given file, version and block and the address * of the block's data on the {@link Journal}. * * @return A {@link Boolean} whose value is <code>true</code> iff the block was overwritten. */ @Override public Object apply(final IIndex ndx) { // tunnel through to the backing journal. final AbstractJournal journal = (AbstractJournal) ((AbstractBTree) ndx).getStore(); // obtain the thread-local key builder for that journal. final IKeyBuilder keyBuilder = ndx.getIndexMetadata().getKeyBuilder(); /* * Write the block on the journal, obtaining the address at which it * was written - use 0L as the address for an empty block. */ final long addr = len == 0 ? 0L : journal.write(ByteBuffer.wrap(b, off, len)); // form the key for the index entry for this block. final byte[] key = keyBuilder .reset() .appendText(id, true /* unicode */, false /* successor */) .append(version) .append(block) .getKey(); // record the address of the block in the index. final boolean overwrite; { final DataOutputBuffer out = new DataOutputBuffer(Bytes.SIZEOF_LONG); // encode the value for the entry. out.reset().putLong(addr); final byte[] val = out.toByteArray(); // insert the entry into the index. overwrite = ndx.insert(key, val) != null; } log.info( "Wrote " + len + " bytes : id=" + id + ", version=" + version + ", block#=" + block + " @ addr" + journal.toString(addr) + ", overwrite=" + overwrite); return Boolean.valueOf(overwrite); } @Override public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { id = in.readUTF(); version = in.readInt(); block = in.readLong(); off = 0; // Note: offset always zero when de-serialized. len = in.readInt(); b = new byte[len]; in.readFully(b); } @Override public void writeExternal(final ObjectOutput out) throws IOException { out.writeUTF(id); out.writeInt(version); out.writeLong(block); /* * Note: offset not written when serialized and always zero when * de-serialized. */ out.writeInt(len); /* length */ out.write(b, off, len); /* data */ } }
private void printLoggerInfo(Logger logger, PrintStream out) { out.println(levelToString(logger.getEffectiveLevel()) + "\t\t" + logger.getName()); }