Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log capturing researching #403

Closed
vit1251 opened this issue Jan 29, 2016 · 8 comments
Closed

Log capturing researching #403

vit1251 opened this issue Jan 29, 2016 · 8 comments

Comments

@vit1251
Copy link

vit1251 commented Jan 29, 2016

Hello,

I design and implement some scenario with progress tag and debugging by write stdout and logging.

stdout capturing work well, but work with logging unpredict:

  • Does not understand from documents how to work filtering (-foo,boo) and how about root logger?
  • Logging only write when test is failed? Can I enable write logging capturing on everytime?
@jenisys
Copy link
Member

jenisys commented Jan 30, 2016

Captured stdout/stderr/logging is normally only shown when a test fails.
To always show output (stdout/stderr/logging), try to disable capturing by using behave --no-capture ... (or: --no-capture-stderr, --no-logcapture) for example.

Logging filters allow you specify that some log categories are excluded from being captured (or specifically included).

SEE ALSO:

@jenisys jenisys added the info label Jan 30, 2016
@LeoHuckvale
Copy link

I'm having trouble here too. I ideally would like to see the logging interwoven with the step printouts, like:

    Given thing happens
    When some step with logging
        INFO:steps:foo bar
    Then something else

I'm logging from within the step files, e.g.:

    import logging
    log = logging.getLogger('foo')

    @step('some step with logging')
    def step_impl(context):
        log.info('foo bar')

I've tried running the feature like:

    behave --no-logcapture --no-capture

I'd also like to see the log output even if everything passes. I find it useful while developing the test suite.

Any help would be much appreciated. I'd be happy to have a go with a pull request too, if you can give any pointers.

@jenisys
Copy link
Member

jenisys commented Feb 5, 2016

@LeoHuckvale
Note that the output order depends on the formatter when you disable the capture mode.
For example, the plain formatter prints the the step and its result after the step is executed and the result is known. Therefore, you will never ever have the desired behaviour with this formatter.
The pretty formatter in no-color mode behaves the same.

OUTPUT-ORDERING:
Can only be ensured when you capture the output from stdout/logging.
But then you will not see the captured-output when the step passes.

@vit1251
Copy link
Author

vit1251 commented Apr 13, 2016

@jenisys how to create a mirror of captured logs in separate "debug.log" file?

Why follow code does not work with "--junit" argument?

def before_all(context):
    context.config.setup_logging(filename="debug.log", level=logging.DEBUG, format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s', datefmt='%Y-%m-%d %H:%M:%S')

@vit1251
Copy link
Author

vit1251 commented Apr 13, 2016

@jenisys you say that "Captured stdout/stderr/logging is normally only shown when a test fails." it no good idea and some time logs arrchiving and research on prevoius starting very usful. Could you provide ability always capture errors and stdtout in junit reports?

@jenisys
Copy link
Member

jenisys commented Apr 17, 2016

@vit1251
No, that is not a good idea to do that in junit reports. It will clutter them with irrelevant details even when all/many tests are passing.

What you should do, is to log the stuff you are interested in into a log-file and use it when needed (for doing the research) even when tests pass. This helps you also with long-running tests (that you hopefully not have) to see up to which internal step the system came. But you should be able to do that already by using log-filters for log-categories (excluding them from log-capture mode).

@vit1251
Copy link
Author

vit1251 commented Apr 18, 2016

@jenisys I would like to understand how I can to log into a separate file when the --junit is captured logs and it's killing my settings made in basicConfig. This is the case the principle can be implemented, is it possible to write the logs and use --junit simultaneously or is it mutually exclusive?

Logs totally required later after month or year and we can make difference between response and debug information when problem occure around the tests. It very nice knowladge resource.

@jenisys
Copy link
Member

jenisys commented Apr 18, 2016

@vit1251
You could for example use stdout/stderr for diagnostic info in failing steps and use logs in not-logcapture mode to log to a file. Otherwise, use logging-filters to ensure that information is always logged even when the scenario passes.

SEE ALSO:

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

No branches or pull requests

3 participants