原文地址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. TCP/IP详解读书笔记:链路层

    在TCP/IP协议族中,链路层主要有三个目的: 1)为IP模块发送和接受IP数据报: 2)为ARP模块发送ARP请求和接受ARP应答: 3)为RARP模块发送RARP请求和接受RARP应答: 以太网和 ...

  2. WOW模型导出到Unity3D使用教程

    最近又重操旧业.搞起了Unity3D.对WOW的模型怨念很深. 于是写了一个教程帮助其他人一起提取wow的模型..哈哈..希望能帮助到大家哈哈.. 我自己的百度网盘里面附加.有兴趣的大家下载看看.文档 ...

  3. Papers of Word Embeddings

    首先解释一下什么叫做embedding.举个例子:地图就是对于现实地理的embedding,现实的地理地形的信息其实远远超过三维 但是地图通过颜色和等高线等来最大化表现现实的地理信息. embeddi ...

  4. 第二百二十三节,jQuery EasyUI,ComboBox(下拉列表框)组件

    jQuery EasyUI,ComboBox(下拉列表框)组件,可以远程加载数据的下拉列表组件 学习要点: 1.加载方式 2.属性列表 3.事件列表 4.方法列表 本节课重点了解 EasyUI 中 C ...

  5. 使用NPOI导入Excel注意日期格式和数字格式

    //使用NPOI导入Excel public static DataTable importExcelToDataSetUsingNPOI(string FilePath, string fileNa ...

  6. windows下caffe如何单独编译proto文件

    利用protoc.exe即可编译. 在protoc.exe当前文件夹下打开cmd,输入命令如下: pushd %~dp0 echo "copying .proto and generated ...

  7. Null value was assigned to a property of primitive type setter

    org.springframework.orm.jpa.JpaSystemException: Null value was assigned to a property of primitive t ...

  8. java代理与动态代理的学习

    静态代理比较简单,就是代理对象与被代理对象继承相同的接口,代理类负责调用被代理类(委托类)的对象的相关方法去提供具体的服务,一个代理类只能为一个接口服务,要是有很多服务的话需要开很多代理类.而动态代理 ...

  9. cocos2d-X学习之主要类介绍:布景:CCLayer

    类继承图:  CCLayer 是CCNode的子类 ,实现了TouchEventsDelegate接口,继承了CCNode所有的特性,并且附加了一些自己的特性,它能够接收iPhone的触摸事件,也能够 ...

  10. 【微信】QQ邮箱助手不提醒解决

    1.问题及原因: 微信上的QQ邮箱提醒功能失效了,收到信后不提醒.忘了是使用了TIM,还是使用了QQ邮箱之后才出现的. 不过原因是:QQ邮箱提醒被设置为仅在QQ邮箱客户端提醒 2.解决: 重新安装QQ ...