refactor: Use hooks to specify default log clearing (#23507)
This commit is contained in:
parent
ba1d597e73
commit
c23771475c
3 changed files with 27 additions and 16 deletions
|
|
@ -10,20 +10,6 @@ from frappe.model.document import Document
|
|||
from frappe.utils import cint
|
||||
from frappe.utils.caching import site_cache
|
||||
|
||||
DEFAULT_LOGTYPES_RETENTION = {
|
||||
"Error Log": 30,
|
||||
"Activity Log": 90,
|
||||
"Email Queue": 30,
|
||||
"Scheduled Job Log": 90,
|
||||
"Route History": 90,
|
||||
"Submission Queue": 30,
|
||||
"Prepared Report": 30,
|
||||
"Webhook Request Log": 30,
|
||||
"Integration Request": 90,
|
||||
"Unhandled Email": 30,
|
||||
"Reminder": 30,
|
||||
}
|
||||
|
||||
|
||||
@runtime_checkable
|
||||
class LogType(Protocol):
|
||||
|
|
@ -81,12 +67,14 @@ class LogSettings(Document):
|
|||
def add_default_logtypes(self):
|
||||
existing_logtypes = {d.ref_doctype for d in self.logs_to_clear}
|
||||
added_logtypes = set()
|
||||
for logtype, retention in DEFAULT_LOGTYPES_RETENTION.items():
|
||||
default_logtypes_retention = frappe.get_hooks("default_log_clearing_doctypes", {})
|
||||
|
||||
for logtype, retentions in default_logtypes_retention.items():
|
||||
if logtype not in existing_logtypes and _supports_log_clearing(logtype):
|
||||
if not frappe.db.exists("DocType", logtype):
|
||||
continue
|
||||
|
||||
self.append("logs_to_clear", {"ref_doctype": logtype, "days": cint(retention)})
|
||||
self.append("logs_to_clear", {"ref_doctype": logtype, "days": cint(retentions[-1])})
|
||||
added_logtypes.add(logtype)
|
||||
|
||||
if added_logtypes:
|
||||
|
|
|
|||
|
|
@ -439,3 +439,18 @@ extend_bootinfo = [
|
|||
]
|
||||
|
||||
export_python_type_annotations = True
|
||||
|
||||
# log doctype cleanups to automatically add in log settings
|
||||
default_log_clearing_doctypes = {
|
||||
"Error Log": 30,
|
||||
"Activity Log": 90,
|
||||
"Email Queue": 30,
|
||||
"Scheduled Job Log": 90,
|
||||
"Route History": 90,
|
||||
"Submission Queue": 30,
|
||||
"Prepared Report": 30,
|
||||
"Webhook Request Log": 30,
|
||||
"Integration Request": 90,
|
||||
"Unhandled Email": 30,
|
||||
"Reminder": 30,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -551,6 +551,14 @@ app_license = "{app_license}"
|
|||
# auth_hooks = [
|
||||
# "{app_name}.auth.validate"
|
||||
# ]
|
||||
|
||||
# Automatically update python controller files with type annotations for this app.
|
||||
# export_python_type_annotations = True
|
||||
|
||||
# default_log_clearing_doctypes = {{
|
||||
# "Logging DocType Name": 30 # days to retain logs
|
||||
# }}
|
||||
|
||||
"""
|
||||
|
||||
gitignore_template = """.DS_Store
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue