Results 1 to 2 of 2
  1. #1
    stephanie is offline Member
    Join Date
    Feb 2015
    Posts
    2
    Rep Power
    0

    Default LayoutPattern java code Use : how to create a custom layout pattern ?

    Hello,

    I would like to implement a custom Logging strategy for my Java project.
    I have implemented 3 appenders : one console-log, one file-log (errors only) and another (custom) file-log (with the custom parameters).
    The custom parameters are : loggerName, logPathDir, logFileLevel and layoutPattern.

    I have not managed yet to implement a custom layoutPattern strategy for the custom file-log.

    When I launch my tests : test1 (default logging setting) and test2 (custom logging setting), I have only managed to get a sucessfull status if I switch the custom layoutPattern strategy to the default one for the test2.

    My implementation extract : (see attachment for the java file)
    ...
    // Layout patterns : default (layout) and custom (patternLayoutCustomBuilt)
    Layout<String> layout = PatternLayout.createLayout(PatternLayout.SIMPLE_CO NVERSION_PATTERN, config, null, null, false,
    false, null, null);

    PatternLayout.Builder patternLayoutCustom = PatternLayout.newBuilder();
    PatternLayout patternLayoutCustomBuilt = patternLayoutCustom.withPattern(layoutPattern).wit hConfiguration(config).build();

    // Appenders
    Appender appenderLogFile = FileAppender.createAppender(logPathDir + "logFile", "false", "false", "logFile", "true",
    "false", "false", "4000", layout, null, "false", null, config); <= switch layout to patternLayoutCustomBuilt

    appenderLogFile.start();
    ...

    I would like to get an example on how to make a layout pattern custom strategy implementation.

    Thanks a lot in advance !!

    Stephanie

    Tools version :
    -java 1.7.0
    -junit 4.12
    -log4j-api-2.1
    -log4j-core-2.1
    Attached Files Attached Files

  2. #2
    stephanie is offline Member
    Join Date
    Feb 2015
    Posts
    2
    Rep Power
    0

    Default Re: LayoutPattern java code Use : how to create a custom layout pattern ?

    ok, solved with :

    // Layout patterns
    Layout<String> layout = PatternLayout.createLayout(PatternLayout.SIMPLE_CO NVERSION_PATTERN, config, null, null, false,
    false, null, null);
    Layout<String> layoutCustom = PatternLayout.createLayout(layoutPattern, config, null, null, false,
    false, null, null);

Similar Threads

  1. JFrame custom layout design help
    By jaytee in forum New To Java
    Replies: 3
    Last Post: 02-02-2012, 03:41 AM
  2. [ASK] How to create custom terminal with java app?
    By ArnOfMagnus in forum Advanced Java
    Replies: 2
    Last Post: 04-05-2011, 08:44 AM
  3. Custom JButton with flow layout
    By phil128 in forum AWT / Swing
    Replies: 1
    Last Post: 01-17-2011, 11:44 PM
  4. Replies: 0
    Last Post: 06-29-2010, 09:16 PM
  5. Create an Asterisk Pattern in Java
    By kaurpower in forum New To Java
    Replies: 1
    Last Post: 03-17-2010, 02:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •