Как я могу контролировать, сколько строк сокращает / усекает log4j 2 PAX Карафа? - PullRequest
0 голосов
/ 28 марта 2019

Возможно, мне потребуется изменить заголовок, чтобы сослаться на ведение журнала pax.

Наблюдаемое явление:

log entry
... 2 more

Желаемый результат:

log entry
log entry
log entry

Обратите внимание, что записи в желаемом результате не были сокращены.

Фон

При использовании Apache Karaf, который использует интерфейс log4j 2, появляется файл свойств etc/org.ops4j.pax.logging.cfg где я могу настроить, что регистрируется и как. Как остановить его от сокращения записей в журнале, как показано выше?

org.ops4j.pax.logging.cfg

################################################################################
#
#    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.
#
################################################################################

# Colors for log level rendering
color.fatal = bright red
color.error = bright red
color.warn = bright yellow
color.info = bright green
color.debug = cyan
color.trace = cyan

# Common pattern layout for appenders
log4j2.pattern = %d{ISO8601} | %-5p | %-16t | %-32c{1} | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %m%n
log4j2.out.pattern = \u001b[90m%d{HH:mm:ss\.SSS}\u001b[0m %highlight{%-5level}{FATAL=${color.fatal}, ERROR=${color.error}, WARN=${color.warn}, INFO=${color.info}, DEBUG=${color.debug}, TRACE=${color.trace}} \u001b[90m[%t]\u001b[0m %msg%n%throwable


# Root logger
log4j2.rootLogger.level = INFO
# uncomment to use asynchronous loggers, which require mvn:com.lmax/disruptor/3.3.2 library
#log4j2.rootLogger.type = asyncRoot
#log4j2.rootLogger.includeLocation = false
log4j2.rootLogger.appenderRef.RollingFile.ref = RollingFile
log4j2.rootLogger.appenderRef.PaxOsgi.ref = PaxOsgi
log4j2.rootLogger.appenderRef.Console.ref = Console
log4j2.rootLogger.appenderRef.Console.filter.threshold.type = ThresholdFilter
log4j2.rootLogger.appenderRef.Console.filter.threshold.level = ${karaf.log.console:-FINEST}

# Loggers configuration

# SSHD logger
log4j2.logger.sshd.name = org.apache.sshd
log4j2.logger.sshd.level = INFO

# Spifly logger
log4j2.logger.spifly.name = org.apache.aries.spifly
log4j2.logger.spifly.level = WARN

# Security audit logger
log4j2.logger.audit.name = audit
log4j2.logger.audit.level = TRACE
log4j2.logger.audit.additivity = false
log4j2.logger.audit.appenderRef.AuditRollingFile.ref = AuditRollingFile

# Appenders configuration

# Console appender not used by default (see log4j2.rootLogger.appenderRefs)
log4j2.appender.console.type = Console
log4j2.appender.console.name = Console
log4j2.appender.console.layout.type = PatternLayout
log4j2.appender.console.layout.pattern = ${log4j2.out.pattern}

# Rolling file appender
log4j2.appender.rolling.type = RollingRandomAccessFile
log4j2.appender.rolling.name = RollingFile
log4j2.appender.rolling.fileName = ${karaf.log}/karaf.log
log4j2.appender.rolling.filePattern = ${karaf.log}/karaf.log.%i
# uncomment to not force a disk flush
#log4j2.appender.rolling.immediateFlush = false
log4j2.appender.rolling.append = true
log4j2.appender.rolling.layout.type = PatternLayout
log4j2.appender.rolling.layout.pattern = ${log4j2.pattern}
log4j2.appender.rolling.policies.type = Policies
log4j2.appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
log4j2.appender.rolling.policies.size.size = 16MB

# Audit file appender
log4j2.appender.audit.type = RollingRandomAccessFile
log4j2.appender.audit.name = AuditRollingFile
log4j2.appender.audit.fileName = ${karaf.log}/security.log
log4j2.appender.audit.filePattern = ${karaf.log}/security-%i.log
log4j2.appender.audit.append = true
log4j2.appender.audit.layout.type = PatternLayout
log4j2.appender.audit.layout.pattern = %m%n
log4j2.appender.audit.policies.type = Policies
log4j2.appender.audit.policies.size.type = SizeBasedTriggeringPolicy
log4j2.appender.audit.policies.size.size = 8MB

# OSGi appender
log4j2.appender.osgi.type = PaxOsgi
log4j2.appender.osgi.name = PaxOsgi
log4j2.appender.osgi.filter = *

# help with identification of maven-related problems with pax-url-aether
#log4j2.logger.aether.name = shaded.org.eclipse.aether
#log4j2.logger.aether.level = TRACE
#log4j2.logger.http-headers.name = shaded.org.apache.http.headers
#log4j2.logger.http-headers.level = DEBUG
#log4j2.logger.maven.name = org.ops4j.pax.url.mvn
#log4j2.logger.maven.level = TRACE

Шаги для воспроизведения

Установить Караф 4.2.4

Создать новый проект Java

mvn archetype:generate \
-DinteractiveMode=false \
-DarchetypeGroupId=org.apache.maven.archetypes \
-DgroupId=com.testproject \
-DartifactId=karaftest 

Добавить зависимость, о которой Караф не знает. Не добавляйте файл functions.xml. Я использовал pom.xml, чтобы сделать это проще.

<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-blueprint</artifactId>
  <version>2.22.2</version>
  <scope>provided</scope>
</dependency>

Main.class:

import org.apache.camel.blueprint.BlueprintCamelContext;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        BlueprintCamelContext blueprintCamelContext = new BlueprintCamelContext();

        System.out.println( "Hello World!" );
    }
}

Сделай пачку. Я запустил файл pom.xml maven, выгрузил значение упаковки и добавил плагин maven-bundle-plugin в команду сборки.

<packaging>bundle</packaging>

<build>
    <plugins>
      <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <extensions>true</extensions>
        <version>2.4.0</version>
      </plugin>
    </plugins>
  </build>

Построить

mvn clean install

Поместите банку из комплекта в папку развертывания Карафа.

Караф не запустит связку. Запустите пакет start 45 (идентификатор пакета по умолчанию при новой установке, вероятно, будет 45).

Выполнить log:set debug и log:display. Ищите ошибку OSGI osgi.wiring.package, потому что я импортировал зависимость в MANIFEST.MF (добавьте в pom.xml)

Исключительная ситуация при выполнении команды

Караф Бревно содержит

11:24:05.970 ERROR [Karaf local console user karaf] Exception caught while executing command
org.apache.karaf.shell.support.MultiException: Error executing command on bundles:
    Error starting bundle 45: Unable to resolve com.testproject.karaftest [45](R 45.0): missing requirement [com.testproject.karaftest [45](R 45.0)] osgi.wiring.package; (&(osgi.wiring.package=org.apache.camel.blueprint)(version>=2.22.0)(!(version>=3.0.0))) Unresolved requirements: [[com.testproject.karaftest [45](R 45.0)] osgi.wiring.package; (&(osgi.wiring.package=org.apache.camel.blueprint)(version>=2.22.0)(!(version>=3.0.0)))]
    at org.apache.karaf.shell.support.MultiException.throwIf(MultiException.java:61) ~[?:?]
    at org.apache.karaf.bundle.command.BundlesCommand.doExecute(BundlesCommand.java:70) ~[?:?]
    at org.apache.karaf.bundle.command.BundlesCommand.execute(BundlesCommand.java:55) ~[?:?]
    at org.apache.karaf.shell.impl.action.command.ActionCommand.execute(ActionCommand.java:84) ~[?:?]
    at org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:68) ~[?:?]
    at org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:86) ~[?:?]
    at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:599) ~[?:?]
    at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:526) ~[?:?]
    at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:415) ~[?:?]
    at org.apache.felix.gogo.runtime.Pipe.doCall(Pipe.java:416) ~[?:?]
    at org.apache.felix.gogo.runtime.Pipe.call(Pipe.java:229) ~[?:?]
    at org.apache.felix.gogo.runtime.Pipe.call(Pipe.java:59) ~[?:?]
    at java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[?:?]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[?:?]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[?:?]
    at java.lang.Thread.run(Thread.java:834) [?:?]
    Suppressed: java.lang.Exception: Error starting bundle 45: Unable to resolve com.testproject.karaftest [45](R 45.0): missing requirement [com.testproject.karaftest [45](R 45.0)] osgi.wiring.package; (&(osgi.wiring.package=org.apache.camel.blueprint)(version>=2.22.0)(!(version>=3.0.0))) Unresolved requirements: [[com.testproject.karaftest [45](R 45.0)] osgi.wiring.package; (&(osgi.wiring.package=org.apache.camel.blueprint)(version>=2.22.0)(!(version>=3.0.0)))]
        at org.apache.karaf.bundle.command.BundlesCommand.doExecute(BundlesCommand.java:67) ~[?:?]
        at org.apache.karaf.bundle.command.BundlesCommand.execute(BundlesCommand.java:55) ~[?:?]
        at org.apache.karaf.shell.impl.action.command.ActionCommand.execute(ActionCommand.java:84) ~[?:?]
        at org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:68) ~[?:?]
        at org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:86) ~[?:?]
        at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:599) ~[?:?]
        at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:526) ~[?:?]
        at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:415) ~[?:?]
        at org.apache.felix.gogo.runtime.Pipe.doCall(Pipe.java:416) ~[?:?]
        at org.apache.felix.gogo.runtime.Pipe.call(Pipe.java:229) ~[?:?]
        at org.apache.felix.gogo.runtime.Pipe.call(Pipe.java:59) ~[?:?]
        at java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[?:?]
        at java.lang.Thread.run(Thread.java:834) [?:?]
    Caused by: org.osgi.framework.BundleException: Unable to resolve com.testproject.karaftest [45](R 45.0): missing requirement [com.testproject.karaftest [45](R 45.0)] osgi.wiring.package; (&(osgi.wiring.package=org.apache.camel.blueprint)(version>=2.22.0)(!(version>=3.0.0))) Unresolved requirements: [[com.testproject.karaftest [45](R 45.0)] osgi.wiring.package; (&(osgi.wiring.package=org.apache.camel.blueprint)(version>=2.22.0)(!(version>=3.0.0)))]
        at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:4149) ~[?:?]
        at org.apache.felix.framework.Felix.startBundle(Felix.java:2119) ~[?:?]
        at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:998) ~[?:?]
        at org.apache.karaf.bundle.command.Start.executeOnBundle(Start.java:38) ~[?:?]
        at org.apache.karaf.bundle.command.BundlesCommand.doExecute(BundlesCommand.java:65) ~[?:?]
        ... 14 more

Похожие: Как остановить обрезку стековых трасс в журналах

...