logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Karen Goh <karenwo...@yahoo.com.INVALID>
Subject Re: Not able to get logging printout to console, email etc
Date Wed, 01 May 2019 00:24:00 GMT
Thanks Ralp for your reply.
I can’t remember if i have subscribed to the mailing list. From what happened, probably
not.
I will subscribe to it, to avoid missing mail again.



Sent from Yahoo Mail for iPhone


On Tuesday, April 30, 2019, 10:34 PM, Ralph Goers <ralph.goers@dslextreme.com> wrote:

Resending this to you again. You probably didn’t get it because I generally only reply to
the mailing list, not individuals. If you are going to ask questions on a mailing list you
should subscribe.

Here was my answer.

I am not sure where to begin. 
Your log4j2.xml looks fine. 
You should not be using a log4j.properties if you are using Log4j 2. 
The configuration for the JDBC API layer looks like it is for Logback. We don’t recommend
using more than one logging implementation at a time. 
I am not sure why you are using System.out if you are using logging. 
Why do you log findEmail() twice. In fact, calling findEmail() twice might not be a good idea
if it is expensive.

Ralph

> On Apr 29, 2019, at 7:59 PM, Karen Goh <karenworld@yahoo.com.INVALID> wrote:
> 
> Hi,
> 
> I would like to know why am I not getting a reply for my question.
> 
> Anyway, I would like to add that I have now changed to maven web app.
> 
> And here's my log4j2.xml file ;
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE xml>
> 
>     <Configuration status="DEBUG">
> 
>         <Appenders>
>             <Console name="LogToConsole" target="SYSTEM_OUT">
>                 <PatternLayout
>                     pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36}
- %msg%n" />
>             </Console>
>         </Appenders>
>         <Loggers>
>             <!-- avoid duplicated logs with additivity=false -->
>             <Logger name="business" level="debug" additivity="false">
>                 <AppenderRef ref="LogToConsole" />
>             </Logger>
>             <Root level="error">
>                 <AppenderRef ref="LogToConsole" />
>             </Root>
>         </Loggers>
>     </Configuration>
>     
> I also have a log4j.properties file which I am not sure if I should remove it cos I am
not sure should I just use log4j2 will do.  Hope someone can advise me.
> 
> status = fatal
> name = PropertiesConfig
> 
> filters = threshold
> 
> filter.threshold.type = ThresholdFilter
> filter.threshold.level = debug
> 
> appenders = console
> 
> appender.console.type = Console
> appender.console.name = STDOUT
> appender.console.layout.type = PatternLayout
> appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
> 
> # Console appender. (this is added on 7 Mar 2019)
> log4j.appender.console=org.apache.log4j.ConsoleAppender
> log4j.appender.console.layout=org.apache.log4j.PatternLayout
> log4j.appender.console.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
> 
> rootLogger.level = fatal
> rootLogger.appenderRefs = stdout
> rootLogger.appenderRef.stdout.ref = STDOUT
> 
> # Root logger (this is added on 7 Mar 2019)
> # console will log to console (local tomcat) or stdout.log im Tomcat/logs
> log4j.rootLogger=ALL, console
> 
> 
> # Root logger option 
> log4j.rootLogger=INFO, stdout
> 
> # Direct log messages to stdout
> log4j.appender.stdout=org.apache.log4j.ConsoleAppender
> log4j.appender.stdout.Target=System.out
> log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
> log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L
- %m%n
> 
> # Define the root logger with file appender
> log4j.rootLogger = fatal, sql
> 
> # Define the file appender
> log4j.appender.sql=org.apache.log4j.jdbc.JDBCAppender
> 
> #log4j.appender.sql.URL="jdbc:mysql://localhost/hi5project?autoReconnect=true&ampserverTimezone=UTC&ampUseSSL=False";
> log4j.appender.sql.URL="jdbc:postgresql://localhost:5432/membership";
> # Set Database Driver
> #log4j.appender.sql.driver=com.mysql.cj.jdbc.Driver
> log4j.appender.sql.driver="org.postgresql.Driver";
> # Set database user name and password
> #log4j.appender.sql.user=root
> log4j.appender.sql.user=postgres
> 
> #log4j.appender.sql.password=password
> log4j.appender.sql.password=travel8
> # Set the SQL statement to be executed.
> # Define the xml layout for file appender
> log4j.appender.sql.layout=org.apache.log4j.PatternLayout
> 
> 
> log4j.additivity.jdbc.sqlonly=false
> log4j.additivity.jdbc.sqltiming=false
> log4j.additivity.jdbc.audidt=false
> log4j.additivity.jdbc.resultset=false
> log4j.additivity.jdbc.connection=false
> log4j.additivity.jdbc.resultsettable=false
> 
> ! the appender used for the JDBC API layer call logging above, sql only
> 
> <configuration>
>    <appender name="CONSOLE" class="MySQLConstants.class.ConsoleAppender">
>        <encoder>
>            <pattern>%d{yyyy-MM-dd HH:mm:ss}|${HOSTNAME}|%contextName|%-5level|%msg
||%class:%line %n</pattern>
>        </encoder>
>    </appender>
>    <!-- the console defaults to INFO level-->
>    <root level="INFO">
>        <appender-ref ref="CONSOLE"/>
>    </root>
> </configuration>
> 
> com.sun.mail.smtp.SMTPTransport.level = CONFIG
> com.sun.mail.smtp.level = CONFIG
> com.sun.mail.level = CONFIG
> com.sun.mail.util.MailLogger.level = CONFIG
> javax.mail.Session.level = CONFIG
> javax.mail.level = CONFIG
> 
> 
> Besides that, I also have added into my tomcat logging properties file the below lines:
> 
> com.sun.mail.smtp.SMTPTransport.level = CONFIG
> com.sun.mail.smtp.level = CONFIG
> com.sun.mail.level = CONFIG
> com.sun.mail.util.MailLogger.level = CONFIG
> javax.mail.Session.level = CONFIG
> javax.mail.level = CONFIG
> 
> And in my javamail;
> 
> public class sendMail() {
> 
> private static final org.apache.logging.log4j.Logger logger = org.apache.logging.log4j.LogManager
>             .getLogger(sendMail.class);
>     private Connection conn;
>     private PreparedStatement ps = null;
> 
> public void sendEmail(String strEmail) throws MessagingException {
>         init();
> 
>         strEmail = findEmail();
>       System.out.println("Email of registered tutor : " + strEmail);
>         try {
>             Message message = new MimeMessage(session);
>             message.setFrom(new InternetAddress("xxx@gmail.com"));
>             message.addRecipient(Message.RecipientType.TO, new InternetAddress(strEmail));
>             logger.debug(findEmail());
>             logger.info("Sending verify email to {} for {}", findEmail());
>             message.setSubject("Thank you for registering with us");
>             message.setContent("You have successfully registered", "text/html;
charset=utf-8");
>             // Send message
>             Transport.send(message);
>             System.out.println("Mail successfully sent");
>             } catch (MessagingException mex) {
>         
>             }
>     }
> }
> 
> Please. I hope someone can help me on this.
> 
> 
> 
> 
> --- On Wed, 4/17/19, Karen Goh <karenworld@yahoo.com> wrote:
> 
>> From: Karen Goh <karenworld@yahoo.com>
>> Subject: Not able to get logging printout to console, email etc
>> To: log4j-user@logging.apache.org
>> Date: Wednesday, April 17, 2019, 1:44 PM
>> Hi,
>> 
>> I have been trying to make netbeans IDE
>> to churn out a log to see what's causing the error in my web
>> app.
>> 
>> Tomcat : 8.0.27
>> OS : Windows 10
>> 
>> I have created the following
>> log4j.properties which I put under WEB-INF
>> 
>> 
>> # To change this license header, choose
>> License Headers in Project Properties.
>> # To change this template file, choose
>> Tools | Templates
>> # and open the template in the editor.
>> # Root logger option
>> log4j.rootLogger=INFO, stdout, Email,
>> DB
>> 
>> # Direct log messages to stdout
>> log4j.appender.stdout=org.apache.log4j.ConsoleAppender
>> log4j.appender.stdout.Target=System.out
>> log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
>> log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd
>> HH:mm:ss} %-5p %c{1}:%L - %m%n
>> log4j.appender.console.immediateFlush=true
>> log4j.appender.console.encoding=UTF-8
>> 
>> 
>> log4j.appender.Email=org.apache.log4j.net.SMTPAppender
>> log4j.appender.Email.BufferSize=512
>> log4j.appender.Email.Threshold=ERROR
>> log4j.appender.Email.SMTPHost=smtp.gmail.com
>> log4j.appender.Email.SMTPUsername=xxx@gmail.com
>> log4j.appender.Email.SMTPPassword=xxx
>> log4j.appender.Email.From= xxx@gmail.com
>> log4j.appender.Email.To=karenworld@yahoo.com
>> log4j.appender.Email.Subject=Error
>> Report
>> log4j.appender.Email.layout=org.apache.log4j.PatternLayout
>> log4j.appender.Email.layout.ConversionPattern=%d
>> [%t] %-5p %c %x - %m%n
>> 
>> 
>> log4j.rootCategory=DEBUG
>> 
>> 
>> log4j.appender.DB=org.apache.log4j.jdbc.JDBCAppender
>> 
>> log4j.appender.DB.driver=org.postgresql.Driver
>> log4j.appender.DB.URL="jdbc:postgresql://localhost:5432/membership"
>> 
>> log4j.appender.DB.user=membership
>> log4j.appender.DB.password=travel8
>> log4j.appender.DB.sql=INSERT INTO
>> log4j_messages (message, class, priority, log_date) values
>> ('%m', '%c', '%p', to_timestamp('%d', 'YYYY-MM-DD
>> HH24:MI:SS,MS'))
>> 
>> 
>> But, it is not printing out anything to
>> the console.
>> 
>> And the last tomcat log keeps giving
>> something that was done earlier: 
>> 
>> 17-Apr-2019 11:10:34.677 SEVERE
>> [http-nio-8084-exec-17]
>> org.apache.catalina.core.StandardWrapperValve.invoke
>> Servlet.service() for servlet [ProcessRegistration] in
>> context with path [/WebApplication1] threw exception
>> [Servlet execution threw an exception] with root cause
>> java.lang.ClassNotFoundException:
>> org.slf4j.Logger
>> 
>> Here are the libraries I have used:
>> 
>> log4j-core-2.11.2.jar
>> lo4j-to-slf4j-2.11.2.jar
>> log4j-web-2.11.2.jar
>> log4j-api-2.11.2.jar
>> slf4j-api-1.7.25.jar
>> 
>> 
>> <?xml version="1.0"
>> encoding="UTF-8"?>
>> <!--
>> To change this license header, choose
>> License Headers in Project Properties.
>> To change this template file, choose
>> Tools | Templates
>> and open the template in the editor.
>> -->
>> 
>> <configuration status="trace">
>>  <appenders>
>>    <Console
>> name="Console" target="SYSTEM_OUT">
>>      <PatternLayout
>> pattern="%d{HH:mm:ss} [%t] %-5level %logger{36} -
>> %msg%n"/>
>>    </Console>
>>  </appenders>
>> 
>>  <loggers>
>>    <root
>> level="trace">
>>      <appender-ref
>> ref="console" level="trace" additivity="true"/>
>>    </root>
>>  </loggers>
>> </configuration>
>> 
>> Any help that point out where I have
>> gone wrong is greatly appreciated 
>> 
>> Tks & rgds,
>> Karen
>> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 
> 





Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message