prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Change default log location
  Logs by default are written to `./opsdroid.log`. So they end up being written wherever you run the command.
  
  Logs should either be written to `/var/log/opsdroid.log` or as that may not be writeable by all users maybe `~/.opsdroid/opsdroid.log`.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `opsdroid/const.py`
  Content:
  ```
  1 """Constants used by OpsDroid."""
  2 import os
  3 
  4 __version__ = "0.8.1"
  5 
  6 LOG_FILENAME = 'output.log'
  7 DEFAULT_GIT_URL = "https://github.com/opsdroid/"
  8 MODULES_DIRECTORY = "opsdroid-modules"
  9 DEFAULT_ROOT_PATH = os.path.join(os.path.expanduser("~"), ".opsdroid")
  10 DEFAULT_MODULES_PATH = os.path.join(DEFAULT_ROOT_PATH, "modules")
  11 DEFAULT_MODULE_DEPS_PATH = os.path.join(DEFAULT_ROOT_PATH, "site-packages")
  12 DEFAULT_CONFIG_PATH = os.path.join(DEFAULT_ROOT_PATH, "configuration.yaml")
  13 DEFAULT_MODULE_BRANCH = "master"
  14 EXAMPLE_CONFIG_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)),
  15                                    "configuration/example_configuration.yaml")
  16
  ```
  
  Path: `opsdroid/__main__.py`
  Content:
  ```
  1 """Starts opsdroid."""
  2 
  3 import sys
  4 import logging
  5 import argparse
  6 
  7 from opsdroid.core import OpsDroid
  8 from opsdroid.const import LOG_FILENAME, EXAMPLE_CONFIG_FILE
  9 from opsdroid.web import Web
  10 
  11 
  12 _LOGGER = logging.getLogger("opsdroid")
  13 
  14 
  15 def configure_logging(config):
  16     """Configure the root logger based on user config."""
  17     rootlogger = logging.getLogger()
  18     while rootlogger.handlers:
  19         rootlogger.handlers.pop()
  20 
  21     try:
  22         logfile_path = config["logging"]["path"]
  23     except KeyError:
  24         logfile_path = LOG_FILENAME
  25 
  26     try:
  27         log_level = get_logging_level(
  28             config["logging"]["level"])
  29     except KeyError:
  30         log_level = logging.INFO
  31 
  32     rootlogger.setLevel(log_level)
  33     formatter = logging.Formatter('%(levelname)s %(name)s: %(message)s')
  34 
  35     console_handler = logging.StreamHandler()
  36     console_handler.setLevel(log_level)
  37     console_handler.setFormatter(formatter)
  38     rootlogger.addHandler(console_handler)
  39 
  40     try:
  41         if not config["logging"]["console"]:
  42             console_handler.setLevel(logging.CRITICAL)
  43     except KeyError:
  44         pass
  45 
  46     if logfile_path:
  47         file_handler = logging.FileHandler(logfile_path)
  48         file_handler.setLevel(log_level)
  49         file_handler.setFormatter(formatter)
  50         rootlogger.addHandler(file_handler)
  51 
  52     _LOGGER.info("="*40)
  53     _LOGGER.info("Stated application")
  54 
  55 
  56 def get_logging_level(logging_level):
  57     """Get the logger level based on the user configuration."""
  58     if logging_level == 'critical':
  59         return logging.CRITICAL
  60     elif logging_level == 'error':
  61         return logging.ERROR
  62     elif logging_level == 'warning':
  63         return logging.WARNING
  64     elif logging_level == 'debug':
  65         return logging.DEBUG
  66 
  67     return logging.INFO
  68 
  69 
  70 def parse_args(args):
  71     """Parse command line arguments."""
  72     parser = argparse.ArgumentParser(description='Run opsdroid.')
  73     parser.add_argument('--gen-config', action="store_true",
  74                         help='prints out an example configuration file')
  75     return parser.parse_args(args)
  76 
  77 
  78 def check_dependencies():
  79     """Check for system dependencies required by opsdroid."""
  80     if sys.version_info[0] < 3 or sys.version_info[1] < 5:
  81         logging.critical("Whoops! opsdroid requires python 3.5 or above.")
  82         sys.exit(1)
  83 
  84 
  85 def main():
  86     """Enter the application here."""
  87     args = parse_args(sys.argv[1:])
  88 
  89     if args.gen_config:
  90         with open(EXAMPLE_CONFIG_FILE, 'r') as conf:
  91             print(conf.read())
  92         sys.exit(0)
  93 
  94     check_dependencies()
  95 
  96     restart = True
  97 
  98     while restart:
  99         with OpsDroid() as opsdroid:
  100             opsdroid.load()
  101             configure_logging(opsdroid.config)
  102             opsdroid.web_server = Web(opsdroid)
  103             opsdroid.start_loop()
  104             restart = opsdroid.should_restart
  105 
  106 
  107 if __name__ == "__main__":
  108     main()
  109
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/opsdroid/__main__.py b/opsdroid/__main__.py
  --- a/opsdroid/__main__.py
  +++ b/opsdroid/__main__.py
  @@ -1,11 +1,12 @@
   """Starts opsdroid."""
   
  +import os
   import sys
   import logging
   import argparse
   
   from opsdroid.core import OpsDroid
  -from opsdroid.const import LOG_FILENAME, EXAMPLE_CONFIG_FILE
  +from opsdroid.const import DEFAULT_LOG_FILENAME, EXAMPLE_CONFIG_FILE
   from opsdroid.web import Web
   
   
  @@ -19,9 +20,12 @@
           rootlogger.handlers.pop()
   
       try:
  -        logfile_path = config["logging"]["path"]
  +        if config["logging"]["path"]:
  +            logfile_path = os.path.expanduser(config["logging"]["path"])
  +        else:
  +            logfile_path = config["logging"]["path"]
       except KeyError:
  -        logfile_path = LOG_FILENAME
  +        logfile_path = DEFAULT_LOG_FILENAME
   
       try:
           log_level = get_logging_level(
  diff --git a/opsdroid/const.py b/opsdroid/const.py
  --- a/opsdroid/const.py
  +++ b/opsdroid/const.py
  @@ -3,10 +3,10 @@
   
   __version__ = "0.8.1"
   
  -LOG_FILENAME = 'output.log'
   DEFAULT_GIT_URL = "https://github.com/opsdroid/"
   MODULES_DIRECTORY = "opsdroid-modules"
  -DEFAULT_ROOT_PATH = os.path.join(os.path.expanduser("~"), ".opsdroid")
  +DEFAULT_ROOT_PATH = os.path.expanduser("~/.opsdroid")
  +DEFAULT_LOG_FILENAME = os.path.join(DEFAULT_ROOT_PATH, 'output.log')
   DEFAULT_MODULES_PATH = os.path.join(DEFAULT_ROOT_PATH, "modules")
   DEFAULT_MODULE_DEPS_PATH = os.path.join(DEFAULT_ROOT_PATH, "site-packages")
   DEFAULT_CONFIG_PATH = os.path.join(DEFAULT_ROOT_PATH, "configuration.yaml")
  
verification_info: {"golden_diff": "diff --git a/opsdroid/__main__.py b/opsdroid/__main__.py\n--- a/opsdroid/__main__.py\n+++ b/opsdroid/__main__.py\n@@ -1,11 +1,12 @@\n \"\"\"Starts opsdroid.\"\"\"\n \n+import os\n import sys\n import logging\n import argparse\n \n from opsdroid.core import OpsDroid\n-from opsdroid.const import LOG_FILENAME, EXAMPLE_CONFIG_FILE\n+from opsdroid.const import DEFAULT_LOG_FILENAME, EXAMPLE_CONFIG_FILE\n from opsdroid.web import Web\n \n \n@@ -19,9 +20,12 @@\n         rootlogger.handlers.pop()\n \n     try:\n-        logfile_path = config[\"logging\"][\"path\"]\n+        if config[\"logging\"][\"path\"]:\n+            logfile_path = os.path.expanduser(config[\"logging\"][\"path\"])\n+        else:\n+            logfile_path = config[\"logging\"][\"path\"]\n     except KeyError:\n-        logfile_path = LOG_FILENAME\n+        logfile_path = DEFAULT_LOG_FILENAME\n \n     try:\n         log_level = get_logging_level(\ndiff --git a/opsdroid/const.py b/opsdroid/const.py\n--- a/opsdroid/const.py\n+++ b/opsdroid/const.py\n@@ -3,10 +3,10 @@\n \n __version__ = \"0.8.1\"\n \n-LOG_FILENAME = 'output.log'\n DEFAULT_GIT_URL = \"https://github.com/opsdroid/\"\n MODULES_DIRECTORY = \"opsdroid-modules\"\n-DEFAULT_ROOT_PATH = os.path.join(os.path.expanduser(\"~\"), \".opsdroid\")\n+DEFAULT_ROOT_PATH = os.path.expanduser(\"~/.opsdroid\")\n+DEFAULT_LOG_FILENAME = os.path.join(DEFAULT_ROOT_PATH, 'output.log')\n DEFAULT_MODULES_PATH = os.path.join(DEFAULT_ROOT_PATH, \"modules\")\n DEFAULT_MODULE_DEPS_PATH = os.path.join(DEFAULT_ROOT_PATH, \"site-packages\")\n DEFAULT_CONFIG_PATH = os.path.join(DEFAULT_ROOT_PATH, \"configuration.yaml\")\n", "issue": "Change default log location\nLogs by default are written to `./opsdroid.log`. So they end up being written wherever you run the command.\r\n\r\nLogs should either be written to `/var/log/opsdroid.log` or as that may not be writeable by all users maybe `~/.opsdroid/opsdroid.log`.\n", "before_files": [{"content": "\"\"\"Constants used by OpsDroid.\"\"\"\nimport os\n\n__version__ = \"0.8.1\"\n\nLOG_FILENAME = 'output.log'\nDEFAULT_GIT_URL = \"https://github.com/opsdroid/\"\nMODULES_DIRECTORY = \"opsdroid-modules\"\nDEFAULT_ROOT_PATH = os.path.join(os.path.expanduser(\"~\"), \".opsdroid\")\nDEFAULT_MODULES_PATH = os.path.join(DEFAULT_ROOT_PATH, \"modules\")\nDEFAULT_MODULE_DEPS_PATH = os.path.join(DEFAULT_ROOT_PATH, \"site-packages\")\nDEFAULT_CONFIG_PATH = os.path.join(DEFAULT_ROOT_PATH, \"configuration.yaml\")\nDEFAULT_MODULE_BRANCH = \"master\"\nEXAMPLE_CONFIG_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)),\n                                   \"configuration/example_configuration.yaml\")\n", "path": "opsdroid/const.py"}, {"content": "\"\"\"Starts opsdroid.\"\"\"\n\nimport sys\nimport logging\nimport argparse\n\nfrom opsdroid.core import OpsDroid\nfrom opsdroid.const import LOG_FILENAME, EXAMPLE_CONFIG_FILE\nfrom opsdroid.web import Web\n\n\n_LOGGER = logging.getLogger(\"opsdroid\")\n\n\ndef configure_logging(config):\n    \"\"\"Configure the root logger based on user config.\"\"\"\n    rootlogger = logging.getLogger()\n    while rootlogger.handlers:\n        rootlogger.handlers.pop()\n\n    try:\n        logfile_path = config[\"logging\"][\"path\"]\n    except KeyError:\n        logfile_path = LOG_FILENAME\n\n    try:\n        log_level = get_logging_level(\n            config[\"logging\"][\"level\"])\n    except KeyError:\n        log_level = logging.INFO\n\n    rootlogger.setLevel(log_level)\n    formatter = logging.Formatter('%(levelname)s %(name)s: %(message)s')\n\n    console_handler = logging.StreamHandler()\n    console_handler.setLevel(log_level)\n    console_handler.setFormatter(formatter)\n    rootlogger.addHandler(console_handler)\n\n    try:\n        if not config[\"logging\"][\"console\"]:\n            console_handler.setLevel(logging.CRITICAL)\n    except KeyError:\n        pass\n\n    if logfile_path:\n        file_handler = logging.FileHandler(logfile_path)\n        file_handler.setLevel(log_level)\n        file_handler.setFormatter(formatter)\n        rootlogger.addHandler(file_handler)\n\n    _LOGGER.info(\"=\"*40)\n    _LOGGER.info(\"Stated application\")\n\n\ndef get_logging_level(logging_level):\n    \"\"\"Get the logger level based on the user configuration.\"\"\"\n    if logging_level == 'critical':\n        return logging.CRITICAL\n    elif logging_level == 'error':\n        return logging.ERROR\n    elif logging_level == 'warning':\n        return logging.WARNING\n    elif logging_level == 'debug':\n        return logging.DEBUG\n\n    return logging.INFO\n\n\ndef parse_args(args):\n    \"\"\"Parse command line arguments.\"\"\"\n    parser = argparse.ArgumentParser(description='Run opsdroid.')\n    parser.add_argument('--gen-config', action=\"store_true\",\n                        help='prints out an example configuration file')\n    return parser.parse_args(args)\n\n\ndef check_dependencies():\n    \"\"\"Check for system dependencies required by opsdroid.\"\"\"\n    if sys.version_info[0] < 3 or sys.version_info[1] < 5:\n        logging.critical(\"Whoops! opsdroid requires python 3.5 or above.\")\n        sys.exit(1)\n\n\ndef main():\n    \"\"\"Enter the application here.\"\"\"\n    args = parse_args(sys.argv[1:])\n\n    if args.gen_config:\n        with open(EXAMPLE_CONFIG_FILE, 'r') as conf:\n            print(conf.read())\n        sys.exit(0)\n\n    check_dependencies()\n\n    restart = True\n\n    while restart:\n        with OpsDroid() as opsdroid:\n            opsdroid.load()\n            configure_logging(opsdroid.config)\n            opsdroid.web_server = Web(opsdroid)\n            opsdroid.start_loop()\n            restart = opsdroid.should_restart\n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "opsdroid/__main__.py"}], "after_files": [{"content": "\"\"\"Constants used by OpsDroid.\"\"\"\nimport os\n\n__version__ = \"0.8.1\"\n\nDEFAULT_GIT_URL = \"https://github.com/opsdroid/\"\nMODULES_DIRECTORY = \"opsdroid-modules\"\nDEFAULT_ROOT_PATH = os.path.expanduser(\"~/.opsdroid\")\nDEFAULT_LOG_FILENAME = os.path.join(DEFAULT_ROOT_PATH, 'output.log')\nDEFAULT_MODULES_PATH = os.path.join(DEFAULT_ROOT_PATH, \"modules\")\nDEFAULT_MODULE_DEPS_PATH = os.path.join(DEFAULT_ROOT_PATH, \"site-packages\")\nDEFAULT_CONFIG_PATH = os.path.join(DEFAULT_ROOT_PATH, \"configuration.yaml\")\nDEFAULT_MODULE_BRANCH = \"master\"\nEXAMPLE_CONFIG_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)),\n                                   \"configuration/example_configuration.yaml\")\n", "path": "opsdroid/const.py"}, {"content": "\"\"\"Starts opsdroid.\"\"\"\n\nimport os\nimport sys\nimport logging\nimport argparse\n\nfrom opsdroid.core import OpsDroid\nfrom opsdroid.const import DEFAULT_LOG_FILENAME, EXAMPLE_CONFIG_FILE\nfrom opsdroid.web import Web\n\n\n_LOGGER = logging.getLogger(\"opsdroid\")\n\n\ndef configure_logging(config):\n    \"\"\"Configure the root logger based on user config.\"\"\"\n    rootlogger = logging.getLogger()\n    while rootlogger.handlers:\n        rootlogger.handlers.pop()\n\n    try:\n        if config[\"logging\"][\"path\"]:\n            logfile_path = os.path.expanduser(config[\"logging\"][\"path\"])\n        else:\n            logfile_path = config[\"logging\"][\"path\"]\n    except KeyError:\n        logfile_path = DEFAULT_LOG_FILENAME\n\n    try:\n        log_level = get_logging_level(\n            config[\"logging\"][\"level\"])\n    except KeyError:\n        log_level = logging.INFO\n\n    rootlogger.setLevel(log_level)\n    formatter = logging.Formatter('%(levelname)s %(name)s: %(message)s')\n\n    console_handler = logging.StreamHandler()\n    console_handler.setLevel(log_level)\n    console_handler.setFormatter(formatter)\n    rootlogger.addHandler(console_handler)\n\n    try:\n        if not config[\"logging\"][\"console\"]:\n            console_handler.setLevel(logging.CRITICAL)\n    except KeyError:\n        pass\n\n    if logfile_path:\n        file_handler = logging.FileHandler(logfile_path)\n        file_handler.setLevel(log_level)\n        file_handler.setFormatter(formatter)\n        rootlogger.addHandler(file_handler)\n\n    _LOGGER.info(\"=\"*40)\n    _LOGGER.info(\"Stated application\")\n\n\ndef get_logging_level(logging_level):\n    \"\"\"Get the logger level based on the user configuration.\"\"\"\n    if logging_level == 'critical':\n        return logging.CRITICAL\n    elif logging_level == 'error':\n        return logging.ERROR\n    elif logging_level == 'warning':\n        return logging.WARNING\n    elif logging_level == 'debug':\n        return logging.DEBUG\n\n    return logging.INFO\n\n\ndef parse_args(args):\n    \"\"\"Parse command line arguments.\"\"\"\n    parser = argparse.ArgumentParser(description='Run opsdroid.')\n    parser.add_argument('--gen-config', action=\"store_true\",\n                        help='prints out an example configuration file')\n    return parser.parse_args(args)\n\n\ndef check_dependencies():\n    \"\"\"Check for system dependencies required by opsdroid.\"\"\"\n    if sys.version_info[0] < 3 or sys.version_info[1] < 5:\n        logging.critical(\"Whoops! opsdroid requires python 3.5 or above.\")\n        sys.exit(1)\n\n\ndef main():\n    \"\"\"Enter the application here.\"\"\"\n    args = parse_args(sys.argv[1:])\n\n    if args.gen_config:\n        with open(EXAMPLE_CONFIG_FILE, 'r') as conf:\n            print(conf.read())\n        sys.exit(0)\n\n    check_dependencies()\n\n    restart = True\n\n    while restart:\n        with OpsDroid() as opsdroid:\n            opsdroid.load()\n            configure_logging(opsdroid.config)\n            opsdroid.web_server = Web(opsdroid)\n            opsdroid.start_loop()\n            restart = opsdroid.should_restart\n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "opsdroid/__main__.py"}]}