Skip to content

Commit

Permalink
JENA-1912: Fix LogCtl and non-Log4J2 provider. Logging cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
afs committed Jun 6, 2020
1 parent c9d3c3c commit 5d8f72d
Show file tree
Hide file tree
Showing 57 changed files with 636 additions and 325 deletions.
6 changes: 6 additions & 0 deletions apache-jena/log4j2.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{HH:mm:ss} %-5p %-15c{1} :: %m%n
#appender.console.layout.pattern = [%d{yyyy-MM-dd HH:mm:ss}] %-5p %-15c{1} :: %m%n

## appender.file.type = File
## appender.file.name = OUT
## appender.file.fileName=log.fuseki
## appender.file.layout.type=PatternLayout
## appender.file.layout.pattern = [%d{yyyy-MM-dd HH:mm:ss}] %-5p %-15c{1} :: %m%n

rootLogger.level = INFO
rootLogger.appenderRef.stdout.ref = OUT

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
* for the "no groups" case.
*/
public class CustomAggregate {
static { LogCtl.setCmdLogging(); }
static { LogCtl.setLogging(); }
/**
* Execution of a custom aggregate is with accumulators. One accumulator is
* created for the factory for each group in a query execution.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
/** Example of using RIOT : register a new input language */
public class ExRIOT6_AddNewReader
{
static { LogCtl.setCmdLogging(); }
static { LogCtl.setLogging(); }

public static void main(String... argv) {
Lang lang = LangBuilder.create("SSE", "text/x-sse").addFileExtensions("rsse").build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

/** Set proeprties of the RDF/XML parser (ARP) */
public class ExRIOT_RDFXML_ReaderProperties {
static { LogCtl.setCmdLogging(); }
static { LogCtl.setLogging(); }

public static void main(String[] args) {
// Inline illustrative data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

/** Example of setting properties for RDF/XML writer via RIOT */
public class ExRIOT_RDFXML_WriteProperties {
static { LogCtl.setCmdLogging(); }
static { LogCtl.setLogging(); }

public static void main(String... args) {
// Data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
/** Example of registering a new writer with RIOT */
public class ExRIOTw3_AddNewWriter
{
static { LogCtl.setCmdLogging(); }
static { LogCtl.setLogging(); }

// See also ExRIOT6_AddNewLang
public static void main(String[] args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

public class UpdateExecuteOperations
{
static { LogCtl.setCmdLogging(); }
static { LogCtl.setLogging(); }
public static void main(String []args)
{
// Create an empty DatasetGraph (has an empty default graph and no named graphs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

public class UpdateProgrammatic
{
static { LogCtl.setCmdLogging(); }
static { LogCtl.setLogging(); }
public static void main(String []args)
{
Dataset dataset = DatasetFactory.createTxnMem() ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
/** Simple example of SPARQL/Update : read a update script from a file and execute it */
public class UpdateReadFromFile
{
static { LogCtl.setCmdLogging(); }
static { LogCtl.setLogging(); }
public static void main(String []args)
{
// Create an empty GraphStore (has an empty default graph and no named graphs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@

/** Property function for FIND() - allows already bound.
* <pre>
* << ?s ?p ?o >> apf:find ?t .
* <pre>
* &lt;&lt; ?s ?p ?o &gt;&gt; apf:find ?t .
* </pre>
* This binds all the variables, with <tt>?t</tt> bound to a triple term for the match of <tt>?s ?p ?o</tt>.
*/
public class TripleTermFind extends PropertyFunctionEval {
Expand Down
135 changes: 135 additions & 0 deletions jena-base/src/main/java/org/apache/jena/atlas/logging/LogCmd.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.jena.atlas.logging;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

import org.apache.jena.atlas.io.IO;
import org.apache.jena.atlas.lib.StrUtils;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.ConfigurationFactory;
import org.apache.logging.log4j.core.config.ConfigurationSource;
import org.apache.logging.log4j.core.config.Configurator;
import org.apache.logging.log4j.core.config.properties.PropertiesConfigurationFactory;

/**
* Additional logging control, for Log4j2 as used by jena-cmds.
* <br/>
* This class pulls in log4j2.
* <br/>
* This class is split out from {@link LogCtl} to decouple the class loading dependencies.
*/
public class LogCmd {
/**
* Reset logging (log4j2). log4j2.properties format.
*/
public static void resetLogging(String configString) {
// Dispatch name to syntax.
try (InputStream inputStream = new ByteArrayInputStream(StrUtils.asUTF8bytes(configString))) {
resetLogging(inputStream, ".properties");
} catch (IOException ex) {
IO.exception(ex);
}
}

private static void resetLogging(InputStream inputStream, String syntaxHint) throws IOException {
ConfigurationSource source = new ConfigurationSource(inputStream);
ConfigurationFactory factory = ( syntaxHint.endsWith(".properties") )
? new PropertiesConfigurationFactory()
: ConfigurationFactory.getInstance();
Configuration configuration = factory.getConfiguration(null, source);
Configurator.initialize(configuration);
}

// public static void setCmdLogging() {
// LogCtl.setLog4j2();
// if ( ! LogCtl.isSetLog4j2property() )
// resetLogging(log4j2setupCmd);
// }

// basic setup.
// @formatter:off
/** A basic logging setup. */
public static String log4j2setup = StrUtils.strjoinNL
( "## Command default log4j2 setup : log4j2 properties syntax."
, "status = error"
, "name = PropertiesConfig"
, "filters = threshold"
, ""
, "filter.threshold.type = ThresholdFilter"
, "filter.threshold.level = INFO"

, "appender.console.type = Console"
, "appender.console.name = OUT"
, "appender.console.target = SYSTEM_OUT"
, "appender.console.layout.type = PatternLayout"
, "appender.console.layout.pattern = %d{HH:mm:ss} %-5p %-10c{1} :: %m%n"
, "#appender.console.layout.pattern = [%d{yyyy-MM-dd HH:mm:ss}] %-5p %-10c{1} :: %m%n"

, "rootLogger.level = INFO"
, "rootLogger.appenderRef.stdout.ref = OUT"

, "logger.jena.name = org.apache.jena"
, "logger.jena.level = INFO"

, "logger.arq-exec.name = org.apache.jena.arq.exec"
, "logger.arq-exec.level = INFO"

, "logger.riot.name = org.apache.jena.riot"
, "logger.riot.level = INFO"
);
// @formatter:on


// @formatter:off
/** A format for commands using stderr. */
public static String log4j2setupCmd = StrUtils.strjoinNL
( "## Command default log4j2 setup : log4j2 properties syntax."
, "status = error"
, "name = PropertiesConfig"
, "filters = threshold"
, ""
, "filter.threshold.type = ThresholdFilter"
, "filter.threshold.level = INFO"

, "appender.console.type = Console"
, "appender.console.name = OUT"
, "appender.console.target = SYSTEM_ERR"
, "appender.console.layout.type = PatternLayout"
, "appender.console.layout.pattern = %d{HH:mm:ss} %-5p %-10c{1} :: %m%n"
, "#appender.console.layout.pattern = [%d{yyyy-MM-dd HH:mm:ss}] %-5p %-10c{1} ::: %m%n"

, "rootLogger.level = INFO"
, "rootLogger.appenderRef.stdout.ref = OUT"

, "logger.jena.name = org.apache.jena"
, "logger.jena.level = INFO"

, "logger.arq-exec.name = org.apache.jena.arq.exec"
, "logger.arq-exec.level = INFO"

, "logger.riot.name = org.apache.jena.riot"
, "logger.riot.level = INFO"
);
// @formatter:on

}

Loading

0 comments on commit 5d8f72d

Please sign in to comment.