Skip to content

Commit

Permalink
Merge pull request #471 from jeanouii/feat/463/add-date-time-cli-option
Browse files Browse the repository at this point in the history
feat(#464) add date time cli option
  • Loading branch information
bjhargrave authored Jun 7, 2023
2 parents 175164a + dc09c76 commit 28ee51a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
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

0 comments on commit 28ee51a

Please sign in to comment.