How to use the appdaemon.conf.logger function in appdaemon

To help you get started, we’ve selected a few appdaemon 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 home-assistant / appdaemon / appdaemon / appdaemon.py View on Github external
def init_object(name, class_name, module_name, args):
    ha.log(
        conf.logger, "INFO",
        "Loading Object {} using class {} from module {}".format(
            name, class_name, module_name
        )
    )
    module = __import__(module_name)
    app_class = getattr(module, class_name)
    conf.objects[name] = {
        "object": app_class(
            name, conf.logger, conf.error, args, conf.global_vars
        ),
        "id": uuid.uuid4()
    }

    # Call it's initialize function

    conf.objects[name]["object"].initialize()
github home-assistant / appdaemon / appdaemon / appdaemon.py View on Github external
# Load apps

    if conf.apps is True:
        ha.log(conf.logger, "DEBUG", "Reading Apps")

        read_apps(True)

        ha.log(conf.logger, "INFO", "App initialization complete")

        # Create timer thread

        # First, update "now" for less chance of clock skew error
        if conf.realtime:
            conf.now = datetime.datetime.now().timestamp()

            ha.log(conf.logger, "DEBUG", "Starting timer thread")

            t = threading.Thread(target=timer_thread)
            t.daemon = True
            t.start()

    # Start Dashboard Thread

    if conf.dashboard is True:
        ha.log(conf.logger, "INFO", "Starting dashboard")
        loop = asyncio.get_event_loop()
        t = threading.Thread(target=appdash.run_dash, args=(loop,))
        t.daemon = True
        t.start()

    # Enter main loop
github home-assistant / appdaemon / appdaemon / appdaemon.py View on Github external
if conf.errorfile is None:
        conf.errorfile = "STDERR"

    if isdaemon and (
                        conf.logfile == "STDOUT" or conf.errorfile == "STDERR"
                        or conf.logfile == "STDERR" or conf.errorfile == "STDOUT"
                    ):
        raise ValueError("STDOUT and STDERR not allowed with -d")

    # Setup Logging

    conf.logger = logging.getLogger("log1")
    numeric_level = getattr(logging, args.debug, None)
    conf.logger.setLevel(numeric_level)
    conf.logger.propagate = False
    # formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')

    # Send to file if we are daemonizing, else send to console

    fh = None
    if conf.logfile != "STDOUT":
        fh = RotatingFileHandler(conf.logfile, maxBytes=1000000, backupCount=3)
        fh.setLevel(numeric_level)
        # fh.setFormatter(formatter)
        conf.logger.addHandler(fh)
    else:
        # Default for StreamHandler() is sys.stderr
        ch = logging.StreamHandler(stream=sys.stdout)
        ch.setLevel(numeric_level)
        # ch.setFormatter(formatter)
        conf.logger.addHandler(ch)
github home-assistant / appdaemon / appdaemon / appdaemon.py View on Github external
if config['AppDaemon'].get("accessfile") is not None:
        conf.dash = logging.getLogger("log3")
        numeric_level = getattr(logging, args.debug, None)
        conf.dash.setLevel(numeric_level)
        conf.dash.propagate = False
        # formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
        efh = RotatingFileHandler(
            config['AppDaemon'].get("accessfile"), maxBytes=1000000, backupCount=3
        )

        efh.setLevel(numeric_level)
        # efh.setFormatter(formatter)
        conf.dash.addHandler(efh)
    else:
        conf.dash = conf.logger

    # Startup message

    ha.log(
        conf.logger, "INFO",
        "AppDaemon Version {} starting".format(__version__)
    )

    if not conf.apps:
        ha.log(
            conf.logger, "INFO",
            "Apps are disabled"
        )

    # Check with HA to get various info
github home-assistant / appdaemon / appdaemon / appdaemon.py View on Github external
conf.logfile = "STDOUT"

    if conf.errorfile is None:
        conf.errorfile = "STDERR"

    if isdaemon and (
                        conf.logfile == "STDOUT" or conf.errorfile == "STDERR"
                        or conf.logfile == "STDERR" or conf.errorfile == "STDOUT"
                    ):
        raise ValueError("STDOUT and STDERR not allowed with -d")

    # Setup Logging

    conf.logger = logging.getLogger("log1")
    numeric_level = getattr(logging, args.debug, None)
    conf.logger.setLevel(numeric_level)
    conf.logger.propagate = False
    # formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')

    # Send to file if we are daemonizing, else send to console

    fh = None
    if conf.logfile != "STDOUT":
        fh = RotatingFileHandler(conf.logfile, maxBytes=1000000, backupCount=3)
        fh.setLevel(numeric_level)
        # fh.setFormatter(formatter)
        conf.logger.addHandler(fh)
    else:
        # Default for StreamHandler() is sys.stderr
        ch = logging.StreamHandler(stream=sys.stdout)
        ch.setLevel(numeric_level)
        # ch.setFormatter(formatter)
