lavaloon-eg / ksa_compliance

KSA Compliance App for KSA E-invoice
https://www.lavaloon.com/
GNU Affero General Public License v3.0
38 stars 34 forks source link

[Errno 2] No such file or directory: '/home/frappe/frappe-bench/sites/ager/logs/zatca.log' #77

Closed salman-aboholiqah closed 1 month ago

salman-aboholiqah commented 4 months ago

I have a site running well in production mode But when I ran this command

bench new-site ager

It shows me this error


Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 109, in <module>
    main()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 18, in main
    click.Group(commands=commands)(prog_name="bench")
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py", line 65, in new_site
    frappe.init(site=site, new_site=True)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 253, in init
    setup_module_map()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1554, in setup_module_map
    for module in get_module_list(app):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1394, in get_module_list
    return get_file_items(os.path.join(os.path.dirname(get_module(app_name).__file__), "modules.txt"))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1343, in get_module
    return importlib.import_module(modulename)
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/frappe/frappe-bench/apps/ksa_compliance/ksa_compliance/__init__.py", line 5, in <module>
    logger = get_logger('zatca', max_size=1_000_000)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/logger.py", line 73, in get_logger
    site_handler = RotatingFileHandler(sitelog_filename, maxBytes=max_size, backupCount=file_count)
  File "/usr/lib/python3.10/logging/handlers.py", line 155, in __init__
    BaseRotatingHandler.__init__(self, filename, mode, encoding=encoding,
  File "/usr/lib/python3.10/logging/handlers.py", line 58, in __init__
    logging.FileHandler.__init__(self, filename, mode=mode,
  File "/usr/lib/python3.10/logging/__init__.py", line 1169, in __init__
    StreamHandler.__init__(self, self._open())
  File "/usr/lib/python3.10/logging/__init__.py", line 1201, in _open
    return open_func(self.baseFilename, self.mode,
FileNotFoundError: [Errno 2] No such file or directory: '/home/frappe/frappe-bench/sites/ager/logs/zatca.log'
mhaggag commented 4 months ago

Hello,

The error indicates it's trying to create the log file under the site directory instead of the bench; usually the logs are under bench/logs but it's trying to create it under bench/sites/ager/logs, which doesn't exist. I suspect this is because we're creating the logger in __init__.py which gets loaded at various points. Presumably it's getting loaded during site creation while the current working directory is the actual site directory.

To fix this, we'll have to make logger creation lazy (i.e. the logger is created on demand the first time it's requested), which would require changing all references.

In the meantime, can you please try to create the logs directory under the site directory as a workaround? i.e. mkdir -p ~/frappe-bench/sites/ager/logs