代码之家  ›  专栏  ›  技术社区  ›  Asur

clojure:boot不显示日志

  •  0
  • Asur  · 技术社区  · 8 年前

    我正在为我的业余爱好项目写一些clojure。现在,我正在实现用于迁移SQL文件的引导任务。

    我有以下处理迁移的代码。

    ; when executed from repl logs whatever printed by println
    (defn migrate-pending [config]
      (if (migration-table-exists? config)
        (for [to-migrate (get-pending-migrations config)]
          (migrate to-migrate config))
        (create-migration-table config)))
    
    ; this consumes the log
    (core/deftask migrate
      "Migrate up"
      []
      (migrate-pending pg-uri))
    

    migrate 函数只打印它得到的值。 boot 似乎消耗了日志,但当执行到 repl 它打印日志。

    这是预期的吗?

    2 回复  |  直到 8 年前
        1
  •  1
  •   Chris Murphy    8 年前

    你不应该做一些有副作用的事情 for ,它“生成一个延迟的expr计算序列”。你应该用 doseq .

    比编写打印内容的函数更好的是编写返回内容的函数。

        2
  •  1
  •   Eyal    8 年前

    你也可以试着用Dorun函数包装,它会增加任何副作用。

    clojure docs - dorun

    推荐文章