Log4j properties file configuration

Hi all,
In the properties file configuration while specifying "Appender" file property, how can we give if we want to save it to different directory ?
Instead of giving like this:
log4j.appender.ErrorAppender.file=error_file.log
I want to have error_file.log to a different folder.
For example: <relativepath> / MyFolder / error_file.log
To specify MyFolder, i gave like this and got the error:
log4j.appender.ErrorAppender.file= MyFolder\error_file.log
how to specify the file to save it in different folder?
Any help would be greatly appreciated...
Thanks,
Manikandan

javainstead:
>>is MyFolder in the root? else you mite wanna try giving the entire path starting from the root
No the "MyFolder" is not in the root. Normally if we give the file name alone, it will store in a directory. Instead of storing in that directory, i want to have create another subfolder under that directory and storing the file in it. This is my need.
OS: Windows 2000.
zakir_sh:
log4j.rootCategory=DEBUG,myproj
log4j.appender.myproj=org.apache.log4j.RollingFileAppender
log4j.appender.myproj.File=/u3/logs/myproj_webapp_logs/dev_region/mylogfile.log......
I gave relative path like this and got the file not found error.
log4j.appender.myproj.File=/MyFolder/error_file.log
Thanks,
Manikandan

Similar Messages

  • Log4j Logger - properties file configuration

    Hi
    This is regarding Apache Log4j logger and the configuration of Log4j.properties file.
    Suppose if I have set the properties file to log the messages in a database. It works fine.
    However, lets say for some reason the database is not accessible for some time.
    Is there a way to configure a "backup" feature in log4j.properties file that basically says that if database is not accessible then log to a temporary file somewhere, may be a text file on the user's system using the RollingFileAppender.

    Hi,
    you can all in the Application class:
    Application.class.getResource( "log4j.properties" ) if its in the Application class package
    Quote:
    URL java.lang.Class.getResource(String name)
    Finds a resource with a given name. The rules for searching resources associated with a given class are implemented by the defining class loader of the class. This method delegates to this object's class loader. If this object was loaded by the bootstrap class loader, the method delegates to ClassLoader.getSystemResource.
    Before delegation, an absolute resource name is constructed from the given resource name using this algorithm:
    If the name begins with a '/' ('\u002f'), then the absolute name of the resource is the portion of the name following the '/'.
    Otherwise, the absolute name is of the following form:
    modified_package_name/name
    Where the modified_package_name is the package name of this object with '/' substituted for '.' ('\u002e').
    Parameters:
    name name of the desired resource
    Returns:
    A java.net.URL object or null if no resource with this name is found
    Since:
    JDK1.1

  • Editing log4j.properties file of ear while deploying ear file.

    Hi,
    Can i edit log4j.properties file of ear while deploying ear file.
    ~ Dhiraj.

    javainstead:
    >>is MyFolder in the root? else you mite wanna try giving the entire path starting from the root
    No the "MyFolder" is not in the root. Normally if we give the file name alone, it will store in a directory. Instead of storing in that directory, i want to have create another subfolder under that directory and storing the file in it. This is my need.
    OS: Windows 2000.
    zakir_sh:
    log4j.rootCategory=DEBUG,myproj
    log4j.appender.myproj=org.apache.log4j.RollingFileAppender
    log4j.appender.myproj.File=/u3/logs/myproj_webapp_logs/dev_region/mylogfile.log......
    I gave relative path like this and got the file not found error.
    log4j.appender.myproj.File=/MyFolder/error_file.log
    Thanks,
    Manikandan

  • Very weird issue with server logging when using log4j.properties file

    I'm using log4j logging. In log4j.properties the root logger is set up to use the ServerLoggingAppender class so that all our application logs go to the main server logfile. In addition, there are several appenders defined for specific components, with output going to specific per-component log files. Everything is going fine until I launch the server console. At this point all of those per-component log files get wiped out (zero length) and some non-ASCII lines are written to at least one of these files, after which the logs appear to be fine. The main server log file does not appear to be affected (because the root logger is set to "warn" level, while component-specific loggers are set to trace, the contents in these files is different; however I tried disabling all the other appenders and turning the root logger up to trace, and that still did not re-create the problem in the main server log file.
    And here's the really weird part -- if I use the same configuration, but in a log4j.xml file, the problem does not happen.

    Figured it out.
    We were passing in the configuration for log4j as -Dlog4j.configuration=file:/<properties file> and this was added to the command line for both the managed and admin servers. Problem is that the console app starts its own instance of log4j, and when it reads the configuration for the appenders it initializes or rolls over the files. At some point we have two JVMs accessing the same files, so some corruption is bound to happen.
    I'm not clear why the .xml file made a difference, but earlier we had been passing the log4j configuration as a jar file placed in the domain/lib folder, so perhaps the designer reverted to that (placed the log4j.xml file in a jar in lib, and not simply changed the -Dlog4j.configuration=file:/ option.

  • Log4J - reading properties file from /WEB-INF directory issue..

    I'm just learning to implement Log4J; the approach I am taking for my JSF application running under Tomcat 5.5x is to create an initialization servlet to initialize the logger, and then access the logger instance within my backing beans and application module services. I include log4j.jar file in /WEB-INF/lib and log4j.properties in /WEB-INF.
    First I wanted to see if this was a good approach, and secondly I'm having trouble accessing the log4j.properties file from the /WEB-INF directory (see below) - any suggestions on how to set up the path so that the properties file can be found (I receive a java.io.filenotfoundexception)?
    Where I'm looking for direction is how to define a single instance of the logger and then access that instance from my java classes versus re-creating the logger in each class.
    ----- web.xml --------
    <servlet>
    <servlet-name>LogServlet</servlet-name>
    <servlet-class>com.sidehire.view.util.LogServlet</servlet-class>
    <init-param>
    <param-name>setup</param-name>
    <param-value>/WEB-INF/log4j.properties</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    </servlet>
    ------ LogServlet class ------
    public void init()
    throws ServletException {
    String config = getInitParameter("setup");
    PropertyConfigurator.configure(config);
    Thanks
    Message was edited by:
    javaX

    Try to put the log4j.properties in your WEB-INF/classes/ directory.
    You could wrap one log4j instance in a static method in a utility class, but then you would probably lose other information depending on your logger configuration.
    If you create an instance in each class, which after all is just one line like this:
    static Logger logger = Logger.getLogger(ChangePasswrdAction.class.getName());
    then you are able to get time and method information.

  • Log4j does not find properties file (but its in the classes directory)

    I am using eclipse, I have created a log4j object:
         private static Logger logger = Logger.getLogger(Http.class.getName());When I try to run the test case, I get:
    log4j:WARN No appenders could be found for logger (com.cable.comcast.nsec.common.Http).
    log4j:WARN Please initialize the log4j system properly.I usually run into this problem when the log4j.properties file is not in the 'classes' directory, but this time it is.
    atlantis@atlantis-laptop:~/workspace/ArborAPI$ cat .classpath | grep output
            <classpathentry kind="output" path="classes"/>
    atlantis@atlantis-laptop:~/workspace/ArborAPI$ ls -la classes/
    total 16
    drwxr-xr-x 3 atlantis atlantis 4096 2008-02-06 16:44 .
    drwxr-xr-x 7 atlantis atlantis 4096 2008-02-06 17:08 ..
    drwxr-xr-x 3 atlantis atlantis 4096 2008-02-06 16:35 com
    -rw-r--r-- 1 atlantis atlantis 2603 2008-02-06 16:44 log4j.propertiesAm I missing something?

    Sorry I was really busy the last few days. Thank you for your answers!
    I probably should have left out all the specifics of what the software was that I was packaging, because I think what I was really asking did not come across clearly. What I really wanted to know is:
    Why do I have to provide the "-I /usr/include/headers_dir" compiler option for some libraries but not for others, although the header files for each lie in a level 1 subdir of /usr/include?
    I thought that maybe there was some kind of index of installed libraries that I didn't know about, which I could have updated from within PKGBUILD (so I guess that's why I included it originally). Seems to me now, though, that this is not the case.
    I did put in some google time (but not lots b/c 1. hard to google and 2. busy) to find an answer, but to no avail and it's not really top priority right now (and quite honestly never will be, since there is the -I option), so I guess it'll have to wait, unless someone knows...
    ---EDIT---
    So, right after I posted this (stupid me) I had a little think and I finally understand, whats happening.
    1. Headers are not found without specifying the directory they are in.
    2. I need the -I option because easykf headers are not well formed.
    Thanks a lot!
    Last edited by maximax (2013-09-27 00:26:03)

  • Cost involved in changing the code using log4j.properties to log4j.xml

    i have finished my application, and it was done in such a way that logging is done using log4j but it was using log4j.properties file.
    now i need to change it to log4j.xml. i need to do this at the earliest. so i need to know the cost involved in it?. do i need to change a lot on my app to read the log4j.xml?. In my app there is a function named getProperties, which actually reads the log4j.properties file.
    this is the code of that function
    public static Properties getProperties(String filename,String path) throws myException
    //InputStream is = null;
    FileInputStream is=null;
            Properties props = new Properties();       
            //ClassLoader classLoader = ResourceUtil.class.getClassLoader();
            //is = classLoader.getResourceAsStream(filename);
            File catalinaHome = new  File(System.getProperty("catalina.home"));     
            try {       
    is=new
    FileInputStream(catalinaHome.getCanonicalFile()+path + filename);
    } catch (IOException e) {
            if(is == null)
                String message = "Cannot locate property file " + filename + " in the classpath";
                log.error(message);
            throw new myException(message);
            try
                props.load(is);
            catch (IOException e)
                String message = "Error reading property file " + filename;
                log.error(message);
            throw new myException(message, e);
            finally
                try
                    is.close();
                catch(Throwable t)
                    t.printStackTrace();
            if(props.isEmpty())
                String message = "No properties are defined in " + filename;
                log.error(message);
            throw new myException(message);
            return props;       
    }and my initialize function is
    public static void initialize()
    Properties properties=null;
    try {
    String path="/properties/";
    properties=ResourceUtil.getProperties("log4j.properties",path);
    } catch (myException e2) {
    e2.printStackTrace();
    PropertyConfigurator.configure(properties);
    }Message was edited by:
    xema
    Message was edited by:
    xema
    Message was edited by:
    xema

    >
    1. Restructure log4j.properties into log4j.xml.
    thats done
    2. Move log4j.xml into a directory that's in the
    classpath.
    actually i donot understand what does it mean to move in a directory thats in classpath means. i have to use logging in my webapplication running in tomcat. and my log4j.xml has to reside in catalina.home/properties/. My log4j.properties have been residing here and it had worked well woth the previous function. Now what i did is placed the log4j.xml under properties folder. Now tell me what modifications should i make in the above code.
    3. Remove any code that explicitly configures log4j
    (i.e. the initialize() method) because log4j will
    configure itself from any properties file it finds in
    the classpath, automatically, the first time it is
    called.I prefer not remvoing this function as this function is being called in many of my classes... and we don't have time to edit all...
    please help... and excuse me if i asked some blunders.!!!

  • URGENT!!! can I borrow a valid jserv.properties file for a JSP application ?

    Hi there !
    I'm running Oracle enterprise edition on NT with oracle http server under apache.
    I created a JSP application using jdeveloper
    and deployed it to the web server.
    Now I'm still getting getting nullPointer exceptions after I have modified the jserv.properties file according to the documentation
    Can someone give me a file that is working for her/him under the above described circumstances ?
    Many Thanaks in advance
    Tony
    null

    laredotornado wrote:
    Hi,
    This might not be a JSF question, but I thought I'd start here as I'm building a JSF application. Upon startup of my Weblogic 9.2.2 server, I see these error messages
    log4j:WARN No appenders could be found for logger (org.apache.myfaces.webapp.StartupServletContextListener).
    log4j:WARN Please initialize the log4j system properly.
    One complication, my log4j.properties file is actually called "my.properties" (bizarre company reason). Is there somewhere in my faces-config.xml file or an equivalent where I can indicate what log4j properties file I'd like to use?Your company policy is to use non-standard names so that things must be configured manually? Interesting.
    In the past people created a servlet those sole purpose was to configure log4j in the initialization sequence and then do nothing.

  • Log4j.properties location

    Hello,
    I want my web application uses a log4j.properties file located in a directory outside Tomcat, in /var/app/conf/.
    I'm using the PropertyConfigurator to configure log4j. If I put log4j.properties in the WEB-INF/classes directory all works fine, but if I put it in the "external" directory works but I get these warnings:
    log4j:WARN No appenders could be found for logger (org.apache.catalina.startup.TldConfig).
    log4j:WARN No appenders could be found for logger (org.apache.commons.digester.Digester.sax).
    How could I avoid these warnings?
    Thanks!

    I am putting log4j.properties file in same folder
    where the java class file is, it's working fine. If
    i'm puting it in some different folder (folder is on
    class path) it's giving the proper output as log file
    but throwing exception at console as:I don't think it's the location of the java class, but rather
    where you are when you run the program. I'm running
    junit tests from within eclipse, and need to put the file
    one directory above my "com" directory. From the
    command line, the properties file just needs to be in
    the current directory. Perhaps using a fully qualified
    path name will solve your problem; no matter where
    you run the program, the file will be found. This
    assumes you have access to a fully qualified location
    (probably bad). Best to determine from where the
    program will be run, and place the file in a relative
    directory off of that (perhaps at deploy time).
    Cheers,
    Brian

  • Log4j.properties with OAF R12

    I am writing OAF R12 components that integrate/extend existing R12 pages.
    I need to deploy a log4j.properties file for logging. I have a dependent jar file that uses log4j. This file is usually placed on the classpath in WEB-INF/classes for a servlet application.
    Where should I place this log4j.properties file so that the OAF R12 container (oc4j) reads this file when processing. I tried to add it to the CLASSPATH. I edited orion_application_xml_1013.tmp and placed the log4j.properties in $JAVA_TOP and added lines for the <library path> as
    <library path="$JAVA_TOP/log4j.properties" /> or
    <library path="%s_javatop%/log4j.properties" />
    and restarted the server.
    However, the log file defined in log4j.properties is not created when running the OAF framework and exercising the integrated code that includes log4j logging.
    What is the best way to integrate this properties file?
    Thanks,
    Ken

    gday Ken --
    If you are OAF R12 wouldn't there be an Oracle standard for logging you should be using? I'd be asking the OAF team for more details.
    Then I'd ask whether using log4j is worth the extra effort over using the Java standard logging API -- the container itself is using Java standard logging API, for which we have the ability to dynamically adjust log levels, view the logs, etc.
    Here are some links to some notes I wrote up recently on using log4j with OC4J (and also using Java standard logging API) :
    http://buttso.blogspot.com/2007/09/directing-log-messages-into-oc4j.html
    http://buttso.blogspot.com/2007/09/directing-log4j-logs-into-oc4j-logging.html
    http://buttso.blogspot.com/2007/09/using-shared-libraries-to-configure.html
    -steve-

  • LMS3.2.1 - should my custom log rotation settings override log4j properties?

    For LMS 3.2.1 on Windows, I have configured log rotation settings for dcmaservice.log but the settings are ineffective, even after stop/start CW daemon manager.  Other posts on this forum state that dcmaservice.log rotation is managed by log4j but can also be configured in logrot.  Is this incorrect or have I encountered a bug in logrot?

    Gaganjeet,
    I'd like definitive answers to the following questions before continuing down this path.
    1) does log4j subsystem manage dcmaservice.log?
    2) if so, is there a log4j properties file for dcmaservice which can be edited to change log file size and number of versions to keep (eg. see the forum entry https://supportforums.cisco.com/message/664225#664225 re license.log)?
    3) can Common Services user-configurable log rotation override the parameters for logs managed by log4j subsystem?
    Thanks.

  • Log filename in log4j.properties

    Hi,
    I use log4j for logging. It's configured in a log4j.properties file. I want to make a new logfile for each day, with the date appended to the filename. Is it possible to do this just with the log4j.properties configuration or I must configure the log in the program?
    Thanks
    Rui Gon?alves

    There is a DailyRollingFileAppender to use.

  • Environment Variable Properties file

    Using log4j and creating a log4j properties file. "log4j.properties".. How do I specify the home directory in the properties file ? On command line I might use $HOME but I don't think that works in a properties file. I'd like any log file generated to be placed in a directory under the home directory. So the log4j.properties file needs to contain the line..
    log4j.appender.A2.File=$HOME/foo/log.txt
    But I'm seeing FNFE set file failed...

    Or, do what I should have done in the first place:
    read the API documentation for PropertyConfigurator
    where it says
    "All option values admit variable substitution. The
    syntax of variable substitution is similar to that of
    Unix shells. The string between an opening "${" and
    closing "}" is interpreted as a key. The value of the
    substituted variable can be defined as a system
    property or in the configuration file itself. The
    value of the key is first searched in the system
    properties, and if not found there, it is then
    searched in the configuration file being parsed. The
    corresponding value replaces the ${variableName}
    sequence. For example, if java.home system property
    is set to /home/xyz, then every occurrence of the
    sequence ${java.home} will be interpreted as
    /home/xyz."
    So your guess was close.Good to know I can do that with all variable names. I should have know to look at the API too. Thanks again :o)

  • Log4j.properties ???

    hi,
    I'm currently working with applets and try to call a web service from my applet. I receive this error message :
    log4j:WARN No appenders could be found for logger (org.apache.axis.i18n.ProjectResourceBundle).
    log4j:WARN Please initialize the log4j system properly.
    Does somebody know where I have to declare this log4j.properties file ? Do I have to configure something by the client ?
    Finally does somebody know if it is possible to call web services from an applet (I mean on the same host) without using signed applets ????
    TU
    PA
    http://www.doffoel.com

    I believe that the log4j.properties file has to be in
    your classpath.
    and in an applet, this means placing log4j.properties in the root of your applet's JAR file.
    The problem you are going to run into, though, is what you are going to do with the logging information. Unless you sign the applet, you won't be able to write the log to disk... I suppose there might be an appender that could write back to your server (or you could implement one), but I'm not sure that's going to do what you are trying for...
    - K

  • Log4j log file not being created

    Using websphere for a web app. At first I was getting the error log4j:WARN No appenders could be found for logger....
    So I created the property file and I assume correctly referenced it. The error went away and my logging messages are showing up in the websphere console, but the .log file specified in my log4j.properties file is not being written to... it is only writing to my systemOut.log.
    If I remove the ROOT.File line it still does not create the file (I've done a search on the IBM directory
    #Default log level to ERROR. Other levels are INFO and DEBUG.
    log4j.rootLogger=INFO,ROOT
    log4j.appender.ROOT=org.apache.log4j.RollingFileAppender
    log4j.appender.ROOT.File=c:\myapplication.log
    log4j.appender.ROOT.MaxFileSize=1000KB
    #Keep 5 old files around.
    log4j.appender.ROOT.MaxBackupIndex=5
    log4j.appender.ROOT.layout=org.apache.log4j.PatternLayout
    #Format almost same as WebSphere's common log format.
    log4j.appender.ROOT.layout.ConversionPattern=[%d] %t %c %-5p - %m%n
    #Optionally override log level of individual packages or classes
    log4j.logger.com.webage.ejbs=INFO       
    private static final Logger logger = Logger.getLogger(LoginAction.class);
        public ActionForward execute(ActionMapping mapping, ActionForm form,
                HttpServletRequest request, HttpServletResponse response)
                throws IOException, ServletException {
            initializeLogger();
    private void initializeLogger() {
            org.apache.log4j.BasicConfigurator.configure();
    //trying the above just to get it to work.. because by default this
    //should look in WEB-INF/classes/log4j.properties... I thought
            /*try {
                String log4jUrl = servlet.getServletContext().getInitParameter(
                        "LOG4J_XML");
                if (!(log4jUrl == null || log4jUrl.equals("")))
                    DOMConfigurator.configure(servlet.getServletContext()
                            .getResource(log4jUrl));
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (FactoryConfigurationError e) {
                e.printStackTrace();
        }    Edited by: gmachamer on Nov 30, 2007 6:37 AM

    ok changed to xml file and found a few things out.
    now when I debug though the logger that was created has an empty level... but if I look at the parent logger it is correctly pulling the root logger from my xml (if I change the priority attribute then it changes when debugging the code)
    <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true">
         <!-- this appender would be the same as having a System.out -->
         <appender name="console" class="org.apache.log4j.ConsoleAppender">
              <param name="Target" value="System.out"/>
              <layout class="org.apache.log4j.PatternLayout">
                         <param name="ConversionPattern" value="%-5p %c{1} - %m%n"/>
                  </layout>
           </appender>
           <appender name="rollingFileAppender" class="org.apache.log4j.RollingFileAppender">
              <!-- name and location of the file to log to -->
                 <param name="File" value="c:/appLog.log"/>
              <!-- the maximum size the file will be before it rolls the file -->
                 <param name="MaxFileSize" value="1000kb"/>
              <!-- the number of backups you want to maintain -->
              <param name="MaxBackupIndex" value="5"/>
              <!--
                   This is the layout of your messages, you can do alot with this.
                   See the java docs for the class PatternLayout for an explanation of
                   the different values you can have.
              -->
                 <layout class="org.apache.log4j.PatternLayout">
                          <param name="ConversionPattern" value="%t %-5p %c{2} - %m%n"/>
                      </layout>          
              </appender>
           <root>
                  <priority value ="error" />
                  <appender-ref ref="rollingFileAppender" />
                  <appender-ref ref="console" />
           </root> 
    </log4j:configuration>

Maybe you are looking for