Skip to content

Commit

Permalink
Merge pull request AdoptOpenJDK#672 from AdoptOpenJDK/newLogging
Browse files Browse the repository at this point in the history
New logging
  • Loading branch information
sclassen authored Jul 10, 2020
2 parents 86fce10 + a3a035e commit a5e1a12
Show file tree
Hide file tree
Showing 16 changed files with 129 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -954,8 +954,8 @@ COPuser=user
COPorigin=origin
COPlevel=level
COPdate=date
COPthread1=thread 1
COPthread2=thread 2
COPthreadHash=thread hash
COPthreadName=thread name
COPShowMessages=Show messages
COPstdOut=std. Out
COPstdErr=std. Err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -879,8 +879,8 @@ COPuser=u\u017eivatel
COPorigin=p\u016fvod
COPlevel=\u00farove\u0148
COPdate=datum
COPthread1=vl\u00e1kno 1
COPthread2=vl\u00e1kno 2
COPthreadHash=vl\u00e1kno 1
COPthreadName=vl\u00e1kno 2
COPShowMessages=Zobrazit zpr\u00e1vy:
COPstdOut=std. out
COPstdErr=std. err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -839,8 +839,8 @@ COPuser=Benutzer
COPorigin=Herkunft
COPlevel=Stufe
COPdate=Datum
COPthread1=Ausf\u00FChrungsstrang 1
COPthread2=Ausf\u00FChrungsstrang 2
COPthreadHash=Ausf\u00FChrungsstrang ID
COPthreadName=Ausf\u00FChrungsstrang Name
COPShowMessages=Meldungen anzeigen
COPstdOut=Standardausgabe
COPstdErr=Standardfehlerausgabe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,8 @@ COPuser=U\u017cytkownik
COPorigin=Pochodzenie
COPlevel=Poziom
COPdate=Data
COPthread1=W\u0105tek 1
COPthread2=W\u0105tek 2
COPthreadHash=W\u0105tek 1
COPthreadName=W\u0105tek 2
COPShowMessages=Pokazuj komunikaty:
COPstdOut=Standardowy strumie\u0144 wyj\u015bcia
COPstdErr=Standardowy strumie\u0144 b\u0142\u0119d\u00f3w
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -945,8 +945,8 @@ COPuser=kullan\u0131c\u0131
COPorigin=origin
COPlevel=seviye
COPdate=tarih
COPthread1=thread 1
COPthread2=thread 2
COPthreadHash=thread 1
COPthreadName=thread 2
COPShowMessages=Mesajlar\u0131 g\u00F6ster
COPstdOut=std. Out
COPstdErr=std. Err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import net.sourceforge.jnlp.util.docprovider.ItwebSettingsTextsProvider;
import net.sourceforge.jnlp.util.docprovider.TextsProvider;
import net.sourceforge.jnlp.util.docprovider.formatters.formatters.PlainTextFormatter;
import net.sourceforge.jnlp.util.logging.FileLog;
import net.sourceforge.jnlp.util.logging.OutputController;

