duct

smnplk 2022-03-29T03:38:02.999359Z

Hi guys, new user of Duct here, I am going over the example app on duct github wiki page. Now if I want to disable default logger and use timbre. I can just put this under :duct.profile/base key:

2022-03-29T04:15:53.302859Z

IIRC the default logger is timbre https://github.com/duct-framework/module.logging/blob/master/src/duct/module/logging.clj

smnplk 2022-03-29T04:58:39.553209Z

Ah I see. But I am still having trouble getting the logger reference from integrant.

smnplk 2022-03-29T05:00:31.881799Z

(defmethod ig/init-key ::create [_ {:keys [db logger]}]
  (fn [{[_ email password] :ataraxy/result}]
    (let [id (create-user db email password)]
      (println logger)
      (log logger :info ::create {:email email})
      [::response/created (str "/users/" id)])))

smnplk 2022-03-29T05:05:30.640219Z

logger has this value: 

smnplk 2022-03-29T05:06:01.871479Z

{:enabled? true, :fn #function[taoensso.timbre.appenders.core/spit-appender/self--15048]}

smnplk 2022-03-29T05:11:10.409709Z

I was passing the wrong key, :duct.logger/timbre is the correct one

2022-03-29T05:44:59.946939Z

You can reference it by :duct/logger. https://github.com/duct-framework/logger.timbre/blob/master/src/duct_hierarchy.edn :duct.logger/timbre implements the :duct/logger interface.

smnplk 2022-04-19T04:38:12.867289Z

👍 clear and thanks.

👍 1
smnplk 2022-03-29T03:38:49.666129Z

:duct.logger/timbre 
{:level :info
 :appenders {:spit #ig/ref :duct.logger.timbre/spit}}

:duct.logger.timbre/spit {:fname "logs/server.log"}

smnplk 2022-03-29T03:41:16.965649Z

And then in the create user handler key i need to reference :duct.logger/timbre

:todo.handler.users/create
  {:db #ig/ref :duct.database/sql
   :logger #ig/ref :duct.logger/timbre}

smnplk 2022-03-29T03:44:27.284179Z

And then in the init-key multimethod for my todo.handlers.users/create i can just reference the passed logger like this

smnplk 2022-03-29T03:44:44.509059Z

(defmethod ig/init-key ::create [_ {:keys [db logger]}]
  (fn [{[_ email password] :ataraxy/result}]
    (let [id (create-user db email password)]
      (log logger :info ::create {:email email})
      [::response/created (str "/users/" id)])))

smnplk 2022-03-29T03:45:46.081659Z

Then I can just remove the :duct.module/logging key from the config. Am I doing this right? It does work.