Merge bootstack-ops:logging into bootstack-ops:master

Proposed by Joe Guo
Status: Merged
Approved by: Xav Paice
Approved revision: c14d73714cb7f53fd36c3316eddb15ad49b3b0d1
Merged at revision: 17f147128087a6c1d63a282fde480b74b1c95677
Proposed branch: bootstack-ops:logging
Merge into: bootstack-ops:master
Diff against target: 47 lines (+9/-4)
1 file modified
bootstack-ops/juju_bundle_export.py (+9/-4)
Reviewer Review Type Date Requested Status
Xav Paice (community) Approve
Review via email: mp+384082@code.launchpad.net

Commit message

juju_bundle_export.py: use logging for diagnosis info

currenly, both diagnosis info and sanitized bundle yaml are printed to stdout.

this patch uses logging for diagnosis info, which will print to stderr instead of stdout.

This will be helpful to exclude diagnosis info when we redirect the output to file with `>` or `tee`.

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
Xav Paice (xavpaice) wrote :

LGTM, tests OK

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

Change successfully merged at revision 17f147128087a6c1d63a282fde480b74b1c95677

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/bootstack-ops/juju_bundle_export.py b/bootstack-ops/juju_bundle_export.py
2index 8f1845d..d64a7aa 100755
3--- a/bootstack-ops/juju_bundle_export.py
4+++ b/bootstack-ops/juju_bundle_export.py
5@@ -27,6 +27,11 @@ import sys
6 import yaml
7 import argparse
8 import math
9+import logging
10+
11+LOG_FORMAT = '%(asctime)s - %(levelname)-9s - %(module)s - %(message)s'
12+logging.basicConfig(format=LOG_FORMAT)
13+log = logging.getLogger(__name__)
14
15
16 MASK_KEYS = ('(.*(ssl-public-key|ssl[_-](ca|cert|key)|secret|password|'
17@@ -78,7 +83,7 @@ class Bundle(object):
18 def get_common_bundle(self):
19 # return the common info only
20 if self.__check_for_entropy_in_dict(self.common_bundle):
21- print('Some entropy was found in the common bundle')
22+ log.warning('Some entropy was found in the common bundle')
23 common_bundle = self.common_bundle
24 return common_bundle
25
26@@ -132,18 +137,18 @@ class Bundle(object):
27 if b64Entropy > 3.8:
28 stringsFound.append(string)
29 entropy_found = True
30- print('WARNING! Entropy found in string '
31+ log.warning('WARNING! Entropy found in string '
32 '"{}"'.format(string))
33 for string in hex_strings:
34 hexEntropy = self.__shannon_entropy(string, HEX_CHARS)
35 if hexEntropy > 3:
36 stringsFound.append(string)
37 entropy_found = True
38- print('WARNING! Entropy found in string '
39+ log.warning('WARNING! Entropy found in string '
40 '"{}"'.format(string))
41
42 if len(stringsFound) != 0:
43- print('ERROR!!! Check output file for entropy warnings, '
44+ log.error('ERROR!!! Check output file for entropy warnings, '
45 'may not be secure.')
46
47 return entropy_found

Subscribers

People subscribed via source and target branches

to all changes: