rest-assured 将log()中的信息打印到log日志中去的方法
2017-05-03 17:06
531 查看
rest-assured 将log()中的信息打印到log日志中去的方法:
============方法1==============
============方法2==============
============方法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; }
相关文章推荐
- 关于android studio log日志打印信息不全的原因以及解决方法
- Android之Log的日志打印信息的封装
- 【ios自学笔记】OC中log信息的输出方法,包含import、字符串、输出日志等知识点
- Android打印调试信息几种方法===>Log
- 魅族MX4开启开发者调试后无法打印log信息的解决方法
- 【Log日志】一个封装的日志打印库(显示类,方法,行数)--破晓觉醒
- android使用orm框架ormlite在控制台打印log日志信息
- Xcode 8打印log日志的问题小结及解决方法
- Activity生命周期及如何存活 用log日志信息打印输出
- 安卓开发解决不打印log日志方法
- java得到距离指定时间num时间的时间、以及反射调用方法、Log日志配置信息
- app卸载后弹出页面-方法2(java+log日志信息)
- Android 定义全局LOG打印日志,并显示调用者相关信息
- android中Log打印日志相关信息
- $ git log打印提交的日志(show commit logs)后的退出方法
- mtk android lcm 打印log信息方法
- logback日志项目使用方法 - 150205交易模块添加日志信息logback,orderNo订单号为log主键便于跟踪,数字常量化,解决取消支付BUG,弱网络环境原因
- mtk android lcm 打印log信息方法
- Android Studio真机调试时不打印Log信息的解决方法
- 使用log4j2打印Log,log4j不能打印日志信息,log4j2不能打印日志信息,log4j和logj2,idea控制台信息乱码(文末)