Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7900477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:58:50+00:00 2026-06-03T08:58:50+00:00

I am developing a mobile application and im using log4j to display information. I

  • 0

I am developing a mobile application and im using log4j to display information. I want to use log4j to display information on the console which it is doing correctly but i am having trouble when I try adding a SMTPAppender to send a email when ever an error occurs. It is not displaying an error but the tomcat does not start correctly when I start it with the SMTPAppender is added.

I am using Apache Tomcat 7.0.23

This is my log4j.properties file

log4j.rootCategory=TRACE, stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} [application] %-5p %m%n


log4j.rootCategory=ERROR, mail

log4j.appender.mail=org.apache.log4j.net.SMTPAppender
#defines how often emails are send
log4j.appender.mail.BufferSize=1
log4j.appender.mail.SMTPHost=smtp.gmail.com
log4j.appender.mail.SMTPUsername=*******   #not the username im using
log4j.appender.mail.SMTPPassword=*******   #not the password im using
log4j.appender.mail.From=info@gmail.com
log4j.appender.mail.To=noc@gmail.com
log4j.appender.mail.Subject="Application.log error occurred"
log4j.appender.mail.layout=org.apache.log4j.PatternLayout
log4j.appender.mail.layout.ConversionPattern=%d{ISO8601} [application] %-5p %m%n

This is my console

Found binding in [jar:file:/C:/Documents%20and%20Settings/noconnor/.m2/repository/org/slf4j/slf4j-simple/1.6.1/slf4j-simple-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Documents%20and%20Settings/noconnor/.m2/repository/org/slf4j/slf4j-log4j12/1.6.2/slf4j-log4j12-1.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.

is this the correct way to add a second appender or am i making a mistake somewhere?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T08:58:52+00:00Added an answer on June 3, 2026 at 8:58 am

    You can only have one log4j.rootCategory property.

    You can have multiple appenders:

    log4j.rootCategory=TRACE, stdout, mail
    

    But you probably don’t want all messages go to mail. For this, you need to add priority filter to your mail appender, but I think that’s only possible to do using XML syntax instead of log4j.properties.

    Here is an example for using both appenders, but “mail” appender is only activated for ERROR and FATAL messages.

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
    
    <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
      <appender name="stdout" class="org.apache.log4j.ConsoleAppender"> 
        <param name="Target" value="System.out"/> 
        <layout class="org.apache.log4j.PatternLayout"> 
          <param name="ConversionPattern" value="%d{ISO8601} [application] %-5p %m%n"/> 
        </layout> 
      </appender> 
    
      <appender name="mail" class="org.apache.log4j.net.SMTPAppender">
        <!-- mail configuration here... -->
    
        <layout class="org.apache.log4j.PatternLayout"> 
            <param name="ConversionPattern" value="%d{ISO8601} [application] %-5p %m%n"/> 
        </layout> 
    
        <filter class="org.apache.log4j.varia.LevelRangeFilter">
            <param name="levelMin" value="ERROR" />
            <param name="levelMax" value="FATAL" />
        </filter>
      </appender>
    
      <root> 
        <priority value="trace" /> 
        <appender-ref ref="stdout" /> 
        <appender-ref ref="mail" />
      </root>
    
    </log4j:configuration>
    

    You need to add more mail configuration options to match your original properties file. This file must be called “log4j.xml” and must be used instead of “log4j.properties” (remove this one).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Netbeans IDE (J2ME) for developing a mobile application, a dictionary which
I am developing an app using phonegap for Android. I want this mobile application
I am developing an application using jquery mobile and flot charts. In That i
I am developing an application using jQuery mobile 1.1.0 RC1 and phonegap 1.5.0 I
I'm developing an winform application for Windows Mobile 5.0 and above. I'm using .Net
I am developing an mobile application which can be run on mobile devices (with
I am developing a mobile social TV application on Android.I want to integrate Facebook
I'm developing a mobile application using J2me for a configuration CLDC-MIDP2.0. In my mobile
I'm developing a mobile application using J2ME for a configuration CLDC-MIDP2.0 . In my
I am developing asp.net mobile application. I am using LINQ to XML to query

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.