001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.classic.net.testObjectBuilders;
015
016import ch.qos.logback.classic.Level;
017import ch.qos.logback.classic.Logger;
018import ch.qos.logback.classic.LoggerContext;
019import ch.qos.logback.classic.spi.LoggingEvent;
020
021public class LoggingEventWithParametersBuilder implements Builder<LoggingEvent> {
022
023    final String MSG = "aaaaabbbbbcccc {} cdddddaaaaabbbbbcccccdddddaaaa {}";
024
025    LoggerContext loggerContext = new LoggerContext();
026    private Logger logger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
027
028    public LoggingEvent build(int i) {
029
030        LoggingEvent le = new LoggingEvent();
031        le.setTimeStamp(System.currentTimeMillis());
032
033        Object[] aa = new Object[] { i, "HELLO WORLD [========== ]" + i };
034
035        le.setArgumentArray(aa);
036        String msg = MSG + i;
037        le.setMessage(msg);
038
039        // compute formatted message
040        // this forces le.formmatedMessage to be set (this is the whole point of the
041        // exercise)
042        le.getFormattedMessage();
043        le.setLevel(Level.DEBUG);
044        le.setLoggerName(logger.getName());
045        le.setLoggerContextRemoteView(loggerContext.getLoggerContextRemoteView());
046        le.setThreadName("threadName");
047        return le;
048    }
049}