diff --git a/README.md b/README.md index ea3fbf3..04ed21b 100644 --- a/README.md +++ b/README.md @@ -186,6 +186,15 @@ $ gogo-set-log-level com.mycompany.mylogger DEBUG ``` +If is not set the current level of is returned. + +Example: + +``` +$ gogo-set-log-level com.mycompany +Level for com.mycompany: ERROR +``` + #### gogo-reindex-all-search-indexes Reindex all search indexes. diff --git a/gogo-set-log-level b/gogo-set-log-level index 031cf99..2157bdb 100755 --- a/gogo-set-log-level +++ b/gogo-set-log-level @@ -26,9 +26,10 @@ # Further documentation: https://github.com/slemarchand/liferay-gogo-scripts # -if { $argc < 2 } { +if { $argc < 1 } { set command [file tail $argv0] send_user "usage: $command \n" + send_user "If is not set the current level of is returned.\n" exit 1 } @@ -69,7 +70,19 @@ set level [lindex $argv 1]; set groovy_script " \ import static com.liferay.util.log4j.Log4JUtil.setLevel; \ - setLevel('$name','$level',true); \ + import static com.liferay.util.log4j.Log4JUtil.getOriginalLevel; \ + level = '$level'; \ + name = '$name'; \ + if(!level.isEmpty()) { \ + setLevel(name, level, true); \ + println('Level set'); \ + } else { \ + try { \ + println('Level for ' + name + ': ' + getOriginalLevel(name)); \ + } catch(java.lang.Exception ex) { \ + ex.printStackTrace(); \ + } \ + } \ "; send -- " \ @@ -106,4 +119,4 @@ expect { set output [string range $output [string first "\n" $output]+1 [string last "\n" $output]-1] if { $return_code == 0 } { send_user "$output\n" } else { send_error "$output\n" } -exit $return_code \ No newline at end of file +exit $return_code