Question

How can I use different log4j properties files based on leiningen test metadata? I have functions that have debug logging output to a file. Often, there is a lot of data being written to this debug log file, slowing down the function. Normal runs of the application will not have debug file writing, so I want to benchmark the normal running of the function without that file writing. For benchmarking, I am using criterium. Let's assume that the metadata for benchmarking deftest defitions is :benchmark.

Était-ce utile?

La solution

The trouble with doing this based on test metadata is that all tests are run in a single JVM instance, and modifying the Log4j configuration on the fly within a JVM is not exactly easy. Instead, I would set up profiles in your project.clj to disable the :benchmark tests by default, and set up a separate profile for running benchmarks. Assuming that you have your :resource-paths set up to include a debug-level log4j.properties file, your benchmark profile could then set up the classpath or system profiles as appropriate to use a different file. For example:

(defproject myproject
  ...
  :test-selectors {:default (complement :benchmark)}
  :profiles {
    :benchmark {
      :test-selectors {:default :benchmark}
      :jvm-opts ["-Dlog4j.configuration=log4j-benchmark.properties"]
    }
  })

You could then run the benchmarks with:

 > lein with-profile +benchmark test
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top