Skip to content

Commit 9f60516

Browse files
committed
Add Profiles section
1 parent d016ac3 commit 9f60516

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

index.adoc

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,3 +406,49 @@ option keys are supported:
406406
`:env` :: an environment variable to take the var's value from
407407
`:type` :: a data type to coerce the var into (one of: `:str`, `:int`
408408
or `float`)
409+
410+
=== Profiles
411+
412+
A Duct application has some number of active profiles, which are
413+
represented by unqualified keywords. When run via the `--main` flag, an
414+
implicit `:main` profile is added. When run via `(go)` at the REPL, an
415+
implicit `:repl` profile is added.
416+
417+
You can add additional profiles via the `--profiles` argument. Profiles
418+
are an ordered list, with preceding profiles taking priority.
419+
420+
[,shell]
421+
----
422+
$ duct --profiles=:dev --main
423+
----
424+
425+
Most of the modules that Duct provides use profiles to customize their
426+
behavior to the environment they're being run under. We can also use the
427+
`#ig/profile` data reader to create our own profile behavior.
428+
429+
Let's change our component to allow for the log level to be specified.
430+
431+
[,clojure]
432+
----
433+
(ns tutorial.print
434+
(:require [duct.logger :as log]))
435+
436+
(defn hello [{:keys [level logger name]}]
437+
(log/log logger level ::hello {:name name}))
438+
----
439+
440+
In `duct.edn` we can use a profile to change the log level depending
441+
on whether the application uses the `:main` or `:repl` profile.
442+
443+
[,clojure]
444+
----
445+
{:vars
446+
{name {:arg name, :env NAME, :type :str, :default "World"
447+
:doc "The name of the person to greet"}}
448+
:system
449+
{:duct.module/logging {}
450+
:tutorial.print/hello
451+
{:logger #ig/ref :duct/logger
452+
:level #ig/profile {:repl :report, :main :info}
453+
:name #ig/var name}}}
454+
----

0 commit comments

Comments
 (0)