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应用在启动的时候,都会输出当前应 ...
随机推荐
- HDU 1398 Square Coins 平方硬币 (普通母函数,水)
题意: 有17种硬币,每种的面值为编号的平方,比如 1,4,9,16.....给出一个数字,求组成这个面值有多少种组法? 思路: 用普通母函数解,主要做的就是模拟乘法,因为硬币是无限的,所以每个构造式 ...
- SQL增删查改语句
一.增:有4种方法 1.使用insert插入单行数据: 语法:insert [into] <表名> [列名] values <列值> insert into sheet1 va ...
- ABAP Netweaver, SAP Cloud Platform和Kubernetes的用户区分
ABAP Dialog: Individual, interactive system access. System: Background processing and communication ...
- WPF知识点全攻略05- XAML内容控件
此处简单列举出布局控件外,其他常用的控件: Window:WPF窗口 UserControl:用户控件 Page:页 Frame:用来浏览Page页 Border:嵌套控件,提供边框和背景. Butt ...
- python 判断路径是否存在
import os os.path.exists(文件绝对路径)
- 使Linux支持exFAT和NTFS格式的磁盘
Linux支持exFAT和NTFS Linux系统默认可以自动识别到fat32格式的盘,但fat32支持的文件不能大于4G,所以只能将移动硬盘和U盘格式化为NTFS和exFAT这两种格式的,对于U盘最 ...
- String中indexof函数的用法
int indexOf(int ch) 返回指定字符在此字符串中第一次出现处的索引. int indexOf(int ch, int fromIndex) 从指定的索引开始搜索,返回在此字符串中第一次 ...
- Elasticsearchs的安装/laravel-scout和laravel-scout-elastic的安装
安装: https://github.com/medcl/elasticsearch-rtf 先下载包 下载解压后 cd elasticsearch-rtf-master ll bin/elastic ...
- python中强大的testdata库自动生成测试所需要的数据
testdata是用于生成测试数据的一个安装包,它不仅提供DictFactory类来生成数据,还提供特定的扩展功能.每个Factory实例均可用于生成用户所需要的特定个数的数据,这将使我们更好地统计分 ...
- python 列表(增删改查)
列表 :(列表可以嵌套,列表的中的元素可以为任意) 列表的创建:1. a = [1, 2, 3] 2. a = list([1, 2, 3]) 1.查: 索引(下标),都是从0开始 切片 .c ...