title: How to print log statements in a single line using Log4J?
body: <p>I have a maven application which contains the logger configured as below.</p>
  
  <pre><code>import org.apache.commons.cli.*;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  
  public class StartCount {
      public static void main(String[] args) throws Exception {
          ChunkRecon chRecon;
          Options options = new Options();
          Option input    = new Option("s", "ssn", true, "source system names");
          input.setRequired(false);
          options.addOption(input);
          CommandLineParser parser = new DefaultParser();
          HelpFormatter formatter  = new HelpFormatter();
          CommandLine cmd          = null;
          CustomSsnTableRecon cstr;
          final Logger LOGGER = Logger.getLogger(StartCount.class.getName());
          try {
              cmd = parser.parse(options, args);
              if(cmd.hasOption("s")) {            // Checks if there is an argument '--s' in the CLI.
                  String sources = cmd.getOptionValue("s");
                  if(sources == null) {
                      System.out.println("Please enter a source system name using the option '--s' and submit the jar again.. Ex: --s ABC ");
                      System.exit(1);
                  }
                  if(sources.contains("custom")) {
                      cstr = new CustomSsnTableRecon(sources);
                      cstr.getChunks();
                      cstr.reconDataFile();
                  } else {
                      LOGGER.log(Level.INFO, "Starting recon for the source: " + sources);
                      chRecon = new ChunkRecon(sources);
                      chRecon.getChunks();
                      chRecon.reconDataFile();
                  }
              } else {
                  LOGGER.log(Level.WARNING, "Please enter a source system using the option '--s' and submit the jar again. Ex: --s ABC");
                  System.out.println("Please enter a source system name using the option '--s' and submit the jar again.. Ex: --s ABC ");
                  System.exit(1);
              }
          } catch(ParseException e) {
              LOGGER.log(Level.WARNING, "Please enter a source system using the option '--s' and submit the jar again. Ex: --s ABC");
              formatter.printHelp("utility-name", options);
              e.printStackTrace();
              System.exit(1);
          }
          catch(Exception e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>This is my logger.properties file:</p>
  
  <pre><code>log4j.rootLogger=DEBUG, INFO, WARN, ERROR, stdout, file
  
  # Redirect log messages to console
  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{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
  </code></pre>
  
  <p>When I run the program I don't see any errors and the logs are coming out fine. But they are being printed in two lines as shown below:</p>
  
  <pre><code>Nov 18, 2019 12:30:22 PM com.recordcount.entry.StartCount main
  INFO: Starting recon for the source: GCORP_HFM
  </code></pre>
  
  <p>Project Structure:</p>
  
  <p><a href="https://i.stack.imgur.com/koN6z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/koN6z.png" alt="enter image description here"></a></p>
  
  <p>Is there any way I can print the log in a single statement &amp; also can we print just the class name instead of full package &amp; class name:</p>
  
  <pre><code>Nov 18, 2019 12:30:22 PM StartCount main INFO: Starting recon for the source: GCORP_HFM
  </code></pre>