-
Notifications
You must be signed in to change notification settings - Fork 54
@W-10459671@ Provide progress information of SFGE on verbose mode #792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
07bf137
2def31f
56fed64
e97100d
3b5a855
88bd84f
978e49c
fd3af9c
8fd2044
5acf779
805ca8c
6776803
a995ba5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,8 @@ | |
|
|
||
| public enum EventKey { | ||
| // MAKE SURE `messageKey` OF EVERY VALUE ADDED HERE HAS AN ENTRY IN 'messages/EventKeyTemplates.js'! | ||
|
|
||
| /** PMD-CATALOGER RELATED **/ | ||
| INFO_GENERAL_INTERNAL_LOG("info.generalInternalLog", 1, MessageType.INFO, MessageHandler.INTERNAL, true), | ||
| WARNING_INVALID_CAT_SKIPPED("warning.invalidCategorySkipped", 1, MessageType.WARNING, MessageHandler.UX, true), | ||
| WARNING_INVALID_RULESET_SKIPPED("warning.invalidRulesetSkipped", 1, MessageType.WARNING, MessageHandler.UX, true), | ||
|
|
@@ -20,8 +22,23 @@ public enum EventKey { | |
| ERROR_EXTERNAL_RECURSION_LIMIT("error.external.recursionLimitReached", 2, MessageType.ERROR, MessageHandler.UX, false), | ||
| ERROR_EXTERNAL_XML_NOT_READABLE("error.external.xmlNotReadable", 2, MessageType.ERROR, MessageHandler.UX, false), | ||
| ERROR_EXTERNAL_XML_NOT_PARSABLE("error.external.xmlNotParsable", 2, MessageType.ERROR, MessageHandler.UX, false), | ||
|
|
||
|
|
||
|
|
||
|
|
||
| /** SFGE RELATED **/ | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New event keys to match the new messages |
||
| INFO_GENERAL("info.sfgeInfoLog", 1, MessageType.INFO, MessageHandler.UX, true), | ||
| INFO_META_INFO_COLLECTED("info.sfgeMetaInfoCollected", 2, MessageType.INFO, MessageHandler.UX, true), | ||
| INFO_COMPLETED_FILE_COMPILATION("info.sfgeFinishedCompilingFiles", 1, MessageType.INFO, MessageHandler.UX_SPINNER, false), | ||
| INFO_STARTED_BUILDING_GRAPH("info.sfgeStartedBuildingGraph", 0, MessageType.INFO, MessageHandler.UX_SPINNER, false), | ||
| INFO_COMPLETED_BUILDING_GRAPH("info.sfgeFinishedBuildingGraph", 0, MessageType.INFO, MessageHandler.UX_SPINNER, false), | ||
| INFO_PATH_ENTRY_POINTS_IDENTIFIED("info.sfgePathEntryPointsIdentified", 1, MessageType.INFO, MessageHandler.UX_SPINNER, false), | ||
| INFO_PATH_ANALYSIS_PROGRESS("info.sfgeViolationsInPathProgress", 4, MessageType.INFO, MessageHandler.UX_SPINNER, false), | ||
| INFO_COMPLETED_PATH_ANALYSIS("info.sfgeCompletedPathAnalysis", 3, MessageType.INFO, MessageHandler.UX_SPINNER, false), | ||
| WARNING_GENERAL("warning.sfgeWarnLog", 1, MessageType.WARNING, MessageHandler.UX, true), | ||
| WARNING_MULTIPLE_METHOD_TARGET_MATCHES("warning.multipleMethodTargetMatches", 3, MessageType.WARNING, MessageHandler.UX, false), | ||
| WARNING_NO_METHOD_TARGET_MATCHES("warning.noMethodTargetMatches", 2, MessageType.WARNING, MessageHandler.UX, false); | ||
| WARNING_NO_METHOD_TARGET_MATCHES("warning.noMethodTargetMatches", 2, MessageType.WARNING, MessageHandler.UX, false), | ||
| ERROR_GENERAL("error.internal.sfgeErrorLog", 1, MessageType.ERROR, MessageHandler.UX, false); | ||
|
|
||
| final String messageKey; | ||
| final int argCount; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| package com.salesforce; | ||
|
|
||
| import com.salesforce.config.SfgeConfigProvider; | ||
| import com.salesforce.messaging.CliMessager; | ||
| import com.salesforce.messaging.EventKey; | ||
| import java.io.Serializable; | ||
| import org.apache.logging.log4j.Level; | ||
| import org.apache.logging.log4j.core.Appender; | ||
| import org.apache.logging.log4j.core.Core; | ||
| import org.apache.logging.log4j.core.Filter; | ||
| import org.apache.logging.log4j.core.Layout; | ||
| import org.apache.logging.log4j.core.LogEvent; | ||
| import org.apache.logging.log4j.core.appender.AbstractAppender; | ||
| import org.apache.logging.log4j.core.config.plugins.Plugin; | ||
| import org.apache.logging.log4j.core.config.plugins.PluginAttribute; | ||
| import org.apache.logging.log4j.core.config.plugins.PluginElement; | ||
| import org.apache.logging.log4j.core.config.plugins.PluginFactory; | ||
| import org.apache.logging.log4j.core.layout.PatternLayout; | ||
|
|
||
| /** | ||
| * Custom log4j2 appender to send logs as realtime events through {@link CliMessager}. This helps | ||
| * streamline logs displayed to commandline users. Invoked from log4j.xml. | ||
| */ | ||
| @Plugin( | ||
| name = "CliMessagerAppender", | ||
| category = Core.CATEGORY_NAME, | ||
| elementType = Appender.ELEMENT_TYPE) | ||
| public class CliMessagerAppender extends AbstractAppender { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New log appender that steps in to pass realtime messages when needed. |
||
|
|
||
| private final boolean shouldLogWarningsOnVerbose; | ||
|
|
||
| @PluginFactory | ||
| public static CliMessagerAppender createAppender( | ||
| @PluginAttribute("name") String name, | ||
| @PluginElement("Layout") Layout<? extends Serializable> layout, | ||
| @PluginElement("Filter") final Filter filter) { | ||
| if (name == null) { | ||
| // Assign default name to avoid complaining | ||
| name = "CliMessagerAppender"; | ||
| } | ||
| if (layout == null) { | ||
| layout = PatternLayout.createDefaultLayout(); | ||
| } | ||
| return new CliMessagerAppender(name, filter, layout, true); | ||
| } | ||
|
|
||
| protected CliMessagerAppender( | ||
| String name, | ||
| Filter filter, | ||
| Layout<? extends Serializable> layout, | ||
| final boolean ignoreExceptions) { | ||
| super(name, filter, layout, ignoreExceptions, null); | ||
| this.shouldLogWarningsOnVerbose = SfgeConfigProvider.get().shouldLogWarningsOnVerbose(); | ||
| } | ||
|
|
||
| /** | ||
| * {@link CliMessagerAppender} decrements the log level while publishing to CLI. Warning is | ||
| * reduced to Info, Error is reduced to Warning, Fatal is reduced to Error. | ||
| * | ||
| * @param event that was published from code | ||
| */ | ||
| @Override | ||
| public void append(LogEvent event) { | ||
| Level level = event.getLevel(); | ||
| if (Level.WARN.equals(level) && this.shouldLogWarningsOnVerbose) { | ||
| CliMessager.postMessage( | ||
| "SFGE Warning as Info", EventKey.INFO_GENERAL, getEventMessage(event)); | ||
| } else if (Level.ERROR.equals(level)) { | ||
| CliMessager.postMessage( | ||
| "SFGE Error as Warning", EventKey.WARNING_GENERAL, getEventMessage(event)); | ||
| } else if (Level.FATAL.equals(level)) { | ||
| CliMessager.postMessage( | ||
| "SFGE Fatal as Error", EventKey.ERROR_GENERAL, getEventMessage(event)); | ||
| } else { | ||
| error( | ||
| String.format( | ||
| "Unable to log less than WARN level [{}]: {}", | ||
| event.getLevel(), | ||
| getEventMessage(event))); | ||
| } | ||
| } | ||
|
|
||
| private String getEventMessage(LogEvent event) { | ||
| return event.getMessage().getFormattedMessage(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,4 +16,16 @@ public interface SfgeConfig { | |
|
|
||
| /** Indicates if a Jorje parse error causes the entire process to stop. */ | ||
| boolean shouldIgnoreParseErrors(); | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New config values to control verbose behavior.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need these config values anymore? Would removing them simplify the code? |
||
| /** | ||
| * Indicates if Warn level logs to log4j should be forwarded to CLI as well when verbose is | ||
| * enabled | ||
| */ | ||
| boolean shouldLogWarningsOnVerbose(); | ||
|
|
||
| /** | ||
| * Should be used to set the level of increments at which path analysis progress update is | ||
| * provided | ||
| */ | ||
| int getProgressIncrements(); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating an alternate method to post realtime messages. I've marked the other entry points as deprecated and we can eventually make them realtime as well.