forked from cloudtools/stacker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request cloudtools#532 from remind101/simple-logging
Simplified logging
- Loading branch information
Showing
13 changed files
with
50 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
#!/usr/bin/env python | ||
|
||
from stacker.logger import setup_logging | ||
from stacker.commands import Stacker | ||
|
||
if __name__ == "__main__": | ||
stacker = Stacker() | ||
stacker = Stacker(setup_logging=setup_logging) | ||
args = stacker.parse_args() | ||
stacker.configure(args) | ||
args.run(args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,36 @@ | ||
import sys | ||
import logging | ||
|
||
from .handler import LogLoopStreamHandler | ||
from .formatter import ColorFormatter | ||
|
||
DEBUG_FORMAT = ("[%(asctime)s] %(levelname)s %(name)s:%(lineno)d" | ||
"(%(funcName)s): %(message)s") | ||
INFO_FORMAT = ("[%(asctime)s] %(message)s") | ||
COLOR_FORMAT = ("[%(asctime)s] %(color)s%(message)s") | ||
COLOR_FORMAT = ("[%(asctime)s] \033[%(color)sm%(message)s\033[39m") | ||
|
||
ISO_8601 = "%Y-%m-%dT%H:%M:%S" | ||
|
||
BASIC_LOGGER_TYPE = 0 | ||
LOOP_LOGGER_TYPE = 1 | ||
|
||
class ColorFormatter(logging.Formatter): | ||
""" Handles colorizing formatted log messages if color provided. """ | ||
def format(self, record): | ||
if 'color' not in record.__dict__: | ||
record.__dict__['color'] = 37 | ||
msg = super(ColorFormatter, self).format(record) | ||
return msg | ||
|
||
|
||
def setup_logging(verbosity, interactive=False, tail=False): | ||
enable_loop_logger = ( | ||
verbosity == 0 and | ||
sys.stdout.isatty() and | ||
not (interactive or tail) | ||
) | ||
def setup_logging(verbosity): | ||
log_level = logging.INFO | ||
log_format = INFO_FORMAT | ||
if sys.stdout.isatty(): | ||
log_format = COLOR_FORMAT | ||
|
||
if verbosity > 0: | ||
log_level = logging.DEBUG | ||
log_format = DEBUG_FORMAT | ||
if verbosity < 2: | ||
logging.getLogger("botocore").setLevel(logging.CRITICAL) | ||
|
||
log_type = BASIC_LOGGER_TYPE | ||
if enable_loop_logger: | ||
log_type = LOOP_LOGGER_TYPE | ||
fmt = ColorFormatter(COLOR_FORMAT, ISO_8601) | ||
hdlr = LogLoopStreamHandler() | ||
hdlr.setFormatter(fmt) | ||
logging.root.addHandler(hdlr) | ||
logging.root.setLevel(log_level) | ||
else: | ||
logging.basicConfig( | ||
format=log_format, | ||
datefmt=ISO_8601, | ||
level=log_level, | ||
) | ||
return log_type | ||
hdlr = logging.StreamHandler() | ||
hdlr.setFormatter(ColorFormatter(log_format, ISO_8601)) | ||
logging.root.addHandler(hdlr) | ||
logging.root.setLevel(log_level) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.