Created
April 29, 2011 16:49
-
-
Save vietj/948608 to your computer and use it in GitHub Desktop.
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
@Usage("logging commands") | |
public class log extends CRaSHCommand implements Completer { | |
@Usage("send a message to a logger") | |
@Man("""\ | |
The send command log one or several loggers with a specified message. For instance the following impersonates | |
the javax.management.mbeanserver class and send a message on its own logger. | |
#% log send -m hello javax.management.mbeanserver | |
Send is a <Logger, Void> command, it can log messages to consumed log objects: | |
% log ls | log send -m hello -l warn""") | |
@Command | |
public void send(InvocationContext<Logger, Void> context, @MsgOpt String msg, @LoggerArg LoggerName name, @LevelOpt Level level) throws ScriptException { | |
level = level ?: Level.info; | |
if (context.piped) { | |
context.consume().each() { | |
level.log(it, msg); | |
} | |
} else { | |
if (name != null) { | |
def logger = LoggerFactory.getLogger(name.string); | |
level.log(logger, msg); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment