[actions] support multiple actions per pattern
This commit is contained in:
@@ -936,23 +936,31 @@ Description
|
|||||||
extractor.*.actions
|
extractor.*.actions
|
||||||
-------------------
|
-------------------
|
||||||
Type
|
Type
|
||||||
* ``object`` (`pattern` -> `action`)
|
* ``object`` (`pattern` -> `action(s)`)
|
||||||
* ``list`` of ``lists`` with 2 ``strings`` as elements
|
* ``list`` of ``lists`` with `pattern` -> `action(s)` pairs as elements
|
||||||
Example
|
Example
|
||||||
.. code:: json
|
.. code:: json
|
||||||
|
|
||||||
{
|
{
|
||||||
"error" : "status |= 1",
|
"info:Logging in as .+" : "level = debug",
|
||||||
"warning:(?i)unable to .+": "exit 127",
|
"warning:(?i)unable to .+": "exit 127",
|
||||||
"info:Logging in as .+" : "level = debug"
|
"error" : [
|
||||||
|
"status |= 1",
|
||||||
|
"exec notify.sh 'gdl error'",
|
||||||
|
"abort"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
.. code:: json
|
.. code:: json
|
||||||
|
|
||||||
[
|
[
|
||||||
["error" , "status |= 1" ],
|
["info:Logging in as .+" , "level = debug"],
|
||||||
["warning:(?i)unable to .+", "exit 127" ],
|
["warning:(?i)unable to .+", "exit 127" ],
|
||||||
["info:Logging in as .+" , "level = debug"]
|
["error" , [
|
||||||
|
"status |= 1",
|
||||||
|
"exec notify.sh 'gdl error'",
|
||||||
|
"abort"
|
||||||
|
]]
|
||||||
]
|
]
|
||||||
|
|
||||||
Description
|
Description
|
||||||
@@ -968,6 +976,9 @@ Description
|
|||||||
``action`` is parsed as action type
|
``action`` is parsed as action type
|
||||||
followed by (optional) arguments.
|
followed by (optional) arguments.
|
||||||
|
|
||||||
|
It is possible to specify more than one ``action`` per ``pattern``
|
||||||
|
by providing them as a ``list``: ``["<action1>", "<action2>", …]``
|
||||||
|
|
||||||
Supported Action Types:
|
Supported Action Types:
|
||||||
|
|
||||||
``status``:
|
``status``:
|
||||||
@@ -982,9 +993,9 @@ Description
|
|||||||
``level``:
|
``level``:
|
||||||
| Modify severity level of the current logging message.
|
| Modify severity level of the current logging message.
|
||||||
| Can be one of ``debug``, ``info``, ``warning``, ``error`` or an integer value.
|
| Can be one of ``debug``, ``info``, ``warning``, ``error`` or an integer value.
|
||||||
``print``
|
``print``:
|
||||||
Write argument to stdout.
|
Write argument to stdout.
|
||||||
``exec``
|
``exec``:
|
||||||
Run a shell command.
|
Run a shell command.
|
||||||
``abort``:
|
``abort``:
|
||||||
Stop the current extractor run.
|
Stop the current extractor run.
|
||||||
@@ -993,7 +1004,8 @@ Description
|
|||||||
``restart``:
|
``restart``:
|
||||||
Restart the current extractor run.
|
Restart the current extractor run.
|
||||||
``wait``:
|
``wait``:
|
||||||
Stop execution until Enter is pressed.
|
| Sleep for a given Duration_ or
|
||||||
|
| wait until Enter is pressed when no argument was given.
|
||||||
``exit``:
|
``exit``:
|
||||||
Exit the program with the given argument as exit status.
|
Exit the program with the given argument as exit status.
|
||||||
|
|
||||||
|
|||||||
@@ -27,9 +27,17 @@ def parse(actionspec):
|
|||||||
|
|
||||||
for event, spec in actionspec:
|
for event, spec in actionspec:
|
||||||
level, _, pattern = event.partition(":")
|
level, _, pattern = event.partition(":")
|
||||||
type, _, args = spec.partition(" ")
|
|
||||||
search = re.compile(pattern).search if pattern else util.true
|
search = re.compile(pattern).search if pattern else util.true
|
||||||
action = (search, ACTIONS[type](args))
|
|
||||||
|
if isinstance(spec, str):
|
||||||
|
type, _, args = spec.partition(" ")
|
||||||
|
action = (search, ACTIONS[type](args))
|
||||||
|
else:
|
||||||
|
action_list = []
|
||||||
|
for s in spec:
|
||||||
|
type, _, args = s.partition(" ")
|
||||||
|
action_list.append(ACTIONS[type](args))
|
||||||
|
action = (search, _chain_actions(action_list))
|
||||||
|
|
||||||
level = level.strip()
|
level = level.strip()
|
||||||
if not level or level == "*":
|
if not level or level == "*":
|
||||||
@@ -50,6 +58,13 @@ def _level_to_int(level):
|
|||||||
return int(level)
|
return int(level)
|
||||||
|
|
||||||
|
|
||||||
|
def _chain_actions(actions):
|
||||||
|
def _chain(args):
|
||||||
|
for action in actions:
|
||||||
|
action(args)
|
||||||
|
return _chain
|
||||||
|
|
||||||
|
|
||||||
def action_print(opts):
|
def action_print(opts):
|
||||||
def _print(_):
|
def _print(_):
|
||||||
print(opts)
|
print(opts)
|
||||||
|
|||||||
Reference in New Issue
Block a user