[ 
https://issues.apache.org/jira/browse/LOG4J2-1944?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16061557#comment-16061557
 ] 

Pierrick HYMBERT commented on LOG4J2-1944:
------------------------------------------

Hello [~wdeng], thank you for this snippet, I have no chance to debate status 
logger error level.

Although I tried to answer your concern about programmatic API and this error 
message that doesnt appears in this case.

But maybe I was wrong, if you required to log error message to console:
{code}
import java.time.Instant;

public class App {
    public static void main(String[] args) {
        System.err.println(String.format("%s [%s] %s %s - %s", Instant.now(),
                Thread.currentThread().getName(), "ERROR", App.class.getName(), 
"Hello"));
    }
}
{code}

If you do need log4j2, please read [The ConfigurationBuilder 
API|https://logging.apache.org/log4j/2.x/manual/customconfig.html], for example:
{code}
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.appender.ConsoleAppender;
import org.apache.logging.log4j.core.config.Configurator;
import 
org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder;
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder;
import 
org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory;
import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;

public class App {
    public static void main(String[] args) {
        final ConfigurationBuilder<BuiltConfiguration> builder = 
ConfigurationBuilderFactory
                .newConfigurationBuilder();
        builder.setStatusLevel(Level.ERROR);
        builder.setConfigurationName("App");
        final AppenderComponentBuilder appenderBuilder = 
builder.newAppender("Stdout", "CONSOLE")
                .addAttribute("target", ConsoleAppender.Target.SYSTEM_OUT);
        appenderBuilder.add(
                builder.newLayout("PatternLayout").addAttribute("pattern", "%d 
%p %C [%t] %m%n"));
        builder.add(appenderBuilder);
        
builder.add(builder.newRootLogger(Level.ERROR).add(builder.newAppenderRef("Stdout")));

        LoggerContext ctx = Configurator.initialize(builder.build());
        Logger log = ctx.getLogger(App.class.getName());
        log.error("Hello");
    }
}
{code}

> Should suppress message "ERROR No log4j2 configuration file found..." when 
> programmatic API is used to config log4j.
> --------------------------------------------------------------------------------------------------------------------
>
>                 Key: LOG4J2-1944
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1944
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Configurators
>    Affects Versions: 2.6.2
>            Reporter: Weian Deng
>            Priority: Minor
>         Attachments: LOG4J2_1944.zip
>
>
> Log4j can be configured through log4j's configuration API.  There are cases 
> that an organization want to control the log4j configuration through the 
> configuration API and discourage the use of config file.  The error message
> {code}
> ERROR No log4j2 configuration file found. Using default configuration: 
> logging only errors to the console.
> {code}
> is misleading.  
> Can this be downgraded to WARN message, or provide a way to suppress it?



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to