All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jayway.restassured.config.LogConfig Maven / Gradle / Ivy

There is a newer version: 2.9.0
Show newest version
/*
 * Copyright 2013 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.jayway.restassured.config;

import org.apache.commons.lang3.Validate;

import java.io.PrintStream;

/**
 * Configure the logging for REST Assured. 

Note that only * log things known to REST Assured (i.e. the request- and response specifications) will be logged. If you need to log what's actually sent on the wire * refer to the HTTP Client logging docs or use an external tool such as * Wireshark.

*/ public class LogConfig { private final PrintStream defaultPrintStream; private final boolean prettyPrintingEnabled; /** * Configure the default stream to use the System.out stream (default). */ public LogConfig() { this(System.out, true); } /** * Configure pretty printing and the default stream where logs should be written if not specified explicitly by a filter. I.e. this stream will be used in cases * where the log specification DSL is used, e.g. *
     * given().log().all()...
     * 
* or *
     * expect().log.ifError(). ..
     * 
* * It will not override explicit streams defined by using the {@link com.jayway.restassured.filter.log.RequestLoggingFilter} or the {@link com.jayway.restassured.filter.log.ResponseLoggingFilter}. * * @param defaultPrintStream The default print stream to use for the {@link com.jayway.restassured.specification.LogSpecification}'s. * @param prettyPrintingEnabled Enable or disable pretty printing when logging. Pretty printing is only possible when content-type is XML, JSON or HTML. */ public LogConfig(PrintStream defaultPrintStream, boolean prettyPrintingEnabled) { Validate.notNull(defaultPrintStream, "Stream to write logs to cannot be null"); this.defaultPrintStream = defaultPrintStream; this.prettyPrintingEnabled = prettyPrintingEnabled; } /** * @return The default stream to use */ public PrintStream defaultStream() { return defaultPrintStream; } /** * Specify a new default stream to the print to. * @param printStream The stream * @return A new LogConfig instance */ public LogConfig defaultStream(PrintStream printStream) { return new LogConfig(printStream, true); } /** * @return The default stream to use */ public boolean isPrettyPrintingEnabled() { return prettyPrintingEnabled; } /** * Specify a whether or not to enable pretty printing by default. * * @param shouldEnable true if pretty-printing should be enabled, false otherwise. * @return A new LogConfig instance */ public LogConfig enablePrettyPrinting(boolean shouldEnable) { return new LogConfig(defaultPrintStream, shouldEnable); } /** * @return A static way to create a new LogConfig instance without calling "new" explicitly. Mainly for syntactic sugar. */ public static LogConfig logConfig() { return new LogConfig(); } /** * Syntactic sugar. * * @return The same log config instance. */ public LogConfig and() { return this; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy