-
Notifications
You must be signed in to change notification settings - Fork 77
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
SLVS-1722 Log extra properties of SLCore log events #5924
base: gb/log-context
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -34,25 +34,26 @@ public class LoggerListener : ILoggerListener | |
[ImportingConstructor] | ||
public LoggerListener(ILogger logger) | ||
{ | ||
this.logger = logger; | ||
this.logger = logger.ForContext(SLCoreStrings.SLCoreName, SLCoreStrings.SLCoreInternalLogContext); | ||
} | ||
|
||
public void Log(LogParams parameters) | ||
{ | ||
var message = "[SLCORE] " + parameters.message; | ||
var contextualizedLogger = logger.ForVerboseContext(parameters.loggerName, parameters.configScopeId, parameters.threadName); | ||
|
||
switch (parameters.level) | ||
{ | ||
case LogLevel.ERROR: | ||
case LogLevel.WARN: | ||
logger.WriteLine(message); | ||
case LogLevel.ERROR or LogLevel.WARN: | ||
contextualizedLogger.WriteLine(parameters.message); | ||
break; | ||
|
||
case LogLevel.INFO: | ||
case LogLevel.DEBUG: | ||
case LogLevel.TRACE: | ||
logger.LogVerbose(message); | ||
case LogLevel.INFO or LogLevel.DEBUG or LogLevel.TRACE: | ||
contextualizedLogger.LogVerbose(parameters.message); | ||
break; | ||
} | ||
|
||
if (parameters.stackTrace != null) | ||
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. Move the null check inside the LogVerbose method |
||
{ | ||
contextualizedLogger.LogVerbose(parameters.stackTrace); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,12 @@ namespace SonarLint.VisualStudio.SLCore.Listener.Logger; | |
public class LogParams | ||
{ | ||
public string message; | ||
// nullable | ||
public string configScopeId; | ||
public string threadName; | ||
public string loggerName; | ||
// nullable | ||
public string stackTrace; | ||
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. We are missing the |
||
|
||
[JsonConverter(typeof(StringEnumConverter))] | ||
public LogLevel level; | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
I think it's enough to add just one context that is a string of type "SlCore Logs". It would occupies less space than [SLCore > Logs].