Example #1
0
    def format(self, msg, force_pretty=False, tag=None):

        if not self.pretty and not force_pretty:
            return msg
        elif isinstance(msg, (list, tuple)):
            return assert_json(msg, indent=4)
        elif hasattr(msg, 'pretty'):
            msg = getattr(msg, 'pretty')()

        if isinstance(msg, dict):
            clean_dyct = self.cleaner(msg)
            kaptan = Kaptan().import_config(clean_dyct)
            yaml = kaptan.export(handler=LoggerConst.PRETTY_FMT,
                                 explicit_start=True)
            return order_yaml(yaml)

        msg = assert_str(msg, allow_none=True)

        if tag is None:
            return msg
        else:
            return '{ts} - {tag} - {msg}'.format(ts=datetime.now().strftime(
                DateFmt.READABLE),
                                                 tag=tag,
                                                 msg=msg)