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 6858103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:06:56+00:00 2026-05-27T02:06:56+00:00

is it possible to log for all classes, to a single file instead of

  • 0

is it possible to log for all classes, to a single file instead of

final Logger logger = LoggerFactory.getLogger(Wombat.class);

what of you need to log for all classes?

  • 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-05-27T02:06:56+00:00Added an answer on May 27, 2026 at 2:06 am

    The short answer…

    The Logger you use in code does not say where the logging messages are output. (What decides where the messages go is the binding and configuration you use.)

    Note that messages with the same Logger will be forced to go to the same place since you’ll no longer be able to tell them apart – so you want each class to have its own Logger so that you have maximum choice later.

    If you want to output all logging messages to a single file the option I’d suggest is using the log4j binding along with the second log4j.properties example I’ve given below. For the most part you should be able to copy/paste this to get running and then configure at your leisure.

    The long answer…

    Covering SLF4J and some of its bindings.

    SLF4J

    From the website, http://www.slf4j.org/

    The Simple Logging Facade for Java or (SLF4J) serves as a simple
    facade or abstraction for various logging frameworks, e.g.
    java.util.logging, log4j and logback, allowing the end user to plug in
    the desired logging framework at deployment time.

    So it’s all down to what binding you use! In fact the idea is that you don’t even have to settle on a binding until runtime, and don’t need to change any of your logging code to change your mind later!

    I’ll discuss the two that I’m familiar with, note there are others and you should consider doing your own research before settling on a particular implementation.

    Simple Binding

    The simple binding (eg. slfj-simple-1.6.4.jar) has no configuration.

    It simply logs all messages of INFO and above to standard error output (System.err).

    Log4j Binding

    Generally though you want to use a more complex binding such as log4j (which is what I use and so will talk about). It is far more flexable than simple binding, but requires you do do some configuration.

    First you’ll require a different binding jar (eg. slf4j-log4j12-1.6.4.jar). You’ll also need the corresponding log4j jar (eg. log4j-1.2.16). And finally you’ll need to configure log4j itself – a log4j.properties file to be located in the root of the project.

    I’ll jump to a couple of example log4j.properties files


    This first one outputs everything to console, and is pretty similar to what the simple binding achieves, except you can configure the level (TRACE, DEBUG, WARN, INFO, ERROR) that you log at, and the output pattern.

    # Root Logger : TRACE & above to console appender
    log4j.rootLogger=TRACE, console
    # Appender : Console
    log4j.appender.console=org.apache.log4j.ConsoleAppender
    log4j.appender.console.layout=org.apache.log4j.PatternLayout
    log4j.appender.console.layout.ConversionPattern=%-8r %-5p %c [%t] %m%n
    

    For outputting to a single file you’ll want a different appender, something like:

    # Root Logger : WARN & above to mainFile appender
    log4j.rootLogger=WARN,mainFile
    # Appender : mainFile
    log4j.appender.mainFile=org.apache.log4j.FileAppender
    log4j.appender.mainFile.File=main.log
    log4j.appender.mainFile.layout=org.apache.log4j.PatternLayout
    log4j.appender.mainFile.layout.ConversionPattern=%-8r %-5p %c [%t] %m%n
    

    Log4j is setup around the concept of loggers and appenders.

    Loggers (different from the logger class you’ll use with SLF4J) capture messages according to some pattern (such as messages within a particular package), and pipe them to an appender.

    Appenders define how the messages are to be output (eg. file, network, console, database), and their format.

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

Sidebar

Related Questions

It is possible in SQL Server Express have a log of all operations SELECT
Is it possible to have 2 applications write to the same log file using
Is it possible to write a global HttpModule in IIS and log all SQL
Is it possible to create an error log in java that extends/works to all
I want to set up log4j so that all log meessages produced from classes
I know this is possible in Linq-to-Sql, is it possible to automatically log all
I want to log all clicks on a link. I've written a little logger,
Is it possible to log out user from a web site if he is
Is it possible to log certain events to -> event log for example, while
Is it possible to log WCF service exceptions? I have added in the app.config.

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.