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

  • Home
  • SEARCH
  • 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 9184365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:01:45+00:00 2026-06-17T19:01:45+00:00

This is my bean class AppLogger.java public class AppLogger { private String logMessage; public

  • 0

This is my bean class AppLogger.java

public class AppLogger {

    private String logMessage;

    public String getLogMessage() {
        return logMessage;
    }

    public void setLogMessage(String logMessage) {
        this.logMessage = logMessage;
    }
}

My log4j.properties

# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=C:\\loging.log
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

# 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{ABSOLUTE} %5p %c{1}:%L - %m%n

# Root logger option
log4j.rootLogger=debug, file, stdout

My Log4j.xml

<bean id="appLogger" class="com.sort.model.AppLogger">
   <property name="message" value="Logger!"/>
   </bean>

My Web.xml

<context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>/WEB-INF/Log4J.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>

My controller, where I am trying to log a sample message.

public class BasicFormController {

    private static final Logger logger = Logger.getLogger(BasicFormController.class);

    @ModelAttribute("evaluation")
    protected List<String> referenceData(HttpServletRequest request) throws Exception {

        logger.info("creating a message");
        List<String> evaluation = new ArrayList<String>();
        evaluation.add("Evaluated");
        evaluation.add("Not Evaluated");
        return evaluation;

    }
}

My servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

    <!-- Enable annotation driven controllers, validation etc... -->
    <mvc:annotation-driven />
    <context:component-scan base-package="com.sort.controller" />

    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value></value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>

    <bean id="multipartResolver"
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    </bean>
    </beans>

I have log4j-1.2.14.jar in my build path.
Now the problem is, I am getting 404 error. The app runs well without all these Log4j relevant matter.
Can you please help me out of this?
Or can someone guide me to a proper example where they demonstrate the logging of a Spring MVC project?

  • 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-17T19:01:49+00:00Added an answer on June 17, 2026 at 7:01 pm

    I used the the xml approach and logged the code flow. Thanks for all your responses.

    Here is the log4j.xml I have used…

    <?xml version="1.0" encoding="UTF-8" ?>
    <log4j:configuration debug="true">
    
        <appender name="ROLL" class="org.apache.log4j.RollingFileAppender">
            <!-- The active file to log to -->
            <param name="file" value="D:/portal.log" />
            <param name="append" value="true" />
            <param name="encoding" value="UTF-8" />
    
            <rollingPolicy class="org.apache.log4j.TimeBasedRollingPolicy">
                <!-- The file to roll to, this is a fairly intelligent parameter, if the 
                    file ends in .gz, it gzips it, based on the date stamp it rolls at that time, 
                    default is yyyy-MM-dd, (rolls at midnight) See: http://logging.apache.org/log4j/companions/extras/apidocs/org/apache/log4j/rolling/TimeBasedRollingPolicy.html -->
                <param name="FileNamePattern" value="D:/portal.%d.log.gz" />
            </rollingPolicy>
    
            <layout class="org.apache.log4j.PatternLayout">
                <!-- The log message pattern -->
                <param name="ConversionPattern" value="%5p %d{ISO8601} [%t][%x] %c - %m%n" />
            </layout>
        </appender>
    
        <!-- Loggers to filter out various class paths -->
    
        <logger name="org.hibernate.engine.loading.LoadContexts"
            additivity="false">
            <level value="error" />
            <appender-ref ref="ROLL" />
        </logger>
    
        <!-- Debugging loggers -->
    
        <!-- Uncomment to enable debug on calpoly code only -->
        <!-- <logger name="edu.calpoly"> <level value="debug"/> <appender-ref ref="ROLL" 
            /> </logger> -->
    
        <root>
            <priority value="info" />
            <appender-ref ref="ROLL" />
        </root>
    
    </log4j:configuration>
    

    I deleted the properties file and dropped that approach.

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

Sidebar

Related Questions

I have this bean: @ManagedBean(name=langListing) @ViewScoped public class LangListing implements Serializable { private List<SelectItem>
This bean State : public class State { private boolean isSet; @JsonProperty("isSet") public boolean
i have an managed bean(session scope) like this: class Home {// as homeBean public
I am using Hibernate to persist this bean. import javax.persistence.*; @Entity public class Person
Here's my Bean class source @Stateless(mappedName=StringVal) public class NewSessionBean implements NewSessionRemote { String val
i have this bean public class Advertisement{ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = pkid,
I have an Java bean class Person containing 3 variables: name (String) age (String)
public class MyBean { private Integer [] myField; public Integer [] getMyField() { return
i have bean that contain method [void return] and want access to this bean
I have this Spring config: <bean id=boo class=com.x.TheClass/> The class TheClass implements TheInterface .

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.