Filed under: Best Practices, Core Updates
Comments: None
This is a handy function for setting the log level dynamically in a running console. I think the original inspiration for this came from Rob Duda – thanks Rob!
Often you want to see more information, or less noise, in your running console during local development. This function is a great way to get there without having to restart your server. We will likely include this in our core libraries in a future release. For the time being, you can simply include it in your scratchpads or create a library (e.g. ed.scm in Resources/Libraries) of helpful functions like this one in your project. You can even load your “personal” library functions by putting something like "(load \"<script_location>")" -
in the program arguments of your scheme console settings at Window/Prefrences/NexJ Studio/Launch Settings/Scheme Console Settings/Server Console/Program Arguments
e.g. “(load \”c:/work/utils/ed.scm\”) – [I beleive the hyphen is needed to force the load]
Here is the function definition.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
; Set the log level in a running console ; ; @arg level integer Log level from 0 (warn) to 3 (all) ; @ret any (define (setLogLevel level) (import '(org.apache.log4j.Logger)) (import '(org.apache.log4j.Level)) ((org.apache.log4j.Logger'rootLogger)'level (org.apache.log4j.Level (case level ((0) 'WARN) ((1) 'INFO) ((2) 'DEBUG) ((3) 'ALL) ('else 'INFO) ) ) ) ) |
To use it just run
(setLogLevel 2) ; this will turn on debug level logging
Enjoy!