51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 1414|回复: 0
打印 上一主题 下一主题

玩转 Appium 中 logger

[复制链接]
  • TA的每日心情
    奋斗
    2021-8-16 14:04
  • 签到天数: 1 天

    连续签到: 1 天

    [LV.1]测试小兵

    跳转到指定楼层
    1#
    发表于 2018-3-12 14:27:04 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
    log形式

    首先我们来看一段log输出:
    1. info: Starting App
    2. info: [debug] Attempting to kill all 'uiautomator' processes
    3. info: [debug] Getting all processes with 'uiautomator'
    4. info: [debug] executing cmd: /Users/wuxian/Documents/tools/sdk/platform-tools/adb -s emulator-5554 shell "ps 'uiautomator'"
    5. info: [debug] No matching processes found
    6. info: [debug] Running bootstrap
    7. 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
    8. info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
    9. info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
    10. info: [debug] [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap:
    11. info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
    12. info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
    13. info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
    14. info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
    15. info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1
    16. info: [debug] [BOOTSTRAP] [debug] Socket opened on port 4724
    17. info: [debug] [BOOTSTRAP] [debug] Appium Socket Server Ready
    复制代码
    我将上面的log分为4种(message为消息体)

    log等级:message
    log等级:[debug] message
    log等级:[debug] [BOOTSTRAP] [debug] message
    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等级的(我之前说过,你应该知道为什么改变的是debug而不
    是info等级吧?)。我们来看看输出:
    1. info: Starting App
    2. warn: [debug] Attempting to kill all 'uiautomator' processes
    3. warn: [debug] Getting all processes with 'uiautomator'
    4. warn: [debug] executing cmd: /Users/wuxian/Documents/tools/sdk/platform-tools/adb -s emulator-5554 shell "ps 'uiautomator'"
    5. warn: [debug] No matching processes found
    6. warn: [debug] Running bootstrap
    7. 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
    8. warn: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
    9. warn: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
    10. warn: [debug] [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap:
    11. warn: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
    12. warn: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
    13. warn: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
    14. warn: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
    15. warn: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1
    16. warn: [debug] [BOOTSTRAP] [debug] Socket opened on port 4724
    17. warn: [debug] [BOOTSTRAP] [debug] Appium Socket Server Ready
    复制代码
    我们将info改变成了warn,但是还是存在info标志的,因为上面代码的改变是建立在你调用的logge
    r.debug,因为我们之前说过了,appium会将debug等级改为info,然后在后面加一个[debug]标志,
    现在我们改为warn,那么之前debug会改为warn,然后加一个[debug]标志。所以凡是warn后面必
    然会跟一个[debug]。

    debug标识

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

    1. info: Starting App
    2. warn: [TesterHome] Attempting to kill all 'uiautomator' processes
    3. warn: [TesterHome] Getting all processes with 'uiautomator'
    4. warn: [TesterHome] executing cmd: /Users/wuxian/Documents/tools/sdk/platform-tools/adb -s emulator-5554 shell "ps 'uiautomator'"
    5. warn: [TesterHome] No matching processes found
    6. warn: [TesterHome] Running bootstrap
    7. 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
    8. warn: [TesterHome] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
    9. warn: [TesterHome] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
    10. warn: [TesterHome] [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap:
    11. warn: [TesterHome] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
    12. warn: [TesterHome] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
    13. warn: [TesterHome] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
    14. warn: [TesterHome] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
    15. warn: [TesterHome] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1
    16. warn: [TesterHome] [BOOTSTRAP] [debug] Socket opened on port 4724
    17. warn: [TesterHome] [BOOTSTRAP] [debug] Appium Socket Server Ready
    18. ok了。
    复制代码
    觉得UIAUTOMATOR STDOUT和BOOTSTRAP不理解?

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

    修改后:

    1. 输出:

    2. info: Starting App
    3. warn: [TesterHome] Attempting to kill all 'uiautomator' processes
    4. warn: [TesterHome] Getting all processes with 'uiautomator'
    5. warn: [TesterHome] executing cmd: /Users/wuxian/Documents/tools/sdk/platform-tools/adb -s emulator-5554 shell "ps 'uiautomator'"
    6. warn: [TesterHome] No matching processes found
    7. warn: [TesterHome] Running bootstrap
    8. 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
    9. warn: [TesterHome] [脚本输出] INSTRUMENTATION_STATUS: numtests=1
    10. warn: [TesterHome] [脚本输出] INSTRUMENTATION_STATUS: stream=
    11. warn: [TesterHome] [脚本输出] io.appium.android.bootstrap.Bootstrap:
    12. warn: [TesterHome] [脚本输出] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
    13. warn: [TesterHome] [脚本输出] INSTRUMENTATION_STATUS: test=testRunServer
    14. warn: [TesterHome] [脚本输出] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
    15. warn: [TesterHome] [脚本输出] INSTRUMENTATION_STATUS: current=1
    16. warn: [TesterHome] [脚本输出] INSTRUMENTATION_STATUS_CODE: 1
    17. warn: [TesterHome] [设备socket服务器输出] [debug] Socket opened on port 4724
    18. warn: [TesterHome] [设备socket服务器输出] [debug] Appium Socket Server Ready
    复制代码


    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有帐号?(注-册)加入51Testing

    x
    分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-11-15 01:07 , Processed in 0.064126 second(s), 25 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

    快速回复 返回顶部 返回列表