Skip to content

Commit 8ced5e1

Browse files
committed
Align Python Action logging with other st2 components:
- instead of hardcoded StreamHandler use logging configured in "cfg.CONF.actionrunner.logging" - update logging config to be a RotatingFileHandler and not include PID in name. PID is now part of the message format string so this information is not lost. - align logrotate config with above changes
1 parent 158ff97 commit 8ced5e1

File tree

3 files changed

+9
-17
lines changed

3 files changed

+9
-17
lines changed

conf/logrotate.conf

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@ notifempty
8686
daily
8787
rotate 5
8888
postrotate
89-
# Delete all files that haven't been modified in over 30 days
90-
# Clean up stale PID logs
91-
find . -type f -name "st2actionrunner*" -mtime +30 -exec rm -f {} \;
9289
st2ctl reopen-log-files st2actionrunner
9390
endscript
9491
}

st2actions/conf/logging.conf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ formatter=simpleConsoleFormatter
1818
args=(sys.stdout,)
1919

2020
[handler_fileHandler]
21-
class=st2common.log.FormatNamedFileHandler
21+
class=handlers.RotatingFileHandler
2222
level=INFO
2323
formatter=verboseConsoleFormatter
24-
args=('logs/st2actionrunner.{pid}.log',)
24+
args=('logs/st2actionrunner.log',)
2525

2626
[handler_auditHandler]
27-
class=st2common.log.FormatNamedFileHandler
27+
class=handlers.RotatingFileHandler
2828
level=AUDIT
2929
formatter=jsonFormatter
30-
args=('logs/st2actionrunner.{pid}.audit.log',)
30+
args=('logs/st2actionrunner.audit.log',)
3131

3232
[formatter_simpleConsoleFormatter]
3333
class=st2common.logging.formatters.ConsoleLogFormatter
@@ -36,7 +36,7 @@ datefmt=
3636

3737
[formatter_verboseConsoleFormatter]
3838
class=st2common.logging.formatters.ConsoleLogFormatter
39-
format=%(asctime)s %(thread)s %(levelname)s %(module)s [-] %(message)s
39+
format=%(asctime)s %(process)d %(thread)s %(levelname)s %(module)s [-] %(message)s
4040
datefmt=
4141

4242
[formatter_gelfFormatter]

st2actions/st2actions/runners/python_action_wrapper.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
import sys
1717
import json
1818
import argparse
19-
import logging as stdlib_logging
19+
20+
from oslo_config import cfg
2021

2122
from st2common import log as logging
2223
from st2actions import config
@@ -47,7 +48,7 @@ def __init__(self, pack, file_path, parameters=None, parent_args=None):
4748
:type parameters: ``dict`` or ``None``
4849
4950
:param parent_args: Command line arguments passed to the parent process.
50-
:type parse_args: ``list``
51+
:type parent_args: ``list``
5152
"""
5253

5354
self._pack = pack
@@ -115,13 +116,7 @@ def _set_up_logger(self, action_name):
115116
logger_name = 'actions.python.%s' % (action_name)
116117
logger = logging.getLogger(logger_name)
117118

118-
console = stdlib_logging.StreamHandler()
119-
console.setLevel(stdlib_logging.DEBUG)
120-
121-
formatter = stdlib_logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
122-
console.setFormatter(formatter)
123-
logger.addHandler(console)
124-
logger.setLevel(stdlib_logging.DEBUG)
119+
logging.setup(cfg.CONF.actionrunner.logging)
125120

126121
return logger
127122

0 commit comments

Comments
 (0)