Java Code Examples for org.apache.commons.logging.Log#isTraceEnabled()
The following examples show how to use
org.apache.commons.logging.Log#isTraceEnabled() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MachOLoader.java From unidbg with Apache License 2.0 | 6 votes |
private void rebaseAt(Log log, int type, long address, Module module) { Pointer pointer = UnicornPointer.pointer(emulator, address); if (pointer == null) { throw new IllegalStateException(); } Pointer newPointer = pointer.getPointer(0); Pointer old = newPointer; if (newPointer == null) { newPointer = UnicornPointer.pointer(emulator, module.base); } else { newPointer = newPointer.share(module.base); } if (log.isTraceEnabled()) { log.trace("rebaseAt type=" + type + ", address=0x" + Long.toHexString(address - module.base) + ", module=" + module.name + ", old=" + old + ", new=" + newPointer); } switch (type) { case REBASE_TYPE_POINTER: case REBASE_TYPE_TEXT_ABSOLUTE32: pointer.setPointer(0, newPointer); break; default: throw new IllegalStateException("bad rebase type " + type); } }
Example 2
Source File: ConfigFileFinder.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 6 votes |
public boolean readFile(Reader reader, String readFrom, String path, String baseUrl, Log log) { // At the moment it is assumed the file is Json, but that does not need to be the case. // We have the path including extension. boolean successReadingConfig = true; try { JsonNode jsonNode = jsonObjectMapper.readValue(reader, JsonNode.class); String readFromMessage = readFrom + ' ' + path; if (log.isTraceEnabled()) { log.trace(readFromMessage + " config is: " + jsonNode); } else { log.debug(readFromMessage + " config read"); } readJson(jsonNode, readFromMessage, baseUrl); } catch (Exception e) { log.error("Error reading "+path, e); successReadingConfig = false; } return successReadingConfig; }
Example 3
Source File: HeartBeat.java From elasticsearch-hadoop with Apache License 2.0 | 5 votes |
HeartBeat(final Progressable progressable, Configuration cfg, TimeValue lead, final Log log) { Assert.notNull(progressable, "a valid progressable is required to report status to Hadoop"); TimeValue tv = HadoopCfgUtils.getTaskTimeout(cfg); Assert.isTrue(tv.getSeconds() <= 0 || tv.getSeconds() > lead.getSeconds(), "Hadoop timeout is shorter than the heartbeat"); this.progressable = progressable; long cfgMillis = (tv.getMillis() > 0 ? tv.getMillis() : 0); // the task is simple hence the delay = timeout - lead, that is when to start the notification right before the timeout this.delay = new TimeValue(Math.abs(cfgMillis - lead.getMillis()), TimeUnit.MILLISECONDS); this.log = log; String taskId; TaskID taskID = HadoopCfgUtils.getTaskID(cfg); if (taskID == null) { log.warn("Cannot determine task id..."); taskId = "<unknown>"; if (log.isTraceEnabled()) { log.trace("Current configuration is " + HadoopCfgUtils.asProperties(cfg)); } } else { taskId = "" + taskID; } id = taskId; }
Example 4
Source File: RMServerUtils.java From big-c with Apache License 2.0 | 5 votes |
/** * Utility method to verify if the current user has access based on the * passed {@link AccessControlList} * @param authorizer the {@link AccessControlList} to check against * @param method the method name to be logged * @param module like AdminService or NodeLabelManager * @param LOG the logger to use * @return {@link UserGroupInformation} of the current user * @throws IOException */ public static UserGroupInformation verifyAdminAccess( YarnAuthorizationProvider authorizer, String method, String module, final Log LOG) throws IOException { UserGroupInformation user; try { user = UserGroupInformation.getCurrentUser(); } catch (IOException ioe) { LOG.warn("Couldn't get current user", ioe); RMAuditLogger.logFailure("UNKNOWN", method, "", "AdminService", "Couldn't get current user"); throw ioe; } if (!authorizer.isAdmin(user)) { LOG.warn("User " + user.getShortUserName() + " doesn't have permission" + " to call '" + method + "'"); RMAuditLogger.logFailure(user.getShortUserName(), method, "", module, RMAuditLogger.AuditConstants.UNAUTHORIZED_USER); throw new AccessControlException("User " + user.getShortUserName() + " doesn't have permission" + " to call '" + method + "'"); } if (LOG.isTraceEnabled()) { LOG.trace(method + " invoked by user " + user.getShortUserName()); } return user; }
Example 5
Source File: RMServerUtils.java From hadoop with Apache License 2.0 | 5 votes |
/** * Utility method to verify if the current user has access based on the * passed {@link AccessControlList} * @param authorizer the {@link AccessControlList} to check against * @param method the method name to be logged * @param module like AdminService or NodeLabelManager * @param LOG the logger to use * @return {@link UserGroupInformation} of the current user * @throws IOException */ public static UserGroupInformation verifyAdminAccess( YarnAuthorizationProvider authorizer, String method, String module, final Log LOG) throws IOException { UserGroupInformation user; try { user = UserGroupInformation.getCurrentUser(); } catch (IOException ioe) { LOG.warn("Couldn't get current user", ioe); RMAuditLogger.logFailure("UNKNOWN", method, "", "AdminService", "Couldn't get current user"); throw ioe; } if (!authorizer.isAdmin(user)) { LOG.warn("User " + user.getShortUserName() + " doesn't have permission" + " to call '" + method + "'"); RMAuditLogger.logFailure(user.getShortUserName(), method, "", module, RMAuditLogger.AuditConstants.UNAUTHORIZED_USER); throw new AccessControlException("User " + user.getShortUserName() + " doesn't have permission" + " to call '" + method + "'"); } if (LOG.isTraceEnabled()) { LOG.trace(method + " invoked by user " + user.getShortUserName()); } return user; }
Example 6
Source File: Trace.java From sissi with Apache License 2.0 | 4 votes |
public static void trace(Log log, Throwable e) { if (log.isTraceEnabled()) { e.printStackTrace(); } }
Example 7
Source File: RestService.java From elasticsearch-hadoop with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") public static List<PartitionDefinition> findPartitions(Settings settings, Log log) { Version.logVersion(); InitializationUtils.validateSettings(settings); ClusterInfo clusterInfo = InitializationUtils.discoverClusterInfo(settings, log); InitializationUtils.validateSettingsForReading(settings); List<NodeInfo> nodes = InitializationUtils.discoverNodesIfNeeded(settings, log); InitializationUtils.filterNonClientNodesIfNeeded(settings, log); InitializationUtils.filterNonDataNodesIfNeeded(settings, log); InitializationUtils.filterNonIngestNodesIfNeeded(settings, log); RestRepository client = new RestRepository(settings); try { boolean indexExists = client.resourceExists(true); List<List<Map<String, Object>>> shards = null; if (!indexExists) { if (settings.getIndexReadMissingAsEmpty()) { log.info(String.format("Index [%s] missing - treating it as empty", settings.getResourceRead())); shards = Collections.emptyList(); } else { throw new EsHadoopIllegalArgumentException( String.format("Index [%s] missing and settings [%s] is set to false", settings.getResourceRead(), ConfigurationOptions.ES_INDEX_READ_MISSING_AS_EMPTY)); } } else { shards = client.getReadTargetShards(); if (log.isTraceEnabled()) { log.trace("Creating splits for shards " + shards); } } log.info(String.format("Reading from [%s]", settings.getResourceRead())); MappingSet mapping = null; if (!shards.isEmpty()) { mapping = client.getMappings(); if (log.isDebugEnabled()) { log.debug(String.format("Discovered resolved mapping {%s} for [%s]", mapping.getResolvedView(), settings.getResourceRead())); } // validate if possible FieldPresenceValidation validation = settings.getReadFieldExistanceValidation(); if (validation.isRequired()) { MappingUtils.validateMapping(SettingsUtils.determineSourceFields(settings), mapping.getResolvedView(), validation, log); } } final Map<String, NodeInfo> nodesMap = new HashMap<String, NodeInfo>(); if (nodes != null) { for (NodeInfo node : nodes) { nodesMap.put(node.getId(), node); } } final List<PartitionDefinition> partitions; if (clusterInfo.getMajorVersion().onOrAfter(EsMajorVersion.V_5_X) && settings.getMaxDocsPerPartition() != null) { partitions = findSlicePartitions(client.getRestClient(), settings, mapping, nodesMap, shards, log); } else { partitions = findShardPartitions(settings, mapping, nodesMap, shards, log); } Collections.shuffle(partitions); return partitions; } finally { client.close(); } }
Example 8
Source File: HttpRangeProcessor.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
/** * Stream a range of bytes from the given InputStream to the ServletOutputStream * * @param r Byte Range to process * @param is InputStream * @param os ServletOutputStream * @param offset Assumed InputStream position - to calculate skip bytes from * */ private void streamRangeBytes(final Range r, final InputStream is, final OutputStream os, long offset) throws IOException { final Log logger = getLogger(); final boolean trace = logger.isTraceEnabled(); // TODO: investigate using getFileChannel() on ContentReader if (r.start != 0L && r.start > offset) { long skipped = offset + is.skip(r.start - offset); if (skipped < r.start) { // Nothing left to download! return; } } long span = (r.end - r.start) + 1L; long bytesLeft = span; int read = 0; // Check that bytesLeft isn't greater than int can hold int bufSize; if (bytesLeft >= Integer.MAX_VALUE - 8) { bufSize = CHUNKSIZE; } else { bufSize = ((int)bytesLeft) < CHUNKSIZE ? (int)bytesLeft : CHUNKSIZE; } byte[] buf = new byte[bufSize]; while ((read = is.read(buf)) > 0 && bytesLeft != 0L) { os.write(buf, 0, read); bytesLeft -= (long)read; if (bytesLeft != 0L) { int resize; if (bytesLeft >= Integer.MAX_VALUE - 8) { resize = CHUNKSIZE; } else { resize = ((int)bytesLeft) < CHUNKSIZE ? (int)bytesLeft : CHUNKSIZE; } if (resize != buf.length) { buf = new byte[resize]; } } if (trace) logger.trace("...wrote " + read + " bytes, with " + bytesLeft + " to go..."); } }
Example 9
Source File: ScriptResourceHelper.java From alfresco-core with GNU Lesser General Public License v3.0 | 4 votes |
/** * Recursively resolve imports in the specified scripts, adding the imports to the * specific list of scriplets to combine later. * * @param location Script location - used to ensure duplicates are not added * @param script The script to recursively resolve imports for * @param scripts The collection of scriplets to execute with imports resolved and removed */ private static void recurseScriptImports( String location, String script, ScriptResourceLoader loader, Map<String, String> scripts, Log logger) { int index = 0; // skip any initial whitespace for (; index<script.length(); index++) { if (Character.isWhitespace(script.charAt(index)) == false) { break; } } // look for the "<import" directive marker if (script.startsWith(IMPORT_PREFIX, index)) { // skip whitespace between "<import" and "resource" boolean afterWhitespace = false; index += IMPORT_PREFIX.length() + 1; for (; index<script.length(); index++) { if (Character.isWhitespace(script.charAt(index)) == false) { afterWhitespace = true; break; } } if (afterWhitespace == true && script.startsWith(IMPORT_RESOURCE, index)) { // found an import line! index += IMPORT_RESOURCE.length(); int resourceStart = index; for (; index<script.length(); index++) { if (script.charAt(index) == '"' && script.charAt(index + 1) == '>') { // found end of import line - so we have a resource path String resource = script.substring(resourceStart, index); if (logger.isDebugEnabled()) logger.debug("Found script resource import: " + resource); if (scripts.containsKey(resource) == false) { // load the script resource (and parse any recursive includes...) String includedScript = loader.loadScriptResource(resource); if (includedScript != null) { if (logger.isDebugEnabled()) logger.debug("Succesfully located script '" + resource + "'"); recurseScriptImports(resource, includedScript, loader, scripts, logger); } } else { if (logger.isDebugEnabled()) logger.debug("Note: already imported resource: " + resource); } // continue scanning this script for additional includes // skip the last two characters of the import directive for (index += 2; index<script.length(); index++) { if (Character.isWhitespace(script.charAt(index)) == false) { break; } } recurseScriptImports(location, script.substring(index), loader, scripts, logger); return; } } // if we get here, we failed to find the end of an import line throw new ScriptException( "Malformed 'import' line - must be first in file, no comments and strictly of the form:" + "\r\n<import resource=\"...\">"); } else { throw new ScriptException( "Malformed 'import' line - must be first in file, no comments and strictly of the form:" + "\r\n<import resource=\"...\">"); } } else { // no (further) includes found - include the original script content if (logger.isDebugEnabled()) logger.debug("Imports resolved, adding resource '" + location); if (logger.isTraceEnabled()) logger.trace(script); scripts.put(location, script); } }
Example 10
Source File: ServletServerHttpRequest.java From java-technology-stack with MIT License | 4 votes |
protected final void logBytesRead(int read) { Log rsReadLogger = AbstractListenerReadPublisher.rsReadLogger; if (rsReadLogger.isTraceEnabled()) { rsReadLogger.trace(getLogPrefix() + "Read " + read + (read != -1 ? " bytes" : "")); } }
Example 11
Source File: ServletServerHttpRequest.java From spring-analysis-note with MIT License | 4 votes |
protected final void logBytesRead(int read) { Log rsReadLogger = AbstractListenerReadPublisher.rsReadLogger; if (rsReadLogger.isTraceEnabled()) { rsReadLogger.trace(getLogPrefix() + "Read " + read + (read != -1 ? " bytes" : "")); } }
Example 12
Source File: LogUtils.java From alfresco-bulk-import with Apache License 2.0 | 4 votes |
public final static boolean trace(final Log log) { return(log.isTraceEnabled()); }
Example 13
Source File: LogFormatUtils.java From java-technology-stack with MIT License | 3 votes |
/** * Use this to log a message with different levels of detail (or different * messages) at TRACE vs DEBUG log levels. Effectively, a substitute for: * <pre class="code"> * if (logger.isDebugEnabled()) { * String str = logger.isTraceEnabled() ? "..." : "..."; * if (logger.isTraceEnabled()) { * logger.trace(str); * } * else { * logger.debug(str); * } * } * </pre> * @param logger the logger to use to log the message * @param messageFactory function that accepts a boolean set to the value * of {@link Log#isTraceEnabled()} */ public static void traceDebug(Log logger, Function<Boolean, String> messageFactory) { if (logger.isDebugEnabled()) { String logMessage = messageFactory.apply(logger.isTraceEnabled()); if (logger.isTraceEnabled()) { logger.trace(logMessage); } else { logger.debug(logMessage); } } }
Example 14
Source File: LogFormatUtils.java From spring-analysis-note with MIT License | 3 votes |
/** * Use this to log a message with different levels of detail (or different * messages) at TRACE vs DEBUG log levels. Effectively, a substitute for: * <pre class="code"> * if (logger.isDebugEnabled()) { * String str = logger.isTraceEnabled() ? "..." : "..."; * if (logger.isTraceEnabled()) { * logger.trace(str); * } * else { * logger.debug(str); * } * } * </pre> * @param logger the logger to use to log the message * @param messageFactory function that accepts a boolean set to the value * of {@link Log#isTraceEnabled()} */ public static void traceDebug(Log logger, Function<Boolean, String> messageFactory) { if (logger.isDebugEnabled()) { boolean traceEnabled = logger.isTraceEnabled(); String logMessage = messageFactory.apply(traceEnabled); if (traceEnabled) { logger.trace(logMessage); } else { logger.debug(logMessage); } } }
Example 15
Source File: SwiftUtils.java From sahara-extra with Apache License 2.0 | 2 votes |
/** * Sprintf() to the log iff the log is at trace level. If the log * is not at trace level, the printf operation is skipped, so * no time is spent generating the string. * @param log log to use * @param text text message * @param args args arguments to the print statement */ public static void trace(Log log, String text, Object... args) { if (log.isTraceEnabled()) { log.trace(String.format(text, args)); } }
Example 16
Source File: SwiftUtils.java From hadoop with Apache License 2.0 | 2 votes |
/** * Sprintf() to the log iff the log is at trace level. If the log * is not at trace level, the printf operation is skipped, so * no time is spent generating the string. * @param log log to use * @param text text message * @param args args arguments to the print statement */ public static void trace(Log log, String text, Object... args) { if (log.isTraceEnabled()) { log.trace(String.format(text, args)); } }
Example 17
Source File: AbstractTraceInterceptor.java From java-technology-stack with MIT License | 2 votes |
/** * Determine whether the given {@link Log} instance is enabled. * <p>Default is {@code true} when the "trace" level is enabled. * Subclasses can override this to change the level under which 'tracing' occurs. * @param logger the {@code Log} instance to check */ protected boolean isLogEnabled(Log logger) { return logger.isTraceEnabled(); }
Example 18
Source File: AbstractTraceInterceptor.java From spring4-understanding with Apache License 2.0 | 2 votes |
/** * Determine whether the given {@link Log} instance is enabled. * <p>Default is {@code true} when the "trace" level is enabled. * Subclasses can override this to change the level under which 'tracing' occurs. * @param logger the {@code Log} instance to check */ protected boolean isLogEnabled(Log logger) { return logger.isTraceEnabled(); }
Example 19
Source File: SwiftUtils.java From big-c with Apache License 2.0 | 2 votes |
/** * Sprintf() to the log iff the log is at trace level. If the log * is not at trace level, the printf operation is skipped, so * no time is spent generating the string. * @param log log to use * @param text text message * @param args args arguments to the print statement */ public static void trace(Log log, String text, Object... args) { if (log.isTraceEnabled()) { log.trace(String.format(text, args)); } }
Example 20
Source File: AbstractTraceInterceptor.java From spring-analysis-note with MIT License | 2 votes |
/** * Determine whether the given {@link Log} instance is enabled. * <p>Default is {@code true} when the "trace" level is enabled. * Subclasses can override this to change the level under which 'tracing' occurs. * @param logger the {@code Log} instance to check */ protected boolean isLogEnabled(Log logger) { return logger.isTraceEnabled(); }