How to use the dbt.logger.GLOBAL_LOGGER function in dbt

To help you get started, we’ve selected a few dbt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fishtown-analytics / dbt / test / integration / base.py View on Github external
register_adapter(self.config)
        adapter = get_adapter(self.config)
        if adapter is not self.adapter:
            adapter.cleanup_connections()
        if not hasattr(self, 'adapter'):
            self.adapter = adapter

        self._drop_schemas()

        self.adapter.cleanup_connections()
        reset_adapters()
        os.chdir(INITIAL_ROOT)
        try:
            shutil.rmtree(self.test_root_dir)
        except EnvironmentError:
            logger.exception('Could not clean up after test - {} not removable'
                             .format(self.test_root_dir))
github fishtown-analytics / dbt / core / dbt / task / migrate.py View on Github external
def migrate_archive_ctas(self, dest):
        # get the columns
        columns = self.adapter.get_columns_in_relation(self.relation)
        if len(columns) == 0:
            # the archive target must not exist? Continue, that is ok.
            logger.info('  - Table {} does not exist, nothing to migrate.'
                        .format(self.relation))
            return
        cols = {c.name.lower(): c.name for c in columns}
        renames = self.get_renamed_columns()
        select_parts = []
        select_as_parts = []
        for old, new in renames:
            key = old.strip('"').lower()
            if key not in cols:
                raise Exception(
                    'expected column like {} not but it is not in the table!'
                    .format(key)
                )
            del cols[key]
            select_as_parts.append('{} as {}'.format(old, new))
github fishtown-analytics / dbt / core / dbt / compilation.py View on Github external
NodeType.Analysis: 'analyse',
        NodeType.Macro: 'macro',
        NodeType.Operation: 'operation',
        NodeType.Seed: 'seed file',
        NodeType.Source: 'source',
    }

    results = {k: 0 for k in names.keys()}
    results.update(stats)

    stat_line = ", ".join([
        dbt.utils.pluralize(ct, names.get(t)) for t, ct in results.items()
        if t in names
    ])

    logger.info("Found {}".format(stat_line))
github fishtown-analytics / dbt / dbt / config.py View on Github external
def warn_for_unused_resource_config_paths(self, resource_fqns, disabled):
        unused = self.get_unused_resource_config_paths(resource_fqns, disabled)
        if len(unused) == 0:
            return

        msg = UNUSED_RESOURCE_CONFIGURATION_PATH_MESSAGE.format(
            len(unused),
            '\n'.join('- {}'.format('.'.join(u)) for u in unused)
        )
        logger.info(dbt.ui.printer.yellow(msg))
github fishtown-analytics / dbt / core / dbt / task / runnable.py View on Github external
def call_runner(self, runner):
        uid_context = UniqueID(runner.node.unique_id)
        with RUNNING_STATE, uid_context:
            startctx = TimestampNamed('node_started_at')
            index = self.index_offset(runner.node_index)
            extended_metadata = ModelMetadata(runner.node, index)
            with startctx, extended_metadata:
                logger.debug('Began running node {}'.format(
                    runner.node.unique_id))
            status = 'error'  # we must have an error if we don't see this
            try:
                result = runner.run_with_hooks(self.manifest)
                status = runner.get_result_status(result)
            finally:
                finishctx = TimestampNamed('node_finished_at')
                with finishctx, DbtModelState(status):
                    logger.debug('Finished running node {}'.format(
                        runner.node.unique_id))
        if result.error is not None and self.raise_on_first_error():
            # if we raise inside a thread, it'll just get silently swallowed.
            # stash the error message we want here, and it will check the
            # next 'tick' - should be soon since our thread is about to finish!
            self._raise_next_tick = result.error
github fishtown-analytics / dbt / core / dbt / clients / registry.py View on Github external
def _get(path, registry_base_url=None):
    url = _get_url(path, registry_base_url)
    logger.debug('Making package registry request: GET {}'.format(url))
    resp = requests.get(url)
    logger.debug('Response from registry: GET {} {}'.format(url,
                                                            resp.status_code))
    resp.raise_for_status()
    return resp.json()
github fishtown-analytics / dbt / core / dbt / node_runners.py View on Github external
def _handle_generic_exception(self, e, ctx):
        node_description = self.node.get('build_path')
        if node_description is None:
            node_description = self.node.unique_id
        prefix = "Unhandled error while executing {description}".format(
                    description=node_description)

        error = "{prefix}\n{error}".format(
                     prefix=dbt.ui.printer.red(prefix),
                     error=str(e).strip())

        logger.error(error)
        logger.debug('', exc_info=True)
        return dbt.compat.to_string(e)
github fishtown-analytics / dbt / core / dbt / main.py View on Github external
def main(args=None):
    if args is None:
        args = sys.argv[1:]

    try:
        results, succeeded = handle_and_check(args)
        if succeeded:
            exit_code = ExitCodes.Success
        else:
            exit_code = ExitCodes.ModelError

    except KeyboardInterrupt:
        logger.info("ctrl-c")
        exit_code = ExitCodes.UnhandledError

    # This can be thrown by eg. argparse
    except SystemExit as e:
        exit_code = e.code

    except BaseException as e:
        logger.info("Encountered an error:")
        logger.info(str(e))

        if logger_initialized():
            logger.debug(traceback.format_exc())
        elif not isinstance(e, RuntimeException):
            # if it did not come from dbt proper and the logger is not
            # initialized (so there's no safe path to log to), log the stack
            # trace at error level.
github fishtown-analytics / dbt / core / dbt / task / runnable.py View on Github external
def run(self):
        """
        Run dbt for the query, based on the graph.
        """
        self._runtime_initialize()

        if len(self._flattened_nodes) == 0:
            logger.info("WARNING: Nothing to do. Try checking your model "
                        "configs and model specification args")
            return []
        else:
            logger.info("")

        selected_uids = frozenset(n.unique_id for n in self._flattened_nodes)
        result = self.execute_with_hooks(selected_uids)

        result.write(self.result_path())

        self.task_end_messages(result.results)
        return result.results
github fishtown-analytics / dbt / plugins / bigquery / dbt / adapters / bigquery / connections.py View on Github external
def exception_handler(self, sql, connection_name='master'):
        try:
            yield

        except google.cloud.exceptions.BadRequest as e:
            message = "Bad request while running:\n{sql}"
            self.handle_error(e, message, sql)

        except google.cloud.exceptions.Forbidden as e:
            message = "Access denied while running:\n{sql}"
            self.handle_error(e, message, sql)

        except Exception as e:
            logger.debug("Unhandled error while running:\n{}".format(sql))
            logger.debug(e)
            raise dbt.exceptions.RuntimeException(dbt.compat.to_string(e))