sheepduke/chameleon

It would be nice to have hooks to run when the profile is switched

Closed this issue · 6 comments

This way, for example, cl-log can be configured.

Probably this could be easier if a profile would be a class instance instead of a keyword.

This way, for example, cl-log can be configured.

Probably this could be easier if a profile would be a class instance instead of a keyword.

OH! I am really sorry that I totally missed your comment.

This is actually an interesting idea. By using class instance one can easily inject functions to monitor value changes. Or it could be implemented simply as a special variable to store hooks, which seems more f

By the way, I am curious about the scenario here. In which case do you think the hooks will be needed? I thought one barely wants to switch profiles when the system is running unless for debugging purpose...

Oh wait...is there any built-in way to get notification when slot value is changed? I do not think I know it, but something like on-change sparked in my head...

I found this article recently. It shows an example of CLOS metaclass allowing to track slot changing.

By the way, I am curious about the scenario here. In which case do you think the hooks will be needed? I thought one barely wants to switch profiles when the system is running unless for debugging purpose...

Changing log level when you are switching from production to develop mode, creating a default database connection for the reply, etc.

Here is my notes on chameleon: https://40ants.com/lisp-project-of-the-day/2020/07/0127-chameleon.html where I show how the log level can be defined in profiles, but there is no way to reconfigure the logger on profile change.

By the way, I am curious about the scenario here. In which case do you think the hooks will be needed? I thought one barely wants to switch profiles when the system is running unless for debugging purpose...

Changing log level when you are switching from production to develop mode, creating a default database connection for the reply, etc.

Here is my notes on chameleon: https://40ants.com/lisp-project-of-the-day/2020/07/0127-chameleon.html where I show how the log level can be defined in profiles, but there is no way to reconfigure the logger on profile change.

I read through your notes. I am rather open to the discussion. :-)

My initial idea about Chameleon is that I want to avoid bare-metal keyword usage everywhere. Instead, I want to use functions to access the configurations.

My ideal scenario is that you define an individual package (something like config) and limit exported symbols to it. In the end, you use the configurations like (config:server-port) or so.

In this case, it is possible to implement hook by implementing an access function by yourself. For example:

(defun change-profile (new-profile callback)
  (setf (active-profile) new-profile)
  (funcall callback))

Then use it like:

(config:change-profile 
  (lambda () (log:config (log-level))))
  1. What do you think? Or is it better to include a hook system?

Another question regards to your blog :-)
2. Could you please elaborate on how could the code be simpler with the help of CLOS?

I thought using hash table would be faster compared to CLOS. Since retrieving configuration is rather primitive, I would like to make it fast.
(It is also possible to provide an alternative implementation...)

@svetlyak40wt So, more than one year later, I finally re-wrote the logic and published v2.0.0 version.

I think the new version resolved your issues. There is currently no way to monitor the slot value change, but I think it is not hard to add given the current design, as long as there is a real-world requirement.

Could you please take a look and close this issue?
Let me know if you have any idea!