component

robertfw 2019-02-15T00:10:34.004200Z

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

robertfw 2019-02-15T00:23:50.005100Z

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

robertfw 2019-02-15T00:30:14.006900Z

(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

metametadata 2019-02-15T00:30:27.007300Z

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}))))

robertfw 2019-02-15T00:31:20.008100Z

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

metametadata 2019-02-15T00:32:17.008900Z

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

metametadata 2019-02-15T00:32:41.009400Z

it will ensure the order you need

robertfw 2019-02-15T00:33:19.010100Z

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

robertfw 2019-02-15T00:33:34.010500Z

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

metametadata 2019-02-15T00:35:53.012400Z

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

robertfw 2019-02-15T00:37:26.014Z

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