原文地址http://blog.csdn.net/itfootball/article/details/45395901

appium中的log输出量很大,我们分析问题的时候会依赖于这些log,但是你理解这些log输出一些标志么?你是否觉得它的输出晦涩难懂了?想不想改成自己的大名?那就看下面的文章吧。

log形式

首先我们来看一段log输出:

info: Starting App
info: [debug] Attempting to kill all 'uiautomator' processes
info: [debug] Getting all processes with 'uiautomator'
info: [debug] executing cmd: /Users/wuxian/Documents/tools/sdk/platform-tools/adb -s emulator-5554 shell "ps 'uiautomator'"
info: [debug] No matching processes found
info: [debug] Running bootstrap
info: [debug] spawning: /Users/wuxian/Documents/tools/sdk/platform-tools/adb -s emulator-5554 shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap -e pkg com.example.android.apis -e disableAndroidWatchers false
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
info: [debug] [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap:
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class="io".appium.android.bootstrap.Bootstrap
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1
info: [debug] [BOOTSTRAP] [debug] Socket opened on port 4724
info: [debug] [BOOTSTRAP] [debug] Appium Socket Server Ready

我将上面的log分为4种(message为消息体) 
1. log等级:message 
2. log等级:[debug] message 
3. log等级:[debug] [BOOTSTRAP] [debug] message 
4. log等级:[debug] [UIAUTOMATOR STDOUT] message

1.log等级:message

这一类log就是简单的appium服务器的log,切log等级为非debug

2.log等级:[debug] message

这一类log和上面是一样的,都是appium服务器的log,区别在于该log等级为debug,在logger.js模块中我们可以看到如下代码,下面的代码将debug等级的log,更改为info等级,然后在后面跟上[debug]的标志。

if (levels[logger.transports.console.level] === levels.debug) {
logger.debug = function (msg) { logger.info('[debug] ' + msg); };
}

3.[debug] [BOOTSTRAP] [debug] message

这一类log为手机中的socket服务器包(放在android手机端的jar包称为bootstrap)返回的输出

4.log等级:[debug] [UIAUTOMATOR STDOUT] message

这一类log为执行case输出的log,我们可以理解为adb接受的log。我们一般执行uiautomator的case时候,控制台输出的就是这类带有uiautomator标识的log。

自定义log部分

log等级

第一步我们来修改log等级。比如我们想将info级别改为warn级别,只需要将logger.js的223行左右的如下代码

if (levels[logger.transports.console.level] === levels.debug) {
logger.debug = function (msg) { logger.info('[debug] ' + msg); };
}

修改为 

这里就将debug等级的修改为了warn模式的,info模式还是info模式(我之前说过,你应该知道为什么改变的是debug而不是info等级吧?)。我们来看看输出:

info: Starting App
warn: [debug] Attempting to kill all 'uiautomator' processes
warn: [debug] Getting all processes with 'uiautomator'
warn: [debug] executing cmd: /Users/wuxian/Documents/tools/sdk/platform-tools/adb -s emulator-5554 shell "ps 'uiautomator'"
warn: [debug] No matching processes found
warn: [debug] Running bootstrap
warn: [debug] spawning: /Users/wuxian/Documents/tools/sdk/platform-tools/adb -s emulator-5554 shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap -e pkg com.example.android.apis -e disableAndroidWatchers false
warn: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
warn: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
warn: [debug] [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap:
warn: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
warn: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
warn: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class="io".appium.android.bootstrap.Bootstrap
warn: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
warn: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1
warn: [debug] [BOOTSTRAP] [debug] Socket opened on port 4724
warn: [debug] [BOOTSTRAP] [debug] Appium Socket Server Ready

我们将info改变成了warn,但是还是存在info标志的,因为上面代码的改变是建立在你调用的logger.debug,因为我们之前说过了,appium会将debug等级改为info,然后在后面加一个[debug]标志,现在我们改为warn,那么之前debug会改为warn,然后加一个[debug]标志。所以凡是warn后面必然会跟一个[debug]。

debug标识

上面的debug,会在info/warn/error标识后面加一个[debug],是不是很丑,我是觉得很丑,我们将其改变一下改成[TesterHome],还是刚才的代码:

info: Starting App
warn: [TesterHome] Attempting to kill all 'uiautomator' processes
warn: [TesterHome] Getting all processes with 'uiautomator'
warn: [TesterHome] executing cmd: /Users/wuxian/Documents/tools/sdk/platform-tools/adb -s emulator-5554 shell "ps 'uiautomator'"
warn: [TesterHome] No matching processes found
warn: [TesterHome] Running bootstrap
warn: [TesterHome] spawning: /Users/wuxian/Documents/tools/sdk/platform-tools/adb -s emulator-5554 shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap -e pkg com.example.android.apis -e disableAndroidWatchers false
warn: [TesterHome] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
warn: [TesterHome] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
warn: [TesterHome] [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap:
warn: [TesterHome] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
warn: [TesterHome] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
warn: [TesterHome] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class="io".appium.android.bootstrap.Bootstrap
warn: [TesterHome] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
warn: [TesterHome] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1
warn: [TesterHome] [BOOTSTRAP] [debug] Socket opened on port 4724
warn: [TesterHome] [BOOTSTRAP] [debug] Appium Socket Server Ready

ok了。

觉得UIAUTOMATOR STDOUT和BOOTSTRAP不理解?

没关系,写成中文,在devices/android/uiautomator.js文件中,找到190和203行左右的语句,将上面两个标识符修改为中文: 
修改前: 

修改后: 

输出:

info: Starting App
warn: [TesterHome] Attempting to kill all 'uiautomator' processes
warn: [TesterHome] Getting all processes with 'uiautomator'
warn: [TesterHome] executing cmd: /Users/wuxian/Documents/tools/sdk/platform-tools/adb -s emulator-5554 shell "ps 'uiautomator'"
warn: [TesterHome] No matching processes found
warn: [TesterHome] Running bootstrap
warn: [TesterHome] spawning: /Users/wuxian/Documents/tools/sdk/platform-tools/adb -s emulator-5554 shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap -e pkg com.example.android.apis -e disableAndroidWatchers false
warn: [TesterHome] [脚本输出] INSTRUMENTATION_STATUS: numtests=1
warn: [TesterHome] [脚本输出] INSTRUMENTATION_STATUS: stream=
warn: [TesterHome] [脚本输出] io.appium.android.bootstrap.Bootstrap:
warn: [TesterHome] [脚本输出] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
warn: [TesterHome] [脚本输出] INSTRUMENTATION_STATUS: test=testRunServer
warn: [TesterHome] [脚本输出] INSTRUMENTATION_STATUS: class="io".appium.android.bootstrap.Bootstrap
warn: [TesterHome] [脚本输出] INSTRUMENTATION_STATUS: current=1
warn: [TesterHome] [脚本输出] INSTRUMENTATION_STATUS_CODE: 1
warn: [TesterHome] [设备socket服务器输出] [debug] Socket opened on port 4724
warn: [TesterHome] [设备socket服务器输出] [debug] Appium Socket Server Ready

哦了,就毁到这里吧。

Appium中的logger的更多相关文章

  1. 手机自动化测试:Appium代码之Logger

    手机自动化测试:Appium代码之Logger   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.poptest推出手机自动化测 ...

  2. python中的logger模块

    logger 提供了应用程序可以直接使用的接口handler将(logger创建的)日志记录发送到合适的目的输出filter提供了细度设备来决定输出哪条日志记录formatter决定日志记录的最终输出 ...

  3. 【转】Appium 中截取 element 图片作为对比,判断对比结果

    其实在https://github.com/gb112211/Adb-For-Test 里面有一个截取element进行对比的方法,但是在使用appium时是无法使用的,因为其用到了uiautomat ...

  4. 当Appium中遇到alert(python篇)

    当Appium中遇到alert,可以使用switch_to_alert(),以下是微信登录切换登录方式的代码示例: #coding=utf-8 from appium import webdriver ...

  5. Appium中app的元素定位

    app定位方式,本文只讲Android手机的定位方式. 前提条件是adb连接到模拟器或者是手机(具体连接方式这里不再讲解),证明已连接到设备 adb devices app元素定位工具一:UI Aut ...

  6. appium中从activity切换到html

    问题:混合开发的app中,会有内嵌的H5页面元素,该如何进行定位操作? 解决思路:appium中的元素定位都是基于android原生控件进行元素定位,而web网页是B/S架构,两者运行环境不同需要进行 ...

  7. Appium中部分api的使用方法

    使用的语言是java,appium的版本是1.3.4,java-client的版本是java-client-2.1.0,建议多参考java-client-2.1.0-javadoc. 1.使用Andr ...

  8. python中的logger模块详细讲解

    logger 提供了应用程序可以直接使用的接口handler将(logger创建的)日志记录发送到合适的目的输出filter提供了细度设备来决定输出哪条日志记录formatter决定日志记录的最终输出 ...

  9. Python中的logger和handler到底是个什么鬼

    最近的任务经常涉及到日志的记录,特意去又学了一遍logging的记录方法.跟java一样,python的日志记录也是比较繁琐的一件事,在写一条记录之前,要写好多东西.典型的日志记录的步骤是这样的: 创 ...

随机推荐

  1. 如何 “解决” WPF中空域问题(Airspace issuse)

    空域问题是由于Winform与WPF在底层渲染机制上有所区别而导致的.多数情况下,开发者为了实现不规则的窗体并承载Winform控件时,遇到此类问题.当WPF窗体设置为允许透明(也就是AllowsTr ...

  2. 一行代码解决各种IE兼容问题,IE6,IE7,IE8,IE9,IE10 (转)

    x-ua-compatible 用来指定IE浏览器解析编译页面的model x-ua-compatible 头标签大小写不敏感,必须用在 head 中,必须在除 title 外的其他 meta 之前使 ...

  3. 蓝桥杯 第三届C/C++预赛真题(2) 古堡算式(数学题)

    福尔摩斯到某古堡探险,看到门上写着一个奇怪的算式: ABCDE * ? = EDCBA 他对华生说:“ABCDE应该代表不同的数字,问号也代表某个数字!” 华生:“我猜也是!” 于是,两人沉默了好久, ...

  4. javascript基本语法和变量(转)

    转载来自 阮一峰老师的文章,地址为:http://javascript.ruanyifeng.com/grammar/basic.html#toc0 1.1语句 JavaScript 程序的执行单位是 ...

  5. WPF通过异常来验证用户输入

    在WPF中使用数据绑定,如果用户输入和绑定类型转换失败,控件就会显示出现错误的模板, 比如一个Textbox绑定到一个int 属性,如果用户输入一个string,那这个textbox就会显示错误模板, ...

  6. 分享一个Unity3D小作品,源码地址已公布在文章开头!

    Update:回复量有点大,楼主工作期间可能无暇向童鞋们发送源码,为了不让童鞋们久等,现公布源码地址.  链接: http://pan.baidu.com/s/1sjpYW4d 密码: zhp9 请注 ...

  7. poj 3498(最大流+拆点)

    题目链接:http://poj.org/problem?id=3498 思路:首先设一个超级源点,将源点与各地相连,边容量为各点目前的企鹅数量,然后就是对每个冰块i进行拆点了(i,i+n),边容量为能 ...

  8. Http服务器实现文件上传与下载(五)

    一.引言 欢迎大家和我一起编写Http服务器实现文件的上传和下载,现在我回顾一下在上一章节中提到的一些内容,之前我已经提到过文件的下载,在文件的下载中也提到了文件的续下载只需要在响应头中填写Conte ...

  9. pandas 读取文件

    import pandas as pd import matplotlib.pyplot as plt data = pd.read_csv('G:timeCompare.txt', sep=' ', ...

  10. 【BZOJ4660】Crazy Rabbit 结论+DP

    [BZOJ4660]Crazy Rabbit Description 兔子们决定在自己的城堡里安排一些士兵进行防守.给出 n 个点的坐标,和城堡里一个圆心在原点的圆形的障碍,兔子们希望从中选出 k 个 ...