Skip to content

Allow log configuration #414

Closed
Closed

Description

@midopa

Description

I set Appium's log level to warn so my console output is decluttered. But when I want to debug an issue, I have to set it to info. I'd like to have the best of both worlds without having to rerun my tests. IOW, I'd like the console to only output warning level messages and above and I'd like a file log with verbose logging.

For this reason, I would like the ability to configure Appium's logging. Maybe with a logging properties file?

If I use the builder.withLogFile(File) API, this doesn't suppress logging to the console.

I use log4j2. I've tried using logging bridges (Java util logging, Commons Util, and log4j1), but my logging configuration isn't being picked up.

Environment

  • java client build version or git revision if you use some shapshot: 3.4.1
  • Appium server version or git revision if you use some shapshot: 1.5.3
  • Desktop OS/version used to run Appium if necessary: OS X El Capitan
  • Node.js version (unless using Appium.app|exe) or Appium CLI or Appium.app|exe: 6.1.0
  • Mobile platform/version under test: N/A
  • Real device or emulator/simulator: N/A

Code To Reproduce Issue

Current code:

AppiumServiceBuilder builder = new AppiumServiceBuilder();
// this filters ALL appium logs to warning level
builder.withArgument(GeneralServerFlag.LOG_LEVEL, "warn");
// now a log file will be created that has warning logs AND the console will output warning logs
builder.withLogFile(myLogFile);

Desired:

AppiumServiceBuilder builder = new AppiumServiceBuilder();
// console will only output warning and above level logs
builder.withArgument(GeneralServerFlag.LOG_LEVEL, "warn");
// a log file will be created for all info and above level logs
builder.withLogFile(myLogFile, "info");
// this will use the current logging level, either default or the user-set LOG_LEVEL argument
builder.withLogFile(myLogFile);

Activity

  1. TikhomirovSergey commented on Jun 14, 2016

    @TikhomirovSergey
    Contributor

    Hi @midopa

    I think it is impossible to make that

    AppiumServiceBuilder builder = new AppiumServiceBuilder();
    // console will only output warning and above level logs
    builder.withArgument(GeneralServerFlag.LOG_LEVEL, "warn");
    // a log file will be created for all info and above level logs
    builder.withLogFile(myLogFile, "info");
    // this will use the current logging level, either default or the user-set LOG_LEVEL argument
    builder.withLogFile(myLogFile);

    This string manages the output log level of the server and client doesn't do anything with it.

    builder.withArgument(GeneralServerFlag.LOG_LEVEL, "warn");

    Server has it is own logger so that is why your log4j2 config is not picked up.
    But there is a feature which may help you. Please take a look at:

    https://github.com/appium/java-client/blob/master/src/main/java/io/appium/java_client/service/local/AppiumDriverLocalService.java#L203

    and use cases:

    https://github.com/appium/java-client/blob/master/src/test/java/io/appium/java_client/localserver/ServerBuilderTest.java#L224

    I think it is possible to to re-use the same output stream as log4j2 uses and filter log messages there.

  2. midopa commented on Jun 16, 2016

    @midopa
    Author

    Thanks! That's very close to what I'd like. Would it be possible to expose an API that would give me a bit more control? In my case, I just want to clear out the existing streams so nothing goes to the console. Or maybe a different ctor/builder API for that?

  3. TikhomirovSergey commented on Jun 21, 2016

    @TikhomirovSergey
    Contributor

    @midopa
    I was thinking about your quetion.
    I'm not sure. We use the same approach as the Selenium project uses.

  4. alexander-poulikakos commented on Sep 10, 2018

    @alexander-poulikakos
    Contributor

    This is solved by #1014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions