Fork me on GitHub
#component
<
2019-02-15
>
robertfw00:02:34

Hi there - I have been trying to figure something out and thought I would drop in here to see if anyone had some advice. I have a component, Config, which pulls in configuration from disk and makes it available to several other components. I'd like to use that configuration at system startup to setup logging levels, probably within it's own Logging component so it can cleanly access the config dependency. I'm wondering whether there is a nicer way to have that logging component run early, beyond making it a dependency of all other components - something i'd rather not do as they don't really depend on it

robertfw00:02:50

The other option I was considering was swapping out the current use of SystemMap for a custom component that first starts config, then starts the logging, then starts the remainder of the system

robertfw00:02:14

(right now I'm just calling a setup-logging function from my config component, but I am feeling like there is a better way to keep the two separate

metametadata00:02:27

I'd probably setup logging outside of system-related code. It doesn't even have to be encapsulated in Logging component because there's no start/stop logic needed:

(defn example-system [config-options]
  ; .......... setup logging ..........
  (let [{:keys [host port]} config-options]
    (component/system-map
      :db (new-database host port)
      :scheduler (new-scheduler)
      :app (component/using
             (example-component config-options)
             {:database  :db
              :scheduler :scheduler}))))

robertfw00:02:20

the problem is I need to run that logging setup prior to those other components starting up - by default, some of them are rather spammy in their logging output

metametadata00:02:17

would be a problem if logging is set up when example-system function is called?

metametadata00:02:41

it will ensure the order you need

robertfw00:02:19

Well, my config is pulled in via a component. it gets slurped off the filesystem, some minor transformations, and then made availble to other components as a dependency

robertfw00:02:34

so I need the config component to have been started in order to feed to the logging setup

metametadata00:02:53

ah, right, hm.. in my app the config is pulled explicitly in main function and is then passed as an arg into example-system-like function

robertfw00:02:26

I was poking through component code and I think the most straightforward is going to be a custom System component so I can hardcode that initial initialization order. but for now i'll just slap a function call in my Config component