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

Tinylog #8226

Merged
merged 23 commits into from
Dec 18, 2021
Merged

Tinylog #8226

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We trim white space and non-ASCII characters from DOI [#8127](https://github.com/JabRef/jabref/issues/8127)
- The duplicate checker now inspects other fields in case no difference in the required and optional fields are found.
- We reworked the library properties dialog and integrated the `Library > Preamble`, `Library > Citation key pattern` and `Library > String constants dialogs` [#8264](https://github.com/JabRef/jabref/pulls/8264)
- We improved the startup time of JabRef by switching from the logging library `log4j2` to `tinylog` [#8007](https://github.com/JabRef/jabref/issues/8007)

### Fixed

Expand Down Expand Up @@ -80,13 +81,12 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where XMP and embedded BibTeX export would not work [#8278](https://github.com/JabRef/jabref/issues/8278)
- We fixed an issue where the XMP and embedded BibTeX import of a file containing multiple schemas failed [#8278](https://github.com/JabRef/jabref/issues/8278)
- We fixed an issue where pdf-paths and the pdf-indexer could get out of sync [#8182](https://github.com/JabRef/jabref/issues/8182)

- We fixed an issue where Status-Logger error messages appeared during the startup of JabRef [#5475](https://github.com/JabRef/jabref/issues/5475)

### Removed

- We removed two orphaned preferences options [#8164](https://github.com/JabRef/jabref/pull/8164)


- We removed the functionality of the `--debug` commandline options. Use the java command line switch `-Dtinylog.level=debug` for debug output instead. [#8226](https://github.com/JabRef/jabref/pull/8226)



Expand Down
21 changes: 3 additions & 18 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,9 @@ dependencies {
implementation 'com.konghq:unirest-java:3.13.4'

implementation 'org.slf4j:slf4j-api:2.0.0-alpha5'
implementation group: 'org.apache.logging.log4j', name: 'log4j-jcl', version: '3.0.0-SNAPSHOT'
implementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j18-impl', version: '3.0.0-SNAPSHOT'
implementation group: 'org.apache.logging.log4j', name: 'log4j-plugins', version: '3.0.0-SNAPSHOT'
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '3.0.0-SNAPSHOT'
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '3.0.0-SNAPSHOT'
annotationProcessor group: 'org.apache.logging.log4j', name: 'log4j-core', version: '3.0.0-SNAPSHOT'
implementation "org.tinylog:tinylog-api:2.4.1"
implementation "org.tinylog:slf4j-tinylog:2.4.1"
implementation "org.tinylog:tinylog-impl:2.4.1"

implementation 'de.undercouch:citeproc-java:3.0.0-alpha.3'

Expand Down Expand Up @@ -566,14 +563,9 @@ jlink {
requires 'com.sun.xml.fastinfoset'
requires 'com.sun.xml.txw2'
requires 'org.slf4j'
uses 'org.apache.logging.log4j.util.PropertySource'
uses 'org.apache.logging.log4j.core.util.WatchEventService'
uses 'org.apache.logging.log4j.plugins.processor.PluginService'
uses 'org.controlsfx.glyphfont.GlyphFont'
uses 'com.airhacks.afterburner.views.ResourceLocator'
uses 'org.apache.logging.log4j.message.ThreadDumpMessage.ThreadInfoFactory'
uses 'com.airhacks.afterburner.injection.PresenterFactory'
uses 'org.apache.logging.log4j.spi.Provider'
uses 'org.mariadb.jdbc.credential.CredentialPlugin'
uses 'org.mariadb.jdbc.authentication.AuthenticationPlugin'
uses 'org.mariadb.jdbc.tls.TlsSocketPlugin'
Expand All @@ -582,16 +574,11 @@ jlink {
uses 'org.eclipse.jgit.lib.GpgSigner'
uses 'javax.xml.bind.JAXBContextFactory'
provides 'org.apache.lucene.codecs.DocValuesFormat' with 'org.apache.lucene.codecs.lucene80.Lucene80DocValuesFormat'
provides 'javax.annotation.processing.Processor' with 'org.apache.logging.log4j.plugins.processor.PluginProcessor'
provides 'org.controlsfx.glyphfont.GlyphFont' with 'org.controlsfx.glyphfont.FontAwesome'
provides 'org.apache.logging.log4j.message.ThreadDumpMessage.ThreadInfoFactory' with 'org.apache.logging.log4j.core.message.ExtendedThreadInfoFactory'
provides 'org.mariadb.jdbc.tls.TlsSocketPlugin' with 'org.mariadb.jdbc.internal.protocol.tls.DefaultTlsSocketPlugin'
provides 'com.microsoft.applicationinsights.core.dependencies.io.grpc.ServerProvider' with 'com.microsoft.applicationinsights.core.dependencies.io.grpc.netty.shaded.io.grpc.netty.NettyServerProvider'
provides 'com.microsoft.applicationinsights.core.dependencies.io.grpc.NameResolverProvider' with 'com.microsoft.applicationinsights.core.dependencies.io.grpc.internal.DnsNameResolverProvider'
provides 'org.apache.logging.log4j.util.PropertySource' with 'org.apache.logging.log4j.util.EnvironmentPropertySource',
'org.apache.logging.log4j.util.SystemPropertiesPropertySource'
provides 'java.sql.Driver' with 'org.postgresql.Driver'
provides 'org.apache.logging.log4j.plugins.processor.PluginService' with 'org.apache.logging.log4j.plugins.convert.plugins.Log4jPlugins'
provides 'org.mariadb.jdbc.authentication.AuthenticationPlugin' with 'org.mariadb.jdbc.internal.com.send.authentication.CachingSha2PasswordPlugin',
'org.mariadb.jdbc.internal.com.send.authentication.ClearPasswordPlugin',
'org.mariadb.jdbc.internal.com.send.authentication.Ed25519PasswordPlugin',
Expand All @@ -603,8 +590,6 @@ jlink {
provides 'org.mariadb.jdbc.credential.CredentialPlugin' with 'org.mariadb.jdbc.credential.aws.AwsIamCredentialPlugin',
'org.mariadb.jdbc.credential.env.EnvCredentialPlugin',
'org.mariadb.jdbc.credential.system.PropertiesCredentialPlugin'
provides 'org.slf4j.spi.SLF4JServiceProvider' with 'org.apache.logging.slf4j.SLF4JServiceProvider'
provides 'org.apache.logging.log4j.spi.Provider' with 'org.apache.logging.log4j.core.impl.Log4jProvider'
provides 'java.security.Provider' with 'org.bouncycastle.jce.provider.BouncyCastleProvider',
'org.bouncycastle.pqc.jcajce.provider.BouncyCastlePQCProvider'
provides 'com.microsoft.applicationinsights.core.dependencies.io.grpc.ManagedChannelProvider' with 'com.microsoft.applicationinsights.core.dependencies.io.grpc.netty.shaded.io.grpc.netty.NettyChannelProvider'
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@

// Logging
requires org.slf4j;
requires org.apache.logging.log4j;
requires org.apache.logging.log4j.core;
requires org.apache.logging.log4j.plugins;
requires org.tinylog.api;
requires org.tinylog.api.slf4j;
requires org.tinylog.impl;

provides org.tinylog.writers.Writer
with org.jabref.gui.logging.GuiWriter,
org.jabref.gui.logging.ApplicationInsightsWriter;

requires applicationinsights.logging.log4j2;
provides org.apache.logging.log4j.plugins.processor.PluginService
with org.jabref.gui.logging.plugins.Log4jPlugins;

// Preferences and XML
requires java.prefs;
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/jabref/cli/ArgumentProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.jabref.logic.importer.fileformat.BibtexParser;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.layout.LayoutFormatterPreferences;
import org.jabref.logic.logging.JabRefLogger;
import org.jabref.logic.net.URLDownload;
import org.jabref.logic.search.DatabaseSearcher;
import org.jabref.logic.search.SearchQuery;
Expand Down Expand Up @@ -181,7 +180,7 @@ public boolean hasParserResults() {
private List<ParserResult> processArguments() {

if (!cli.isBlank() && cli.isDebugLogging()) {
JabRefLogger.setDebug();
System.err.println("use java property -Dtinylog.level=debug");
}

if ((startupMode == Mode.INITIAL_START) && cli.isShowVersion()) {
Expand Down Expand Up @@ -229,7 +228,7 @@ private List<ParserResult> processArguments() {
automaticallySetFileLinks(loaded);
}

if (cli.isWriteXMPtoPdf() && cli.isEmbeddBibfileInPdf() || cli.isWriteMetadatatoPdf() && (cli.isWriteXMPtoPdf() || cli.isEmbeddBibfileInPdf())) {
if ((cli.isWriteXMPtoPdf() && cli.isEmbeddBibfileInPdf()) || (cli.isWriteMetadatatoPdf() && (cli.isWriteXMPtoPdf() || cli.isEmbeddBibfileInPdf()))) {
System.err.println("Give only one of [writeXMPtoPdf, embeddBibfileInPdf, writeMetadatatoPdf]");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import com.tobiasdiez.easybind.EasyBind;
import org.apache.http.client.utils.URIBuilder;
import org.apache.logging.log4j.core.LogEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
14 changes: 7 additions & 7 deletions src/main/java/org/jabref/gui/errorconsole/LogEventViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@
import org.jabref.logic.util.OS;

import com.google.common.base.Throwables;
import org.apache.logging.log4j.core.LogEvent;
import org.tinylog.core.LogEntry;

public class LogEventViewModel {

private LogEvent logEvent;
private final LogEntry logEvent;

public LogEventViewModel(LogEvent logEvent) {
public LogEventViewModel(LogEntry logEvent) {
this.logEvent = Objects.requireNonNull(logEvent);
}

public String getDisplayText() {
return logEvent.getMessage().getFormattedMessage();
return logEvent.getMessage();
}

public String getStyleClass() {
switch (logEvent.getLevel().getStandardLevel()) {
switch (logEvent.getLevel()) {
case ERROR:
return "exception";
case WARN:
Expand All @@ -35,7 +35,7 @@ public String getStyleClass() {
}

public JabRefIcon getIcon() {
switch (logEvent.getLevel().getStandardLevel()) {
switch (logEvent.getLevel()) {
case ERROR:
return (IconTheme.JabRefIcons.INTEGRITY_FAIL);
case WARN:
Expand All @@ -47,7 +47,7 @@ public JabRefIcon getIcon() {
}

public Optional<String> getStackTrace() {
return Optional.ofNullable(logEvent.getMessage().getThrowable()).map(Throwables::getStackTraceAsString);
return Optional.ofNullable(logEvent.getException()).map(Throwables::getStackTraceAsString);
}

public String getDetailedText() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.jabref.gui.logging;

/*
* ApplicationInsights-Java
* ApplicationInsightsJava
* Copyright (c) Microsoft Corporation
* All rights reserved.
*
Expand All @@ -23,42 +23,40 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import com.microsoft.applicationinsights.internal.common.ApplicationInsightsEvent;
import com.microsoft.applicationinsights.internal.logger.InternalLogger;
import com.microsoft.applicationinsights.telemetry.SeverityLevel;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.spi.StandardLevel;
import org.tinylog.core.LogEntry;

// TODO: Remove this copy as soon as the one included in AI is compatible with log4j 3
public final class ApplicationInsightsLogEvent extends ApplicationInsightsEvent {

private LogEvent logEvent;
private final LogEntry logEvent;

public ApplicationInsightsLogEvent(LogEvent logEvent) {
public ApplicationInsightsLogEvent(LogEntry logEvent) {
this.logEvent = logEvent;
}

@Override
public String getMessage() {
String message = this.logEvent.getMessage() != null ?
this.logEvent.getMessage().getFormattedMessage() :
"Log4j Trace";
String message = this.logEvent.getMessage() != null ? this.logEvent.getMessage() : "Tinylog Trace";

return message;
}

@Override
public boolean isException() {
return this.logEvent.getThrown() != null;
return this.logEvent.getException() != null;
}

@Override
public Exception getException() {
Exception exception = null;

if (isException()) {
Throwable throwable = this.logEvent.getThrown();
Throwable throwable = this.logEvent.getException();
exception = throwable instanceof Exception ? (Exception) throwable : new Exception(throwable);
}

Expand All @@ -68,29 +66,28 @@ public Exception getException() {
@Override
public Map<String, String> getCustomParameters() {

Map<String, String> metaData = new HashMap<String, String>();
Map<String, String> metaData = new HashMap<>();

metaData.put("SourceType", "Log4j");
metaData.put("SourceType", "slf4j");

addLogEventProperty("LoggerName", logEvent.getLoggerName(), metaData);
addLogEventProperty("LoggingLevel", logEvent.getLevel() != null ? logEvent.getLevel().name() : null, metaData);
addLogEventProperty("ThreadName", logEvent.getThreadName(), metaData);
addLogEventProperty("TimeStamp", getFormattedDate(logEvent.getTimeMillis()), metaData);
addLogEventProperty("ThreadName", logEvent.getThread().getName(), metaData);
addLogEventProperty("TimeStamp", getFormattedDate(logEvent.getTimestamp().toInstant().toEpochMilli()), metaData);

if (isException()) {
addLogEventProperty("Logger Message", getMessage(), metaData);
}

if (logEvent.isIncludeLocation()) {
StackTraceElement stackTraceElement = logEvent.getSource();
for (StackTraceElement stackTraceElement : logEvent.getException().getStackTrace()) {

addLogEventProperty("ClassName", stackTraceElement.getClassName(), metaData);
addLogEventProperty("FileName", stackTraceElement.getFileName(), metaData);
addLogEventProperty("MethodName", stackTraceElement.getMethodName(), metaData);
addLogEventProperty("LineNumber", String.valueOf(stackTraceElement.getLineNumber()), metaData);
}

addLogEventProperty("ClassName", stackTraceElement.getClassName(), metaData);
addLogEventProperty("FileName", stackTraceElement.getFileName(), metaData);
addLogEventProperty("MethodName", stackTraceElement.getMethodName(), metaData);
addLogEventProperty("LineNumber", String.valueOf(stackTraceElement.getLineNumber()), metaData);
}

for (Map.Entry<String, String> entry : logEvent.getContextData().toMap().entrySet()) {
for (Entry<String, String> entry : logEvent.getContext().entrySet()) {
addLogEventProperty(entry.getKey(), entry.getValue(), metaData);
}

Expand All @@ -102,28 +99,21 @@ public Map<String, String> getCustomParameters() {

@Override
public SeverityLevel getNormalizedSeverityLevel() {
int log4jLevelAsInt = logEvent.getLevel().intLevel();
org.tinylog.Level logEventLevel = logEvent.getLevel();

switch (StandardLevel.getStandardLevel(log4jLevelAsInt)) {
case FATAL:
return SeverityLevel.Critical;
switch (logEventLevel) {

case ERROR:
return SeverityLevel.Error;

case WARN:
return SeverityLevel.Warning;

case INFO:
return SeverityLevel.Information;

case TRACE:
case DEBUG:
case ALL:
return SeverityLevel.Verbose;

default:
InternalLogger.INSTANCE.error("Unknown Log4j v2 option, %d, using TRACE level as default", log4jLevelAsInt);
InternalLogger.INSTANCE.error("Unknown slf4joption, %d, using TRACE level as default", logEventLevel);
return SeverityLevel.Verbose;
}
}
Expand Down
Loading