What is better Java Logging or Log4J?

What is better Java Logging or Log4J and why?

for my money, log4j has the edge, largely because it doesn't keep a lock on log files when they're not actually being written to. but on the downside, it's another third-party library you have to use. then again, every project I've worked on recently has had it imported anyway via some other third-party library like Spring or Hibernate, so it's there anyway
but only you can answer "which is more suitable for me"

Similar Messages

  • Want to Generate custom logs with Log4J within Java Embedding activity

    Hi Gurus,
    i want to Generate custom logs with Log4J within Java Embedding activity. For that i have performed some steps, but the log file has not been created.
    ServerSide Configuration:
    *===============*
    1. I have copied the log4j-1.2.15.jar file to the "oracle.soa.ext_11.1.1" location and recreate the oracle.soa.ext.jar file using an-script, which appends the log4j.jar file to the classpath.( That was created successfully)
    2. Specify a File location in log4j.xml for creating the log file. (e.g. (<middleware_home>/config/customLog.log)
    3. Then create a folder and add log4j.xml and log4j.dtd file under the folder.
    4. Modify the startManagedWeblogicServer by adding JAVA_OPTIONS="-Dlog4j.configuration=<middleware_home>/config/log4j.debug.xml”
    5. Then restart the SOA server.
    log4j.xml :
    I have used fileAppender.
    DevelopmentSide Configuration:
    *===================*
    1. Create synchronous BPEL process and Add "JAVA Embedding Activity" inbetween receiveInput and replyOutput activity.
    2.Import the log4j-1.2.15.jar to the project libs
    3.In the BPEL source code, import the Logger class.
    4.Insert the code in the JAVA Embedding Activity
    Logger logger = Logger.getLogger("CustomLog");
    logger.info("CustomeLog " + getTitle());
    Compile and deploy the project into the SOA_server and test it. Test status is completed but log is not created in the mentioned location.
    Ref: http://blog.andrade.inf.br/search/label/Log4j
    Is there any other way to achieve this requirement. Please suggest.
    Thanks in Advance,
    Sharmistha

    You can try this.
    http://veejai24.blogspot.co.uk/2008/04/simple-way-to-implement-log4j-in-your.html
    Thanks,
    Vijay

  • Use Java Logging mechanism

    We have a requirement to log application errors in a local log file in the form of key/value pairs (from a property object) after every transaction, append to the previous transaction and generate one log file for each day.
    Log file example,
    currentTime=xxxx
    message=xxxxx
    userId=xxxx
    etc.
    What would be the best way to do it ? Can I take advantage of the Java Logging API, like file handler , although it does not do exactly what I wanted ?

    Thanks for the reply. But the company standard does
    not allow open source package like log4j.Then the company standard is completely nuts... but they're like that aren't they... I'd still get a copy of the log4j source from the apache site, to use a working example of how to do it well... then maybe write a simplified "write behind" logging service based on it... a single format "log4j-lite"
    Have fun with it.
    Keith.

  • Application specific logging with Log4j on weblogic 8.1

    Hi,
    For a few days now, I have been trying to implement application specific logging using Log4j (1.2.x) for my 3 applications running on the same server (8.1.6). All three application war files are generated from same source. I followed the example of Jboss in setting up the Hierarchy for logging using RepositorySelector. In my case Java class which implements RepositorySelector is loaded through ServletContextListener from jar file placed in WEB_INF/lib folder and log4j.properties file is in WEB-INF folder of each application.
    Independent logging of each application takes place correctly, if the applications are deployed from console. However logging fails if weblogic is shutdown and restarted, in this case logging takes place from 2 classes only implementing filters of each application. Logging from other classes is not taking place. I am spinning my wheels on this and can't seem to figure out what the issue is.
    Thanks for any help...below is the snippet of code
    Sohan
    public static synchronized void init(ServletContext config, String strLogProperties, String webAppName)
    throws ServletException {
    if( !initialized ) // set the global RepositorySelector
    defaultRepository = LogManager.getLoggerRepository();
    RepositorySelector theSelector = new MyRepositorySelector();
    LogManager.setRepositorySelector(theSelector, guard);
    initialized = true;
    Hierarchy hierarchy = new Hierarchy(new RootCategory(Level.DEBUG));
    loadLog4JConfig(config, hierarchy, strLogProperties, webAppName);
    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    repositories.put(loader, hierarchy);
    config.setAttribute("hierarchy", hierarchy );
    public LoggerRepository getLoggerRepository() {
    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    LoggerRepository repository = (LoggerRepository)repositories.get(loader);
    if (repository == null) {
    return defaultRepository;
    } else {
    return repository;
    public void LogInit(ServletContext ctx) throws ServletException {
    System.out.println("\n\n---------------Log4jInit---------------\n\n");
    String strLogProperties = ctx.getInitParameter("Log4JProperties");
    System.out.println("Log4j properties " + strLogProperties);
    String webAppName = ctx.getInitParameter("LogFileName");
    System.out.println("App log File name " + webAppName);
    if (webAppName == null ) {
    webAppName = getWebAppName(ctx);
    System.out.println("Application name = " + webAppName);
    MyRepositorySelector.init(ctx, strLogProperties, webAppName);
    LOG = Logger.getLogger(this.getClass());
    LOG.info("Log message from Log4jInit ServletContextListener");
    System.out.println("\n\n---------------Log4jInit: Complete---------------\n\n");
    }

    Has anyone been able to get around the "Export of object xxx barred" error when
    trying to access the object?
    Thanks,
    Kevin
    "Koua" <[email protected]> wrote:
    >
    I have the same problem when adding listener for COM events. I think
    it's a bug
    in Weblogic. It seems that no one can help.
    Teresa Canales <[email protected]> wrote:
    Hi,
    I am getting the following error. I am not sure how to fix this. I
    looked in everywhere on the admin console and couldn't find anything.
    The following is what I am getting....
    BEA-210000 Apr 14, 2004 11:05:42 AM EDT servicelayertrain
    Error COM Export of object: com.symphonyhealth.user.facade.ejb.User_eecm3e_HomeImpl@2ba3e4
    barred
    Any help would be greatly appreciated.
    Teresa

  • Java logging questions - an example would really help

    We have taken over a project (i.e. we inherited someone else's code). I am relatively new to java. We would like to add debug messages or log messages to trace the application. Is there an easy way to insert debug messages and view the applicable log files?
    1.) I added the following code to add a debug message "log.error("Inside doResetPassword (" + userIdentification + ", " + newPassword + ")");"
    2.) Where is this log file located (what is the name of the log file)? Do I have to enable logging in Oracle? What are the steps to enable the logging? Is there a console that displays the log messages?
    Any help would be greatly appreciated ...
    Thanks,
    Mike
    public class AuthenticationListener implements Listener {
    private static final Log log = LogFactory.getLog(AuthenticationListener.class);
    PersonnelService personnelService;
    EmailService emailService;
    * Setter for Spring injection of {@link EmailService}.
    * @param emailService
    public void setEmailService(EmailService emailService) {
    this.emailService = emailService;
    * Setter for Spring injection of {@link PersonnelService}.
    * @param personnelService
    public void setPersonnelService(PersonnelService personnelService) {
    this.personnelService = personnelService;
    public void doResetPassword(String userIdentification, String newPassword) {
    Personnel personnel = personnelService.loadPersonnelById(Integer.parseInt(userIdentification));
    log.error("Inside doResetPassword (" + userIdentification + ", " + newPassword + ")");
    try {
    emailService.send(new PasswordEmail(personnel, newPassword));
    } catch (Exception e) {
    log.error("AuthenticationListener.doResetPassword: " + e.getMessage());
    }

    Hi,
    You should check out log4j. It's pretty easy to use, and has been the favorite logging tool for pretty much everyone I've worked with for the last few years. It's free, just google it.
    You won't have to change your java code, it plugs into the standard Java logging facility automatically.
    You just put log4j.jar and log4j.xml into your applib directory. Here is an example of a log4j.xml file that logs both to the console and to the file /logs/my.log. It assumes your code is in 'com.mypackage.' You can have as many logger elements as you want, and have different packages or classes set to different logging levels.
    <pre>
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
    <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
         <appender name="console" class="org.apache.log4j.ConsoleAppender">
              <param name="Target" value="System.out" />
              <layout class="org.apache.log4j.PatternLayout">
                   <param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p %C %m%n" />
              </layout>
         </appender>
         <appender name="file" class="org.apache.log4j.RollingFileAppender">
              <param name="File" value="/logs/my.log" />
         <param name="Append" value="true" />     
              <layout class="org.apache.log4j.PatternLayout">
                   <param name="ConversionPattern"
                        value="%d{HH:mm:ss,SSS} %-5p %c %m%n" />
              </layout>
         </appender>
         <logger name="com.mypackage">
              <level value="debug" />
         </logger>
         <root>
              <priority value="warn" />
              <appender-ref ref="console" />
              <appender-ref ref="file" />
         </root>
    </log4j:configuration>
    </pre>
    Hope that helps,
    Mike from Ottawa

  • Error in Logging using log4j When deployed in weblogic server

    I have deployed an SOAP based web service application as an war file and used log4j propertiers to do application logging .When i tested the application through a JAVA client the log4j log file has all the application log information but when i deployed it in the weblogic server 10.3.3 and tested it through SOAP UI it gives me just "Run time error exception" in the log4j log file(which is returned in the SOAP response) as against the application logs which i need. I have also added <wls:package-name>org.apache.log4j.*</wls:package-name> in the weblogic.xml and also changwed the logging to the log4j logging in the server ( which was perviously JDK logging) .But still it is not returning the complete application error stack trace in the log4j log file(and also in the weblogic command console) I need to get the application error stack trace in the log4j log file ( and also in the console) so it would be easy to debug the code.
    Please help me out in doing the same.
    thanks in advance

    Noman,
    have you checked that the folder D:\OracleJeveloper\Middleware\jdk160_14_R27.6.5-32 contains the jre?
    Timo

  • What is better way for creating a thread? Why?

    A thread can be create in two way, extending Thread class or implimenting Runnable.
    What is better way for creating a thread? Why?

    Implementing Runnable
    See FAQ #1 here [http://forum.java.sun.com/ann.jspa?annID=9]

  • Practical use of Java Logging API

    There was a recent technical tip about the Java Logging API, but after reading it I still don't understand how to use it in a real situation.
    Can anyone help me with this with a practical example?
    At the moment I have try-catch clauses that catch exceptions and print a message in a System.err log that I can consult if there's a specific problem.
    How should I be using the Logging API? I feel sure that it can help me, but can't see how.
    Thanks for any practical information.

    What if you don't want to write to system.err anymore? What if you need to write something to the windows event log? What if system.err is irrelevant (nt service), ...
    Btw, lots of examples on the JDK1.4 logging api:
    http://www.esus.com/docs/GetIndexPage.jsp?uid=265

  • AS Java logs

    Hi All,
    I have few question on AS Java logs.
    - how many type of log files can be generated and what are they? (e.g - security audit log, security log, system log, etc)
    - whether logs are activated by default? how to activate the log?
    - how to extract logs? whether I can use ABAP itself or any other way to extract?
    Thank you.
    With Regards,
    Gandhi Subramani

    1) I have format for security audit log. Can you give the file format of security log file?
    I checked here on a system, and there is no format defined. (if this is what you mean...)
    2) Whether data in log file depends on OS where AS java server is installed?
    (example : event date will be seconds since 1970-01-01 00:00:00 UTC in linux)
    No, as far as I know (just checked a Windows system) the time stamp in the logfile is written in epoch format. (like you already mentioned)
    Check http://www.epochconverter.com on how to convert epoch to a readable format.
    3) Any API's available for fetching the logs?
    That is very likely, but I don't know them... You could write a script yourself to analyze this log.
    Kind regards,
    Mark

  • Java Logging - Socket Handler

    How to use Socket Handler of java.util.logging package. Do we need to write a SocketServer to receive the LogRecord from SocketHandler or java itself provides SocketServer implementation to log the records?

    I am not seeing any socket server implementation just like log4j in java logging (JDK1.4.2) API documentation. I just want to know is there any additional packages available for this.

  • Dynamic java logging properties file

    Hello,
    I am looking for a dynamic way to set a property in a java logging properties file.
    For example something like this:
    java.util.logging.FileHandler.pattern = ${log.dir}/logfile%u.log
    ..where log.dir is a system property. But this does not work. Any other way to do it?
    Thanks in advance,
    Rohnny

    This pattern doesn't work ? here is the content of my
    logging.properties file.
    java.util.logging.FileHandler.pattern = LOGFILE.log
    java.util.logging.FileHandler.limit = 50000
    java.util.logging.FileHandler.count = 1
    java.util.logging.FileHandler.formatter =
    java.util.logging.SimpleFormatter
    FIRST_LOGGER.Handler = java.util.logging.FileHandler
    FIRST_LOGGER.level = ALL
    SECOND_LOGGER.Handler =
    java.util.logging.FileHandler
    SECOND_LOGGER.level = ALLIt seems like you're not thoroughly reading the spec on this stuff.
    I don't think ".Handler" is even a valid property on a logger.
    Loggers aren't typically initialized with a complex configuration out of a configuration file...unless you write your own custom format. For instance, FileHandler is a class, so when you define java.util.logging.FileHandler.pattern in the config file, you're defining it for every default instance of FileHandler...so naturally both your loggers that use FileHandlers will write to the same file.
    I've never done this before, but here's what I came up with after reading the spec:
    1) define 1 subclass of FileHandler for each file you want to write to... let's call them FileHandlerA and FileHandlerB. All they have to do is extend FileHandler, nothing else.
    2) define the patterns for each subclass in the config file. You can also define any other properties you want for each handler, such as .level, .limit, .count, etc.
    mypackage.myhandlers.FileHandlerA.pattern = LogFile-A.log
    mypackage.myhandlers.FileHandlerB.pattern = LogFile-B.log
    // ... more config here
    3) define the loggers in the config file and specify the handlers to use on each:
    FIRST_LOGGER.handlers = mypackage.myhandlers.FileHandlerA
    SECOND_LOGGER.handlers = mypackage.myhandlers.FileHandlerB
    4) create your Loggers in your code:
    Logger firstLog = Logger.getLogger("FIRST_LOGGER");
    Logger secondLog = Logger.getLogger("SECOND_LOGGER");
    Good luck.

  • Buffer Overflow Exploit from beta java 16 to beta java 20

    I have a pretty severe virus complete with a remote server, and when opening up a form in java from java 16 to beta java 20. the java program crashes whenever your entering information into a form. in chrome it says that java has crashed when trying to type into a form(it then doesnt allow the username field to be typed in and then freezes (it wont allow it to focus so you can type in your username or password) for a couple seconds. The same thing happens in internet explorer. I'm running windows 7. Even with my setup, the program definetly still has security holes.
    (the site itself is fine,webct, i didn't click onto a phishing site, the website works fine on any other computer, but the exploit has been used on my computer)
    Edited by: user12865305 on Mar 27, 2010 6:39 PM
    Edited by: user12865305 on Mar 27, 2010 6:40 PM

    This is the forum for Berkeley DB, Java Edition. Your question belongs on another forum, though I'm not quite sure what that would be.
    Regards,
    Linda

  • What possible things to log in mvc webapp

    I'm about to learn to handle logging in my c# asp.net mvc app and are going to store my log in a noSQL-db. How to handle the logging is done. The thing is I'm having a hard time to figure out possible things to log.
    The app I'm building is a quite regular website, were a admin-user can login and edit content on the site using a wysiwyg-editor. Visiting users can send mail using a simple form.
    The things I'm planning to log info about is functionalities like:
    admin login/logout
    visiting user send-mail status
    admin changing content in the wysiwyg-editor(driven by js-function sending data to a c#-method through ajax. So basiclly log info when the c#-method gets hit)
    To my question: what other possible things can I log in this type of application?
    Any suggestions would be helpful

    Hello
    techelite1337 ,
    Not the right forum for your case. Please post ASP.NET related issue to this forum:
    http://forums.asp.net/
    In general, you need to manually export what you want to log to a file with in a order. Please search for some classes or API about File I/O and I think you will get what you want.
    Best regards,
    Barry
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Connection to DB: What is better?

    Hi all,I have a project with a high frequency of database accesses and connections. I use a pool connection and i want to know what is better, opening and closing each connection after every query or close the connection when user logs out or loses session?
    Thanx in advance.

    Connection pooling is the right direction to go. Now about the when to open or close connection. In my opinion, as you are using connection pooling or even if you not, its better to open the connection when needed and close after you have looped through result set.
    If you keep the connection as a data memmber in a class, you might need to check the connection status before executing the query.

  • What is better for RIA - FLEX or Silverlight?

    What is better for RIA - FLEX or Silverlight? Any experience
    here...
    " Microsoft Silverlight 1.0 beta availability. Optimized for
    the Web, Microsoft Silverlight enables developers and designers to
    easily use existing skills and Visual Studio and Expression Studio
    tools to deliver media experiences and rich interactive
    applications. Silverlight works with any back-end Web platform or
    technology, seamlessly integrating with existing infrastructure and
    applications, including Apache and PHP, as well as JavaScript and
    XHTML on the client. Beta 1.0 includes a go-live license, which
    means customers can deploy their Silverlight applications in
    production. Final availability of Microsoft Silverlight 1.0 is
    scheduled for summer 2007."
    Best Regards
    Attila

    I imagine that the Microsoft folks are really proud of
    Silverlight -- I mean, they have been fighting the shift that the
    Internet has caused from the beginning--pure client/server dies
    hard. From the MS-only folks, Silverlight is a breath of fresh AIR.
    I am glad that Microsoft has finally seen the RIA wisdom and joined
    in with the rest of the world. I mean, how long was Java on the
    scene before C# magically appeared; I am glad that they finally saw
    the writing on the wall.
    Personally, I don't care if you use Flex or Silverlight; just
    that you use whatever for the right reasons. Flex has ample
    documentation for me and the example apps far outshine anything
    that I have seen in Silverlight. I found Flex to be pretty simple
    to learn too. As Silverlight was only announced in April 2007, I
    seriously doubt that "shakro" has actually gotten around to doing
    any real work -- Flex at least has been around since 2004. I know a
    lot of people that are building production-grade Flex/AIR
    applications. I don't know anyone that is seriously considering
    using Silverlight.
    But then, that is my circle --- take my experience with a
    grain of salt. Just also make sure to take the Microsoft fanboys
    with a grain of salt too.

Maybe you are looking for

  • Cycle count Storage location selection

    Hi, Could someone explain to how the Storage locations are selected when I run transaction MICN. Our settings in config are like this I have a material in one storage location, it has never been counted. I run the transaction MICN for that material i

  • FieldPoint I/O Data Type versus Fieldpoint I/O Point Data Type

    I have upgrated a project from LV 8.5 version to LV 2011 the Fieldpoint Data Types are different in LV 8.5 it is FieldPoint I/O and in LV 2011 it is Fieldpoint I/O Point. I built the proyect and tried to run it, no errors were present. Now the applic

  • I downloaded a version of Roboform and got unsupported browser messages so I uninstalled it but the messages persist

    I downloaded a version of Roboform and got unsupported browser messages. I tried to uninstall Roboform and apparently did, as no icon, application or system preference files remain. The toolbar remains and the messages persist. I had the whole system

  • Mac Pro and FCP - Very Unstable

    I just purchased the Mac Pro and installed FCP 5.1.2. I have a dual 2.6 Ghz with 2.5 TB external eSATA Raid (using the Sonnet E4P card), Kona LHe Card and 3 GB of RAM. 1. FCP, Quicktime and Shake each unexpectedly quits on playback of video within a

  • Which HDD Camcorder

    Hello all, I figured this was the best place to post this. I'm looking for some constructive feedback. I am planning on purchasing a Hard Disk Drive Camcorder sometime in the next 6 months. I intend to shoot the typical family footage along with some