Skip to content

Instantly share code, notes, and snippets.

@vietj
Created April 29, 2011 16:49
Show Gist options
  • Save vietj/948608 to your computer and use it in GitHub Desktop.
Save vietj/948608 to your computer and use it in GitHub Desktop.
@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