Skip to content

Commit

Permalink
feat: use timestap for log message
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Miura <[email protected]>
  • Loading branch information
miurahr committed Jul 8, 2024
1 parent 77525c6 commit 7cca083
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/org/omegat/logger.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ org.omegat.level = ALL
java.util.logging.ConsoleHandler.level = ALL
org.omegat.util.logging.OmegaTFileHandler.level = ALL

org.omegat.util.logging.OmegaTLogFormatter.mask=$mark: $level: $text $key
org.omegat.util.logging.OmegaTLogFormatter.mask=$time: $level: $text $key
#org.omegat.util.logging.OmegaTLogFormatter.mask=$time: $threadName [$level] $key $text
#org.omegat.util.logging.OmegaTLogFormatter.mask=$mark: $level: $text $key

org.omegat.util.logging.OmegaTLogFormatter.timeFormat=HH:mm:ss,SSSS
org.omegat.util.logging.OmegaTLogFormatter.timeFormat=HH:mm:ss.SSS

java.util.logging.ConsoleHandler.formatter = org.omegat.util.logging.OmegaTLogFormatter

org.omegat.util.logging.OmegaTFileHandler.formatter = org.omegat.util.logging.OmegaTLogFormatter
org.omegat.util.logging.OmegaTFileHandler.size=1048576
org.omegat.util.logging.OmegaTFileHandler.count=10
# 20 days * 24 hours * 60 min * 60 sec = 1,020,000 seconds
org.omegat.util.logging.OmegaTFileHandler.retention=1020000

# precise control of log levels, please change when debug
org.omegat.core.data.level = INFO
Expand Down
7 changes: 3 additions & 4 deletions src/org/omegat/util/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Properties;
import java.util.concurrent.ThreadLocalRandom;
import java.util.logging.Formatter;
Expand Down Expand Up @@ -63,14 +62,14 @@ public final class Log {

// Line mark is day-of-the-year and five-character random number
private static final String SESSION_ID;
private static final String SESSION_START_DATETIME;
private static final ZonedDateTime SESSION_START_DATETIME;

private Log() {
}

static {
SESSION_ID = String.format("%05d", ThreadLocalRandom.current().nextInt(100000));
SESSION_START_DATETIME = DateTimeFormatter.ofPattern("yyyyMMddHHmmss").format(ZonedDateTime.now());
SESSION_START_DATETIME = ZonedDateTime.now();
LOGGER = LoggerFactory.getLogger(ILogger.ROOT_LOGGER_NAME,
OStrings.getResourceBundle());
init();
Expand All @@ -80,7 +79,7 @@ public static String getSessionId() {
return SESSION_ID;
}

public static String getSessionStartDateTime() {
public static ZonedDateTime getSessionStartDateTime() {
return SESSION_START_DATETIME;
}

Expand Down
3 changes: 2 additions & 1 deletion src/org/omegat/util/logging/OmegaTFileHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
import java.time.format.DateTimeFormatter;
import java.util.logging.ErrorManager;
import java.util.logging.Level;
import java.util.logging.LogManager;
Expand Down Expand Up @@ -115,7 +116,7 @@ private void openFiles(final File dir) throws IOException {
boolean ignored = dir.mkdirs();
for (int instanceIndex = 0; instanceIndex < 100; instanceIndex++) {
String fileName = String.format("%s_%s_%s%s", OStrings.getApplicationName(), Log.getSessionId(),
Log.getSessionStartDateTime(),
DateTimeFormatter.ofPattern("yyyyMMdd-HHmmss").format(Log.getSessionStartDateTime()),
// Instance index
instanceIndex > 0 ? ("-" + instanceIndex) : "");

Expand Down

0 comments on commit 7cca083

Please sign in to comment.