Skip to content

Commit a9a0f73

Browse files
committed
Update patch to add minion ID to master logs
Updates the Cloudflare patch to add minion ID to master logs: * Reverts changes to the default log formats - as with the existing support for JID it should probably be up to user to set that rather than us changing the defaults and potentially causing breakage. * Updates code to get id and log_fmt_minion_id from context as data is no longer available in _log
1 parent 91d9a3b commit a9a0f73

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

salt/_logging/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
DFLT_LOG_DATEFMT_LOGFILE,
1616
DFLT_LOG_FMT_CONSOLE,
1717
DFLT_LOG_FMT_JID,
18-
DFLT_LOG_FMT_MINION_ID,
1918
DFLT_LOG_FMT_LOGFILE,
19+
DFLT_LOG_FMT_MINION_ID,
2020
LOG_COLORS,
2121
LOG_LEVELS,
2222
LOG_VALUES_TO_LEVELS,

salt/_logging/impl.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""
2-
salt._logging.impl
3-
~~~~~~~~~~~~~~~~~~
2+
salt._logging.impl
3+
~~~~~~~~~~~~~~~~~~
44
5-
Salt's logging implementation classes/functionality
5+
Salt's logging implementation classes/functionality
66
"""
77

88
import atexit
@@ -103,8 +103,8 @@
103103
DFLT_LOG_FMT_MINION_ID = "[%(minion_id)s]"
104104
DFLT_LOG_DATEFMT = "%H:%M:%S"
105105
DFLT_LOG_DATEFMT_LOGFILE = "%Y-%m-%d %H:%M:%S"
106-
DFLT_LOG_FMT_CONSOLE = "[%(levelname)-8s]%(jid)s%(minion_id)s %(message)s"
107-
DFLT_LOG_FMT_LOGFILE = "%(asctime)s,%(msecs)03d [%(name)-17s:%(lineno)-4d][%(levelname)-8s][%(process)d]%(jid)s%(minion_id)s %(message)s"
106+
DFLT_LOG_FMT_CONSOLE = "[%(levelname)-8s] %(message)s"
107+
DFLT_LOG_FMT_LOGFILE = "%(asctime)s,%(msecs)03d [%(name)-17s:%(lineno)-4d][%(levelname)-8s][%(process)d] %(message)s"
108108

109109

110110
class SaltLogRecord(logging.LogRecord):
@@ -257,15 +257,22 @@ def _log(
257257
.get("log_fmt_jid", None)
258258
)
259259

260+
current_minion_id = (
261+
salt.utils.ctx.get_request_context().get("data", {}).get("id", None)
262+
)
263+
264+
log_fmt_minion_id = (
265+
salt.utils.ctx.get_request_context()
266+
.get("opts", {})
267+
.get("log_fmt_minion_id", None)
268+
)
269+
260270
if current_jid is not None:
261271
extra["jid"] = current_jid
262272

263273
if log_fmt_jid is not None:
264274
extra["log_fmt_jid"] = log_fmt_jid
265275

266-
current_minion_id = data.get("id", None)
267-
log_fmt_minion_id = opts.get("log_fmt_minion_id", None)
268-
269276
if current_minion_id is not None:
270277
extra["minion_id"] = current_minion_id
271278

salt/config/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
DFLT_LOG_DATEFMT_LOGFILE,
3737
DFLT_LOG_FMT_CONSOLE,
3838
DFLT_LOG_FMT_JID,
39-
DFLT_LOG_FMT_MINION_ID,
4039
DFLT_LOG_FMT_LOGFILE,
40+
DFLT_LOG_FMT_MINION_ID,
4141
)
4242

4343
try:
@@ -353,7 +353,7 @@ def _gather_buffer_space():
353353
"log_fmt_logfile": (tuple, str),
354354
# The format for JIDs prior to formatting into log lines as %(jid)s
355355
"log_fmt_jid": str,
356-
# The format for minion_ids prior to formatting into log lines as %(jid)s
356+
# The format for minion_ids prior to formatting into log lines as %(minion_id)s
357357
"log_fmt_minion_id": str,
358358
# A dictionary of logging levels
359359
"log_granular_levels": dict,

0 commit comments

Comments
 (0)