-
Notifications
You must be signed in to change notification settings - Fork 17
Log API Improvements #974
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
base: master
Are you sure you want to change the base?
Log API Improvements #974
Changes from all commits
c6c58e5
0390aff
9fe1f5d
5757ac4
1434503
019dd90
87c7b43
fb92557
466e167
d9bf16e
ca17eb5
4c6e64c
bce840b
f5a2d66
9cc80d0
ebb9788
018e64e
dd7a0f8
940f24a
3381ea9
89380c4
49b138d
70e2f65
33f00db
569f8a3
c26b06e
15dcce7
c9e9a2f
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 |
---|---|---|
@@ -1,14 +1,24 @@ | ||
package com.genexus.diagnostics; | ||
|
||
public class LogLevel { | ||
|
||
static final int OFF = 0; | ||
static final int TRACE = 1; | ||
static final int DEBUG = 5; | ||
static final int INFO = 10; | ||
static final int WARNING = 15; | ||
static final int ERROR = 20; | ||
static final int FATAL = 30; | ||
|
||
|
||
public enum LogLevel { | ||
OFF(0), | ||
TRACE(1), | ||
DEBUG(5), | ||
INFO(10), | ||
WARN(15), | ||
ERROR(20), | ||
FATAL(30); | ||
|
||
private final int lvl; | ||
LogLevel(int lvl) { this.lvl = lvl; } | ||
public int intValue() { return lvl; } | ||
|
||
public static LogLevel fromInt(int lvl) { | ||
for (LogLevel level : LogLevel.values()) { | ||
if (level.intValue() == lvl) { | ||
return level; | ||
} | ||
} | ||
return LogLevel.OFF; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.genexus.diagnostics.core.provider; | ||
|
||
import org.apache.logging.log4j.core.config.plugins.Plugin; | ||
import org.apache.logging.log4j.core.config.plugins.PluginFactory; | ||
import org.apache.logging.log4j.layout.template.json.resolver.EventResolverContext; | ||
import org.apache.logging.log4j.layout.template.json.resolver.EventResolverFactory; | ||
import org.apache.logging.log4j.layout.template.json.resolver.TemplateResolverConfig; | ||
import org.apache.logging.log4j.layout.template.json.resolver.TemplateResolverFactory; | ||
|
||
|
||
@Plugin(name = "CustomMessage", category = TemplateResolverFactory.CATEGORY) | ||
public final class CustomMessageFactory implements EventResolverFactory { | ||
private static final CustomMessageFactory INSTANCE = new CustomMessageFactory(); | ||
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. Right now you have a package-private default constructor (implicit), plus a single INSTANCE. It’s clearer to readers if you explicitly prevent instantiation
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. |
||
private CustomMessageFactory() { /* no instances */ } | ||
|
||
@PluginFactory | ||
public static CustomMessageFactory getInstance() { | ||
return INSTANCE; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return CustomMessageResolver.getName(); | ||
} | ||
|
||
@Override | ||
public CustomMessageResolver create(EventResolverContext context, TemplateResolverConfig config) { | ||
return new CustomMessageResolver(config); | ||
} | ||
} |
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.
Your level constant is called WARNING, but the method is isWarnEnabled(). It’s better if the naming matches exactly (e.g. either rename the constant to WARN or the method to isWarningEnabled())
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.
Fix: Rename constant to WARN