/** * Logs a message. * <p> * If the logger is enabled for the given {@code level} the message is sent to the * {@link Handler} registered in the current {@link Context}. * * @param level the required {@link Level} * @param message the message to log * @since 1.0 */ public void log(final Level level, final String message) { if (!isLoggable(level)) { return; } doLog(level, message, null, null, (Object) null); }
/** * Logs a message with {@link Level#CONFIG config level}. * <p> * If the logger is enabled for the {@link Level#CONFIG config level} the message is sent to the * {@link Handler} registered in the current {@link Context}. * * @param message the message to log * @since 1.0 */ public void config(final String message) { log(Level.CONFIG, message); }
/** * Logs entry into method with multiple parameters. * <p> * This method can be used to log entry into a method. A {@link LogRecord} with message "ENTRY", * the given {@code sourceMethod} and {@code sourceClass} and given parameters is logged with * {@link Level#FINER finer level}. * * @param sourceClass the entered class * @param sourceMethod the entered method * @param parameters the method parameters * @since 1.0 */ public void entering(final String sourceClass, final String sourceMethod, final Object[] parameters) { String msg = "ENTRY"; if (parameters == null) { logp(Level.FINER, sourceClass, sourceMethod, msg); return; } if (!isLoggable(Level.FINER)) { return; } for (int i = 0; i < parameters.length; i++) { msg = msg + " {" + i + "}"; } logp(Level.FINER, sourceClass, sourceMethod, msg, parameters); }
private void updateLevelNum(boolean singleContext) { int value; if (levelObj != null) { value = levelObj.intValue(); if (parent != null && !singleContext) { value = Math.min(value, parent.getLevelNum()); } } else if (parent != null) { value = parent.getLevelNum(); } else { value = DEFAULT_VALUE; } setLevelNum(value); if (children != null) { for (ChildLoggerRef ref : children) { final TruffleLogger logger = ref.get(); if (logger != null) { logger.updateLevelNum(singleContext); } } } }
@CompilerDirectives.TruffleBoundary private void doLog( final Level level, final String message, final String className, final String methodName, final Object[] params) { final LogRecord logRecord = TruffleLanguage.AccessAPI.engineAccess().createLogRecord( level, getName(), message, className, methodName, params, null); callHandlers(logRecord); }
/** * Find or create a logger for a given language or instrument class. If a logger for the class * already exists it's returned, otherwise a new logger is created. * * @param id the unique id of language or instrument * @param forClass the {@link Class} to create a logger for * @return a {@link Logger} * @throws NullPointerException if {@code id} or {@code forClass} is null * @since 1.0 */ public static TruffleLogger getLogger(final String id, final Class<?> forClass) { Objects.requireNonNull(forClass, "Class must be non null."); return getLogger(id, forClass.getName()); }
private static boolean shouldLogPhases() { return LOG_PHASES.isLoggable(Level.FINER); }
elapsedTimeMain = timer.getElapsed(); LOG_COMPILER_FALLBACK.finer(() -> "Primary compiler used: " + regexSource); } catch (UnsupportedRegexException mainBailout) { LOG_BAILOUT_MESSAGES.fine(() -> mainBailout.getReason() + ": " + regexSource); try { if (shouldLog) { elapsedTimeFallback = timer.getElapsed(); LOG_COMPILER_FALLBACK.fine(() -> String.format("Secondary compiler used (primary bailout due to '%s'): %s", mainBailout.getReason(), regexSource)); } catch (UnsupportedRegexException fallbackBailout) { LOG_COMPILER_FALLBACK.fine(() -> String.format("No compiler handled following regex (primary bailout: '%s'; secondary bailout: '%s'): %s", mainBailout.getReason(), fallbackBailout.getReason(), regexSource)); String bailoutReasons = String.format("%s; %s", mainBailout.getReason(), fallbackBailout.getReason());
/** * Checks if a message of the given level would be logged by this logger. * * @param level the required logging level * @return true if message is loggable by this logger * @since 1.0 */ public boolean isLoggable(final Level level) { int value = getLevelNum(); if (level.intValue() < value || value == OFF_VALUE) { return false; } final Object currentContext = TruffleLanguage.AccessAPI.engineAccess().getCurrentOuterContext(); if (currentContext == null) { return false; } return isLoggableSlowPath(currentContext, level); }
@CompilerDirectives.TruffleBoundary private void doLog( final Level level, final String message, final String className, final String methodName, final Throwable thrown) { final LogRecord logRecord = TruffleLanguage.AccessAPI.engineAccess().createLogRecord( level, getName(), message, className, methodName, null, thrown); callHandlers(logRecord); }
private boolean setLevelNum(final int value) { if (this.levelNum != value) { this.levelNum = value; final Assumption currentAssumtion = levelNumStable; levelNumStable = Truffle.getRuntime().createAssumption("Log Level Value stable for: " + getName()); currentAssumtion.invalidate(); return true; } return false; }
private void phaseStart(String phase) { if (shouldLogPhases()) { LOG_PHASES.finer(phase + " Start"); timer.start(); } }
private LoggerCache() { this.polyglotRootLogger = new TruffleLogger(); this.loggers = new HashMap<>(); this.loggers.put(ROOT_NAME, new NamedLoggerRef(this.polyglotRootLogger, ROOT_NAME)); this.root = new LoggerNode(null, new NamedLoggerRef(this.polyglotRootLogger, ROOT_NAME)); this.activeContexts = new HashSet<>(); this.effectiveLevels = Collections.emptyMap(); }
private void switchToEagerSearch(RegexProfile profile) { compileEagerSearchNode(); if (eagerSearchNode != EAGER_SEARCH_BAILED_OUT) { LOG_SWITCH_TO_EAGER.fine(() -> "regex " + getSource() + ": switching to eager matching." + (profile == null ? "" : " profile: " + profile)); runRegexSearchNode = insert(eagerSearchNode); } }
@CompilerDirectives.TruffleBoundary private void doLog( final Level level, final Supplier<String> messageSupplier, final String className, final String methodName, final Throwable thrown) { doLog(level, messageSupplier.get(), className, methodName, thrown); }
private synchronized ShadowStack initializeShadowStack() { ShadowStack localShadowStack = shadowStack; if (localShadowStack == null) { assert stacksBinding == null; SourceSectionFilter f = this.filter; if (f == null) { f = DEFAULT_FILTER; } this.shadowStack = localShadowStack = new ShadowStack(stackLimit, f, env.getInstrumenter(), TruffleLogger.getLogger(CPUSamplerInstrument.ID)); this.stacksBinding = this.shadowStack.install(env.getInstrumenter(), combine(f, mode), mode == Mode.EXCLUDE_INLINED_ROOTS); } return localShadowStack; }
private static boolean shouldLogCompilationTime() { return LOG_TOTAL_COMPILATION_TIME.isLoggable(Level.FINE); }
@TruffleBoundary private CompiledRegex compileInternal() { LOG_TREGEX_COMPILATIONS.finer(() -> String.format("TRegex compiling %s\n%s", DebugUtil.jsStringEscape(source.toString()), new RegexUnifier(source).getUnifiedPattern())); createAST(); RegexProperties properties = ast.getProperties(); } catch (UnsupportedRegexException e) { phaseEnd("TraceFinder NFA Bailout"); LOG_BAILOUT_MESSAGES.fine(() -> "TraceFinder: " + e.getReason() + ": " + source);
@CompilerDirectives.TruffleBoundary private boolean isLoggableSlowPath(final Object context, final Level level) { return LoggerCache.getInstance().isLoggable(getName(), context, level); }
private void phaseEnd(String phase) { if (shouldLogPhases()) { LOG_PHASES.finer(phase + " End, elapsed: " + timer.elapsedToString()); } }