Skip to content
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

feat(#464) add date time cli option #471

Merged
merged 2 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class LoggerSettings {
public final boolean isQuiet;
public final boolean isDebug;
public final boolean isTrace;
public final boolean isShowDateTime;

public final List<String> properties;
public final String propertyFileName;
Expand All @@ -33,6 +34,8 @@ public LoggerSettings(TransformOptions options) {
this.isDebug = options.hasOption(AppOption.LOG_DEBUG);
this.isTrace = options.hasOption(AppOption.LOG_TRACE);

this.isShowDateTime = options.hasOption(AppOption.LOG_SHOW_DATE_TIME);

this.properties = options.getOptionValues(AppOption.LOG_PROPERTY);
this.propertyFileName = options.normalize(options.getOptionValue(AppOption.LOG_PROPERTY_FILE));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
* The format to use for date and time values which are included in log messages.
* Formats are specified according to:
* <a href="http://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat</a>.
* Defaults to display the the number of milliseconds since the logger was
* Defaults to display the number of milliseconds since the logger was
* initialized. The default is used if a non-valid format is specified.
*
* org.slf4j.simpleLogger.showThreadName
Expand Down Expand Up @@ -165,6 +165,12 @@ private void setLoggingProperties(String loggerName) {
setLoggingProperty(LoggerProperty.LOG_LEVEL_PREFIX + loggerName, "error");
}

// this is a shortcut to avoid below properties
if (settings.isShowDateTime) {
setLoggingProperty(LoggerProperty.LOG_SHOW_DATE_TIME.toString(), "true");
setLoggingProperty(LoggerProperty.LOG_DATE_TIME_FORMAT.toString(), "yyyy.MM.dd 'at' HH:mm:ss z");
}

if (settings.properties != null) {
for (String propertyAssignment : settings.properties) {
assignLoggingProperty(propertyAssignment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public enum AppOption {
LOG_TRACE(
new Settings("x", "trace", "Display trace output: trace level logging", !Settings.HAS_ARG, !Settings.HAS_ARGS,
!Settings.IS_REQUIRED, "LOG_GROUP")),
LOG_SHOW_DATE_TIME(
new Settings("ldt", "logShowDateTime", "Show date and time in log statements. Shortcut for -lp bellow with showDateTime and dateTimeFormat.",
!Settings.HAS_ARG, !Settings.HAS_ARGS, !Settings.IS_REQUIRED, Settings.NO_GROUP)),
LOG_PROPERTY(new Settings("lp", "logProperty", "Logging property", !Settings.HAS_ARG, Settings.HAS_ARGS,
!Settings.IS_REQUIRED, Settings.NO_GROUP)),
LOG_PROPERTY_FILE(new Settings("lpf", "logPropertyFile", "Logging properties file", Settings.HAS_ARG,
Expand Down