-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
--debug
flag, replace all calls to print()
with a streamhandl…
…er logger (#256) Adds a `--debug` (`-d`) flag, which displays debug logging during dbt execution. Useful for debugging and making bug reports. Removes the `logs/` directory. If you want logs, use the debug flag instead.
- Loading branch information
Showing
17 changed files
with
169 additions
and
167 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
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,43 +1,24 @@ | ||
import logging | ||
import logging.config | ||
import os | ||
import sys | ||
|
||
def make_log_dir_if_missing(log_dir): | ||
if not os.path.exists(log_dir): | ||
os.makedirs(log_dir) | ||
# disable logs from other modules, excepting ERROR logs | ||
logging.getLogger('contracts').setLevel(logging.ERROR) | ||
logging.getLogger('requests').setLevel(logging.ERROR) | ||
logging.getLogger('urllib3').setLevel(logging.ERROR) | ||
|
||
def getLogger(log_dir, name): | ||
make_log_dir_if_missing(log_dir) | ||
filename = "dbt.log" | ||
base_log_path = os.path.join(log_dir, filename) | ||
|
||
dictLogConfig = { | ||
"version":1, | ||
"handlers": { | ||
"fileHandler":{ | ||
"class":"logging.handlers.TimedRotatingFileHandler", | ||
"formatter":"fileFormatter", | ||
"when": "d", # rotate daily | ||
"interval": 1, | ||
"backupCount": 7, | ||
"filename": base_log_path | ||
}, | ||
}, | ||
"loggers":{ | ||
"dbt":{ | ||
"handlers":["fileHandler"], | ||
"level":"DEBUG", | ||
"propagate": False | ||
} | ||
}, | ||
# create a global console logger for dbt | ||
handler = logging.StreamHandler(sys.stdout) | ||
handler.setFormatter(logging.Formatter('%(message)s')) | ||
|
||
"formatters":{ | ||
"fileFormatter":{ | ||
"format":"%(asctime)s - %(name)s - %(levelname)s - %(threadName)s - %(message)s" | ||
} | ||
} | ||
} | ||
logging.config.dictConfig(dictLogConfig) | ||
logger = logging.getLogger(name) | ||
return logger | ||
logger = logging.getLogger() | ||
logger.addHandler(handler) | ||
logger.setLevel(logging.INFO) | ||
|
||
|
||
def initialize_logger(debug_mode=False,): | ||
if debug_mode: | ||
handler.setFormatter(logging.Formatter('%(asctime)-18s: %(message)s')) | ||
logger.setLevel(logging.DEBUG) | ||
|
||
GLOBAL_LOGGER = logger |
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.