Merge ~ec0/juju-lint:fix-logging-color-when-piped into juju-lint:master

Proposed by James Hebden
Status: Merged
Approved by: James Troup
Approved revision: 11151887a5c2a525b48bd4968f5d0133a652b5f0
Merged at revision: 9c9a145973e94d89f50108dd2f547b74bb1a5bb4
Proposed branch: ~ec0/juju-lint:fix-logging-color-when-piped
Merge into: juju-lint:master
Diff against target: 21 lines (+2/-1)
1 file modified
jujulint/logging.py (+2/-1)
Reviewer Review Type Date Requested Status
Juju Lint maintainers Pending
Review via email: mp+385229@code.launchpad.net

Commit message

Disable coloured logging when stdout is redirected

Description of the change

This merge ensures coloured output is disabled when the standard output of the program is redirected from the console (either piped to another program, or redirected to a file) in the user's shell, rather than using the commandline argument to create a log file.

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 9c9a145973e94d89f50108dd2f547b74bb1a5bb4

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/jujulint/logging.py b/jujulint/logging.py
2index 00dd200..47eaa88 100644
3--- a/jujulint/logging.py
4+++ b/jujulint/logging.py
5@@ -32,7 +32,7 @@ class Logger:
6 if not len(self.logger.handlers):
7 format_string = "%(log_color)s%(asctime)s [%(levelname)s] %(message)s"
8 date_format = "%Y-%m-%d %H:%M:%S"
9- colour_formatter = colorlog.ColoredFormatter(
10+ colour_formatter = colorlog.TTYColoredFormatter(
11 format_string,
12 datefmt=date_format,
13 log_colors={
14@@ -42,6 +42,7 @@ class Logger:
15 "ERROR": "red",
16 "CRITICAL": "red,bg_white",
17 },
18+ stream=sys.stdout,
19 )
20 console = colorlog.StreamHandler()
21 console.setFormatter(colour_formatter)

Subscribers

People subscribed via source and target branches