#(log4j2) loggger.info doesnt print in console

1 messages · Page 1 of 1 (latest)

obtuse peak
#

in log4j2, loggger.info does not print anything in the console. however, logger.error does. my code is ```Logger logger = logger= LogManager.getLogger(Main.class);
logger.info("Logging in java");
logger.error("Error in java");

I have also attached my build.gradle file in case that is needed
worn crestBOT
#

<@&987246399047479336> please have a look, thanks.

worn crestBOT
timber yoke
#

can you share your log4j2.xml configuration as well

obtuse peak
#

where is that in my project?

timber yoke
#

in your resources folder ig

obtuse peak
#

resources folder is empy

timber yoke
#

then you didnt even configured log4j2 correctly

obtuse peak
#

yeah, can you show me? i am learning log4j2 rn and icant find any good guides online

timber yoke
obtuse peak
#

ok

obtuse peak
#

my log4j2.xml file looks like this now

    <Appenders>
        <Console name="stdout" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} %p %m%n"/>
        </Console>
    </Appenders>
</Configuration>
<Loggers>
    <Root level="error">
        <AppenderRef ref="STDOUT"/>
    </Root>
</Loggers>```
#

but log4j2 is saying [Fatal Error] log4j2.xml:8:2: The markup in the document following the root element must be well-formed.

timber yoke
#

the loggers part needs to be inside the configuration part

#

see this for example

obtuse peak
#

ok. now my xml file is like this. it works well.<Configuration status="info" name="org.legoaggelos.Main" packages=""> <Appenders> <Console name="stdout" target="SYSTEM_OUT"> <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} %p %m%n"/> </Console> </Appenders> <Loggers> <Root level="info"> <AppenderRef ref="stdout"/> </Root> </Loggers> </Configuration>
I read a bit more, and i changed the root level to info. now logger.info("..."); actually prints stuff!
I have another question now, in the site, it shows this block of code that makes the logger log to baeldung.log.

    <File name="fout" fileName="baeldung.log" append="true">
        <PatternLayout>
            <Pattern>%d{yyyy-MM-dd HH:mm:ss} %-5p %m%n</Pattern>
        </PatternLayout>
    </File>
</Appenders>```
is there any way i can change where baeldung.log will be created?
bold quartz
#

I would assume that its creating it in working directory

#

so you can just specify the path inside fileName

obtuse peak
#

ok lemme try

#

yep that works thank you!!