github home-assistant / appdaemon / appdaemon / appdaemon.py View on Github external
# Setup Logging

    conf.logger = logging.getLogger("log1")
    numeric_level = getattr(logging, args.debug, None)
    conf.logger.setLevel(numeric_level)
    conf.logger.propagate = False
    # formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')

    # Send to file if we are daemonizing, else send to console

    fh = None
    if conf.logfile != "STDOUT":
        fh = RotatingFileHandler(conf.logfile, maxBytes=1000000, backupCount=3)
        fh.setLevel(numeric_level)
        # fh.setFormatter(formatter)
        conf.logger.addHandler(fh)
    else:
        # Default for StreamHandler() is sys.stderr
        ch = logging.StreamHandler(stream=sys.stdout)
        ch.setLevel(numeric_level)
        # ch.setFormatter(formatter)
        conf.logger.addHandler(ch)

    # Setup compile output

    conf.error = logging.getLogger("log2")
    numeric_level = getattr(logging, args.debug, None)
    conf.error.setLevel(numeric_level)
    conf.error.propagate = False
    # formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')

    if conf.errorfile != "STDERR":
github home-assistant / appdaemon / appdaemon / appdaemon.py View on Github external
if conf.logfile is None:
        conf.logfile = "STDOUT"

    if conf.errorfile is None:
        conf.errorfile = "STDERR"

    if isdaemon and (
                        conf.logfile == "STDOUT" or conf.errorfile == "STDERR"
                        or conf.logfile == "STDERR" or conf.errorfile == "STDOUT"
                    ):
        raise ValueError("STDOUT and STDERR not allowed with -d")

    # Setup Logging

    conf.logger = logging.getLogger("log1")
    numeric_level = getattr(logging, args.debug, None)
    conf.logger.setLevel(numeric_level)
    conf.logger.propagate = False
    # formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')

    # Send to file if we are daemonizing, else send to console

    fh = None
    if conf.logfile != "STDOUT":
        fh = RotatingFileHandler(conf.logfile, maxBytes=1000000, backupCount=3)
        fh.setLevel(numeric_level)
        # fh.setFormatter(formatter)
        conf.logger.addHandler(fh)
    else:
        # Default for StreamHandler() is sys.stderr
        ch = logging.StreamHandler(stream=sys.stdout)
github home-assistant / appdaemon / appdaemon / appdaemon.py View on Github external
conf.logger, "WARNING",
                            "Unexpected result from Home Assistant, "
                            "id = {}".format(_id)
                        )
                        ha.log(conf.logger, "WARNING", result)
                        raise ValueError(
                            "Unexpected result from Home Assistant"
                        )

                    process_message(result["event"])

        except:
            reading_messages = False
            if not stopping:
                ha.log(
                    conf.logger, "WARNING",
                    "Disconnected from Home Assistant, retrying in 5 seconds"
                )
                if conf.loglevel == "DEBUG":
                    ha.log(conf.logger, "WARNING", '-' * 60)
                    ha.log(conf.logger, "WARNING", "Unexpected error:")
                    ha.log(conf.logger, "WARNING", '-' * 60)
                    ha.log(conf.logger, "WARNING", traceback.format_exc())
                    ha.log(conf.logger, "WARNING", '-' * 60)
                time.sleep(5)

    ha.log(conf.logger, "INFO", "Disconnected from Home Assistant")
github home-assistant / appdaemon / appdaemon / hassapi.py View on Github external
def info_listen_state(self, handle):
        name = self.name
        utils.log(
            conf.logger, "DEBUG",
            "Calling info_listen_state for {}".format(name)
        )
        with conf.callbacks_lock:
            if name in conf.callbacks and handle in conf.callbacks[name]:
                callback = conf.callbacks[name][handle]
                return (
                    callback["entity"],
                    callback["kwargs"].get("attribute", None),
                    utils.sanitize_state_kwargs(callback["kwargs"])
                )
            else:
                raise ValueError("Invalid handle: {}".format(handle))
    #