Allow for easier overriding of custom scripts _log method #130

Closed
opened 2026-04-05 16:22:04 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @mburggraf on 3/17/2026

NetBox version

v4.5.4

Feature type

Change to existing functionality

Proposed functionality

It's not really a request, but more like a proposal:
Change the function-signatures of the log-wrapper functions in netbox/extras/scripts.py, to take additional parameters, like:

    def log_debug(self, message=None, obj=None, *args, **kwargs):
        self._log(message, obj, level=LogLevelChoices.LOG_DEBUG, *args, **kwargs)

(for all the wrapper functions)

Use case

As the comment in the _log function states, it shouldn't be called directly, but instead only by using one of the wrapper functions.
In case the author of a custom scripts likes to extend the functionality of the log_* methods to take additional parameters (for example: self.log_info("text", lang="de_DE")), it's not only necessary to override the_log method, but also all of the wrappers, which needlessly bloats the script.
By changing the function signatures to take any number of additional argument, which are just transferred to the main function, an override for the main function is all it takes, without tampering with the functionality of the wrappers.

Additionally, by slightly modifying the _log function, to return the newly added dict-entry, the custom script author can easily extend the information in in:

self.messages.append(retval:={
 ⋮
return retval

could allow to access it in a possible override by entry = super()._log(message, obj, level).

Database changes

No change required.

External dependencies

No change required.

*Originally created by @mburggraf on 3/17/2026* ### NetBox version v4.5.4 ### Feature type Change to existing functionality ### Proposed functionality It's not really a request, but more like a proposal: Change the function-signatures of the log-wrapper functions in `netbox/extras/scripts.py`, to take additional parameters, like: ``` def log_debug(self, message=None, obj=None, *args, **kwargs): self._log(message, obj, level=LogLevelChoices.LOG_DEBUG, *args, **kwargs) ``` (for all the wrapper functions) ### Use case As the comment in the `_log` function states, it shouldn't be called directly, but instead only by using one of the wrapper functions. In case the author of a custom scripts likes to extend the functionality of the log_* methods to take additional parameters (for example: `self.log_info("text", lang="de_DE")`), it's not only necessary to override the`_log` method, but also all of the wrappers, which needlessly bloats the script. By changing the function signatures to take any number of additional argument, which are just transferred to the main function, an override for the main function is all it takes, without tampering with the functionality of the wrappers. _Additionally_, by slightly modifying the `_log` function, to return the newly added dict-entry, the custom script author can easily extend the information in in: ``` self.messages.append(retval:={ ⋮ return retval ``` could allow to access it in a possible override by `entry = super()._log(message, obj, level)`. ### Database changes No change required. ### External dependencies No change required.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/netbox#130