1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
Feature: Setup logging subsystem by using a logging configfile
As a tester
I want to setup the logging subsystem by using a configfile
To be more flexible even in complex situations
@setup
Scenario: Feature setup
Given a new working directory
And a file named "features/steps/use_behave4cmd_steps.py" with:
"""
import behave4cmd0.log.steps
import behave4cmd0.failing_steps
import behave4cmd0.passing_steps
"""
And a file named "features/example.log_and_pass.feature" with:
"""
Feature:
Scenario: Passing
Given I create log records with:
| category | level | message |
| root | FATAL | Hello Alice |
| foo | ERROR | Hello Bob |
| foo.bar | WARN | Hello Charly |
| bar | INFO | Hello Dora |
| baz | DEBUG | Hello Emily |
And another step passes
"""
And a file named "features/example.log_and_fail.feature" with:
"""
Feature:
Scenario: Failing
Given I create log records with:
| category | level | message |
| root | FATAL | Hello Alice |
| foo | ERROR | Hello Bob |
| foo.bar | WARN | Hello Charly |
| bar | INFO | Hello Dora |
| baz | DEBUG | Hello Emily |
And another step fails
"""
And a file named "behave.ini" with:
"""
[behave]
log_capture = false
logging_level = DEBUG
logging_format = LOG.%(levelname)-8s %(name)-10s: %(message)s
"""
And a file named "behave_logging.ini" with:
"""
[loggers]
keys=root
[handlers]
keys=Console,File
[formatters]
keys=Brief
[logger_root]
level = NOTSET
handlers = File
# handlers = Console,File
[handler_File]
class=FileHandler
args=("behave.log", 'w')
level=NOTSET
formatter=Brief
[handler_Console]
class=StreamHandler
args=(sys.stderr,)
level=NOTSET
formatter=Brief
[formatter_Brief]
format= LOG.%(levelname)-8s %(name)-10s: %(message)s
datefmt=
"""
Scenario: Setup logging subsystem via environment (case: logging mode)
Given a file named "features/environment.py" with:
"""
def before_all(context):
context.config.setup_logging(configfile="behave_logging.ini")
"""
And I use the log record configuration:
| property | value |
| format | LOG.%(levelname)-8s %(name)-10s: %(message)s |
When I run "behave -f plain features/example.log_and_pass.feature"
Then it should pass
And the file "behave.log" should contain the log records:
| category | level | message |
| root | FATAL | Hello Alice |
| foo | ERROR | Hello Bob |
| foo.bar | WARN | Hello Charly |
| bar | INFO | Hello Dora |
| baz | DEBUG | Hello Emily |
And the command output should not contain the following log records:
| category | level | message |
| root | FATAL | Hello Alice |
| foo | ERROR | Hello Bob |
| foo.bar | WARN | Hello Charly |
| bar | INFO | Hello Dora |
| baz | DEBUG | Hello Emily |
Scenario: Setup logging subsystem via environment (case: log-capture mode)
Given a file named "features/environment.py" with:
"""
def before_all(context):
context.config.setup_logging(configfile="behave_logging.ini")
"""
And I use the log record configuration:
| property | value |
| format | LOG.%(levelname)-8s %(name)-10s: %(message)s |
When I run "behave -f plain --logcapture features/example.log_and_fail.feature"
Then it should fail with:
"""
0 scenarios passed, 1 failed, 0 skipped
1 step passed, 1 failed, 0 skipped, 0 undefined
"""
And the file "behave.log" should contain the log records:
| category | level | message |
| root | FATAL | Hello Alice |
| foo | ERROR | Hello Bob |
| foo.bar | WARN | Hello Charly |
| bar | INFO | Hello Dora |
| baz | DEBUG | Hello Emily |
And the command output should contain the following log records:
| category | level | message |
| root | FATAL | Hello Alice |
| foo | ERROR | Hello Bob |
| foo.bar | WARN | Hello Charly |
| bar | INFO | Hello Dora |
| baz | DEBUG | Hello Emily |
|