import javax.naming.ConfigurationException;
Expand Down Expand Up @@ -73,6 +74,11 @@
*/
public class CommandLine {

static {
// this is placed here above the any thing else to ensure no logger has been created prior to this line
FileLog.setLogFileNamePostfix("settings");
}

private final static Logger LOG = LoggerFactory.getLogger(CommandLine.class);

public static final int ERROR = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
Expand All @@ -32,7 +31,6 @@
import javax.swing.text.Document;
import javax.swing.text.PlainDocument;
import javax.swing.text.html.HTMLDocument;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
Expand Down Expand Up @@ -100,8 +98,8 @@ public ConsoleOutputPane(final ObservableMessagesProvider dataProvider) {
showOrigin = new JCheckBox();
showLevel = new JCheckBox();
showDate = new JCheckBox();
showThread1 = new JCheckBox();
showThread2 = new JCheckBox();
showThreadHash = new JCheckBox();
showThreadName = new JCheckBox();
showMessage = new JCheckBox();
showOut = new JCheckBox();
showErr = new JCheckBox();
Expand Down Expand Up @@ -337,13 +335,13 @@ private final void initComponents() {
showDate.setText(Translator.R("COPdate"));
showDate.addActionListener(getDefaultActionSingleton());

showThread1.setSelected(true);
showThread1.setText(Translator.R("COPthread1"));
showThread1.addActionListener(getDefaultActionSingleton());
showThreadHash.setSelected(true);
showThreadHash.setText(Translator.R("COPthreadHash"));
showThreadHash.addActionListener(getDefaultActionSingleton());

showThread2.setSelected(true);
showThread2.setText(Translator.R("COPthread2"));
showThread2.addActionListener(getDefaultActionSingleton());
showThreadName.setSelected(true);
showThreadName.setText(Translator.R("COPthreadName"));
showThreadName.addActionListener(getDefaultActionSingleton());

showMessage.setSelected(true);
showMessage.setText(Translator.R("COPShowMessages"));
Expand All @@ -369,8 +367,8 @@ private final void initComponents() {
Translator.R("COPlevel"),
Translator.R("COPdate"),
Translator.R("COPcode"),
Translator.R("COPthread1"),
Translator.R("COPthread2"),
Translator.R("COPthreadHash"),
Translator.R("COPthreadName"),
Translator.R("COPmessage")}));
sortBy.addActionListener(getDefaultActionSingleton());

Expand Down Expand Up @@ -498,8 +496,8 @@ public final void actionPerformed(final ActionEvent evt) {
addComponent(showLevel).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).
addComponent(showDate).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).
addComponent(showCode).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).
addComponent(showThread1).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(showThread2)).
addComponent(showThreadHash).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(showThreadName)).
addGroup(jPanel2Layout.createSequentialGroup().addGroup(
jPanel2Layout.createParallelGroup(GroupLayout.Alignment.TRAILING).addGroup(
GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
Expand Down Expand Up @@ -548,8 +546,8 @@ public final void actionPerformed(final ActionEvent evt) {
addComponent(showDate).
addComponent(showOrigin).
addComponent(showCode).
addComponent(showThread1).
addComponent(showThread2)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(
addComponent(showThreadHash).
addComponent(showThreadName)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(
jPanel2Layout.createParallelGroup(GroupLayout.Alignment.BASELINE).
addComponent(showMessage).
addComponent(showOut).
Expand Down Expand Up @@ -698,8 +696,8 @@ private final void setHeadersCheckBoxesEnabled(final boolean enable) {
showLevel.setEnabled(enable);
showDate.setEnabled(enable);
showCode.setEnabled(enable);
showThread1.setEnabled(enable);
showThread2.setEnabled(enable);
showThreadHash.setEnabled(enable);
showThreadName.setEnabled(enable);
}

private final void setMessagesCheckBoxesEnabled(final boolean enable) {
Expand Down Expand Up @@ -855,8 +853,8 @@ private final void updateModel() {
model.showMessage = showMessage.isSelected();
model.showOrigin = showOrigin.isSelected();
model.showOut = showOut.isSelected();
model.showThread1 = showThread1.isSelected();
model.showThread2 = showThread2.isSelected();
model.showThreadHash = showThreadHash.isSelected();
model.showThreadName = showThreadName.isSelected();
model.showUser = showUser.isSelected();
model.sortBy = sortBy.getSelectedIndex();
model.wordWrap = wordWrap.isSelected();
Expand Down Expand Up @@ -896,8 +894,8 @@ private final void updateModel() {
private final JCheckBox showMessage;
private final JCheckBox showOrigin;
private final JCheckBox showOut;
private final JCheckBox showThread1;
private final JCheckBox showThread2;
private final JCheckBox showThreadHash;
private final JCheckBox showThreadName;
private final JCheckBox showUser;
private final JCheckBox sortCopyAll;
private final JComboBox<String> sortBy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ String importList() {
String importList(int start) {
return importList(highLight, start);
}

String importList(boolean mark, int start) {
return importList(mark, start, sortBy);
}
Expand Down Expand Up @@ -164,11 +164,11 @@ String createLine(MessageWithHeader m) {
if (showHeaders) {
sb.append(m.getHeader().toString(showUser,
showOrigin,
showLevel,
showDate,
showLevel,
showCode,
showThread1,
showThread2));
showThreadHash,
showThreadName));
}
if (showMessage && showHeaders) {
sb.append(": ");
Expand Down Expand Up @@ -272,8 +272,8 @@ String createStatisticHint() {
boolean showMessage;
boolean showOrigin;
boolean showOut;
boolean showThread1;
boolean showThread2;
boolean showThreadHash;
boolean showThreadName;
boolean showUser;
int sortBy;
boolean wordWrap;
Expand Down
9 changes: 8 additions & 1 deletion core/src/main/java/net/sourceforge/jnlp/ItwJvmLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
import net.adoptopenjdk.icedteaweb.launch.JvmLauncher;
import net.adoptopenjdk.icedteaweb.logging.Logger;
import net.adoptopenjdk.icedteaweb.logging.LoggerFactory;
import net.sourceforge.jnlp.util.logging.FileLog;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import static java.util.Objects.requireNonNull;
import static net.adoptopenjdk.icedteaweb.JavaSystemPropertiesConstants.ITW_BIN_LOCATION;
Expand Down Expand Up @@ -61,7 +63,12 @@ private void launchExternal(final List<String> vmArgs, final List<String> javaws

LOG.info("About to launch external with commands: '{}'", commands.toString());

final Process p = new ProcessBuilder()
final ProcessBuilder pb = new ProcessBuilder();
final Map<String, String> env = pb.environment();
env.put(FileLog.LOG_PREFIX_ENV, FileLog.getLogFileNamePrefix());
env.put(FileLog.LOG_POSTFIX_ENV, FileLog.getLogFileNamePostfix() + "-app");

final Process p = pb
.command(commands)
.inheritIO()
.start();
Expand Down
50 changes: 36 additions & 14 deletions core/src/main/java/net/sourceforge/jnlp/util/logging/FileLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@
statement from your version. */
package net.sourceforge.jnlp.util.logging;

import net.adoptopenjdk.icedteaweb.Assert;
import net.adoptopenjdk.icedteaweb.StringUtils;
import net.adoptopenjdk.icedteaweb.logging.Logger;
import net.adoptopenjdk.icedteaweb.logging.LoggerFactory;
import net.adoptopenjdk.icedteaweb.os.OsUtil;
import net.sourceforge.jnlp.util.docprovider.TextsProvider;
import net.sourceforge.jnlp.util.logging.filelogs.LogBasedFileLog;
import net.sourceforge.jnlp.util.logging.filelogs.WriterBasedFileLog;
import net.sourceforge.jnlp.util.logging.headers.Header;

import java.text.SimpleDateFormat;
import java.util.Date;
Expand All @@ -50,26 +51,48 @@ public final class FileLog {

private static final Logger LOG = LoggerFactory.getLogger(FileLog.class);

private static final String TIME_SEPARATOR = OsUtil.isWindows() ? "_" : ":";
public static String LOG_PREFIX_ENV = "itwLogFilePrefix";
public static String LOG_POSTFIX_ENV = "itwLogFilePostfix";

private static final String DEFAULT_LOGGER_NAME = TextsProvider.ITW + " file-logger";
private static final String TIME_SEPARATOR = OsUtil.isWindows() ? "_" : ":";
private static final SimpleDateFormat FILE_LOG_NAME_FORMATTER = new SimpleDateFormat("yyyy-MM-dd_HH" + TIME_SEPARATOR + "mm" + TIME_SEPARATOR + "ss.S");

public static Header getHeadlineHeader() {
return new Header(OutputControllerLevel.WARN, false);
private static final String logFileNamePrefix;
private static String logFileNamePostfix;

static {
final String envPrefix = System.getenv(LOG_PREFIX_ENV);
if (!StringUtils.isBlank(envPrefix)) {
logFileNamePrefix = envPrefix;
} else {
logFileNamePrefix = FILE_LOG_NAME_FORMATTER.format(new Date());
}

final String envPostfix = System.getenv(LOG_POSTFIX_ENV);
if (!StringUtils.isBlank(envPostfix)) {
logFileNamePostfix = envPostfix;
} else {
logFileNamePostfix = "itw";
}
}

public static SingleStreamLogger createFileLog() {
return createFileLog("javantx");
public static String getLogFileNamePrefix() {
return logFileNamePrefix;
}

public static String getLogFileNamePostfix() {
return logFileNamePostfix;
}

public static SingleStreamLogger createAppFileLog() {
return createFileLog("clienta");
public static void setLogFileNamePostfix(String logFileNamePostfix) {
FileLog.logFileNamePostfix = Assert.requireNonBlank(logFileNamePostfix, "logFileNamePostfix");
}

private static SingleStreamLogger createFileLog(String id) {
public static SingleStreamLogger createFileLog() {
SingleStreamLogger s;
try {
final String fileName = getFileName(id);
final String fileName = getFileName();
if (LogConfig.getLogConfig().isLegacyLogBasedFileLog()) {
s = new LogBasedFileLog(DEFAULT_LOGGER_NAME, fileName, false);
} else {
Expand All @@ -84,9 +107,8 @@ private static SingleStreamLogger createFileLog(String id) {
return s;
}

private static String getFileName(String id) {
final String timeStamp = FILE_LOG_NAME_FORMATTER.format(new Date());
return LogConfig.getLogConfig().getIcedteaLogDir() + "itw-" + id + "-" + timeStamp + ".log";
private static String getFileName() {
final String logDir = LogConfig.getLogConfig().getIcedteaLogDir();
return logDir + (logFileNamePrefix + "-" + logFileNamePostfix + ".log");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private void consume() {
private void consumeClientAppMessage(MessageWithHeader message) {
final LogConfig logConfig = LogConfig.getLogConfig();
if (logConfig.isLogToFile() && logConfig.isLogToFileForClientApp()) {
getAppFileLog().log(convertToPrintableString(message, logConfig));
getFileLog().log(convertToPrintableString(message, logConfig));
}
}

Expand Down Expand Up @@ -244,18 +244,6 @@ private SingleStreamLogger getFileLog() {
return FileLogHolder.INSTANCE;
}


private static class AppFileLogHolder {

//https://en.wikipedia.org/wiki/Double-checked_locking#Usage_in_Java
//https://en.wikipedia.org/wiki/Initialization_on_demand_holder_idiom
private static final SingleStreamLogger INSTANCE = FileLog.createAppFileLog();
}

private SingleStreamLogger getAppFileLog() {
return AppFileLogHolder.INSTANCE;
}

private static class SystemLogHolder {

//https://en.wikipedia.org/wiki/Double-checked_locking#Usage_in_Java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ public enum OutputControllerLevel {

;

private final String displayName = (name() + " ").substring(0,5);

public boolean printToOutStream() {
return this == INFO || this == DEBUG || this == WARN;
}

public boolean printToErrStream() {
return this == ERROR || this == WARN;
}

public String display() {
return displayName;
}
}
Loading

0 comments on commit a5e1a12

Please sign in to comment.