rest-assured 将log()中的信息打印到log日志中去的方法
rest-assured 将log()中的信息打印到log日志中去的方法:
============方法1==============
PrintStream fileOutPutStream = new PrintStream(new File("log/test.log"));
RestAssured.config
= RestAssured.config().logConfig(new LogConfig(fileOutPutStream, true));
============方法2==============
RestAssured.config = RestAssured.config().logConfig(new LogConfig(new ToLoggerPrintStream(logger).getPrintStream(), true));
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import org.slf4j.Logger; /**
* A wrapper class which takes a logger as constructor argument and offers a PrintStream whose flush
* method writes the written content to the supplied logger (debug level).
* <p>
* Usage:<br>
* initializing in @BeforeClass of the unit test:
* <pre>
* ToLoggerPrintStream loggerPrintStream = new ToLoggerPrintStream( myLog );
* RestAssured.config = RestAssured.config().logConfig(
* new LogConfig( loggerPrintStream.getPrintStream(), true ) );
* </pre>
* will redirect all log outputs of a ValidatableResponse to the supplied logger:
* <pre>
* resp.then().log().all( true );
* </pre>
*
* @version 1.0 (28.10.2015)
* @author Heri Bender
*/
public class ToLoggerPrintStream
{
/** Logger for this class */
private Logger myLog;
private PrintStream myPrintStream; /**
* @return printStream
*/
public PrintStream getPrintStream()
{
if ( myPrintStream == null )
{
OutputStream output = new OutputStream()
{
private StringBuilder myStringBuilder = new StringBuilder(); @Override
public void write(int b) throws IOException
{
this.myStringBuilder.append((char) b );
} /**
* @see java.io.OutputStream#flush()
*/
@Override
public void flush()
{
myLog.debug( this.myStringBuilder.toString() );
myStringBuilder = new StringBuilder();
}
}; myPrintStream = new PrintStream( output, true ); // true: autoflush must be set!
} return myPrintStream;
} /**
* Constructor
*
* @param aLogger
*/
public ToLoggerPrintStream( Logger aLogger )
{
super();
myLog = aLogger;
}
rest-assured 将log()中的信息打印到log日志中去的方法的更多相关文章
- makefile 与android.mk中加信息打印
makefile里面加打印: [table]@echo ' zImage - Compressed kernel image' android.mk里面加信息打印: $(warning TEXT... ...
- 使用rsyslog编程,产生trace信息,记录到日志中
参考:http://blog.csdn.net/nowayings/article/details/38926501 https://www.cnblogs.com/bonelee/p/6234647 ...
- 在linux中使用shell来分析统计日志中的信息
在运维工作中,要经常分析后台系统的日志,通过抓取日志中的关键字信息,对抓取结果进行统计,从而为监控结果提供基础数据.下面的shell演示了如何从大量的日志中取得想要的统计结果.其中展示了各种有趣的命令 ...
- 把e.printStackTrace的堆栈信息打印在log.error()中
不要这样写: log.error(e);这样只是简单的记录下错误的类型,不能精确出错误出错在哪行 要写成:log.error(e.toString(),e);
- springboot中将日志信息存放在catalina.base中
<?xml version="1.0" encoding="UTF-8"?> <configuration debug="true& ...
- springboot读取配置文件中的信息
在一个项目中,我们有时候会把一些配置信息写入到一个配置文件中,在java代码中读取配置文件的信息.在此记录下读取属性文件中的内容. 在springboot项目中,springboot的配置文件可以使用 ...
- CODING DevOps 助力中化信息打造新一代研效平台,驱动“线上中化”新未来
中化信息技术有限公司,简称"中化信息",是世界 500 强企业中国中化控股有限责任公司(简称"中国中化")的全资直属公司,依托于中国中化的信息化建设实践,建立起 ...
- 涉及到复制和二进制日志中的选项和变量-Replication and Binary Logging Options and Variables
在搭建复制中,有些参数需要我们留意,在这里罗列出来,供大家参考一下,以GTID为基础 --server-id server-id:这是一个全局的可动态调整的变量,取值范围为0-4294967295,也 ...
- Spring Boot 2.x基础教程:找回启动日志中的请求路径列表
如果您看过之前的Spring Boot 1.x教程,或者自己原本就对Spring Boot有一些经验,或者对Spring MVC很熟悉.那么对于Spring构建的Web应用在启动的时候,都会输出当前应 ...
随机推荐
- 洛谷 2299 Mzc和体委的争夺战
题目背景 mzc与djn第四弹. 题目描述 mzc家很有钱(开玩笑),他家有n个男家丁(做过前三弹的都知道).但如此之多的男家丁吸引来了我们的体委(矮胖小伙),他要来与mzc争夺男家丁. mzc很生气 ...
- App Transport Security has blocked a cleartext HTTP
打开info.plist源代码复制粘贴 <key>NSAppTransportSecurity</key> <dict> <!--Includ ...
- PLSQL练习-数据共享与整合技术
1.编写一个存储过程,根据输入的工作类型,输出该工作的平均工资. 命令如下: 创建存储过程: create or replace procedure avgsal(v_job in emp.job%t ...
- js 获取当前URL信息
document.location 这个对象包含了当前URL的信息 location.host 获取port号 location.hostname 设置或获取主机名称 location.href 设置 ...
- maven项目jsp无法识别jstl的解决办法
EL表达式无效是因为maven项目的jsp不识别jstl,只要在web-APP 标签中引入命名空间 xmlns="http://xmlns.jcp.org/xml/ns/javaee&quo ...
- 关于 QObject 类
1.QObject类 简述 QObject类是所有Qt对象的基类. QObject是Qt对象模型的核心. 该模型的核心特征是称为信号和槽的对象通信机制. 您可以使用connect()将信号连接到槽 ...
- webuploader项目中多文件上传实例
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- Qt读写excel
今天在利用Qt进行excel操作时,代码总是走到打开excel这一步是总是出现程序崩溃.在网上查找了各种帖子 说法不一,尝试都没有解决.后来猜想是不是excel没有激活影响的.发现自己的excel没 ...
- [SDOi2012]Longge的问题 (数论)
Luogu2303 [SDOi2012]Longge的问题 题目 题目背景 SDOi2012 题目描述 Longge的数学成绩非常好,并且他非常乐于挑战高难度的数学问题.现在问题来了:给定一个整数N, ...
- 【Java_基础】空串、空格串、null的区别
1.表示的区别 string str1 = ""; //空串 str1.length() 等于 0 string str2 = " "; / ...