-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
66 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// END_HELP | ||
import java.util.logging.* | ||
import org.jline.utils.* | ||
import org.jline.builtins.Options | ||
|
||
class Trace { | ||
|
||
static def set(def args) { | ||
String[] usage = [ | ||
"trace - set JLine REPL console trace level", | ||
"Usage: trace [LEVEL]", | ||
" -? --help Displays command help" | ||
] | ||
Options opt = Options.compile(usage).parse(args) | ||
if (opt.isSet("help")) { | ||
throw new Options.HelpException(opt.usage()) | ||
} | ||
def logger = LogManager.getLogManager().getLogger("") | ||
def console = org.jline.builtins.SystemRegistry.get().consoleEngine() | ||
def out | ||
def CONSOLE_OPTIONS = console.getVariable('CONSOLE_OPTIONS'); | ||
def handlers = logger.getHandlers() | ||
if (!opt.args() || !opt.args().get(0).isInteger()) { | ||
out = [:] | ||
out['CONSOLE_OPTIONS.trace'] = CONSOLE_OPTIONS.trace | ||
int i = 0 | ||
for (def h : handlers) { | ||
out['Log.handler' + i++] = h | ||
} | ||
} else { | ||
def level = opt.args().get(0).toInteger() | ||
if (!handlers) { | ||
def handler = new ConsoleHandler() | ||
System.setProperty("java.util.logging.SimpleFormatter.format",'%5$s%n') | ||
SimpleFormatter formatter = new SimpleFormatter() | ||
handler.setFormatter(formatter) | ||
logger.addHandler(handler) | ||
handlers = logger.getHandlers() | ||
} | ||
def tl = Level.OFF | ||
CONSOLE_OPTIONS.trace = level | ||
if (level == 2) { | ||
tl = Level.FINE | ||
} else if (level > 2) { | ||
tl = Level.ALL | ||
} | ||
console.putVariable('CONSOLE_OPTIONS', CONSOLE_OPTIONS) | ||
logger.setLevel(tl) | ||
handlers.each { it.setLevel(tl) } | ||
} | ||
out | ||
} | ||
} | ||
|
||
def static main(def _args){ | ||
Trace.set(_args) | ||
} |