Signed-off-by: YAMAMOTO Takashi <[email protected]>
---
ryu/app/cli.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 49 insertions(+), 6 deletions(-)
diff --git a/ryu/app/cli.py b/ryu/app/cli.py
index 75dbdba..e056093 100644
--- a/ryu/app/cli.py
+++ b/ryu/app/cli.py
@@ -19,6 +19,7 @@
import gevent
import gevent.server
+import logging
from oslo.config import cfg
@@ -36,15 +37,58 @@ CONF.register_opts([
])
+class PrefixedLogger(object):
+ def __init__(self, logger, prefix):
+ self.logger = logger
+ self.prefix = prefix
+
+ def __getattr__(self, name):
+ basemethod = getattr(self.logger, name)
+ if not name in ['debug', 'info', 'warn', 'error', 'critical']:
+ raise AttributeError
+
+ def method(msg, *args, **kwargs):
+ return basemethod("%s %s" % (self.prefix, msg), *args, **kwargs)
+ return method
+
+
+def command_log(*args, **kwargs):
+ def _log(f):
+ # XXX see the implementation of @command for command_name and __doc
+ def wrapper(self, params):
+ self.logger.info("command %s %s" % (wrapper.command_name, params))
+ f(self, params)
+ wrapper.__doc__ = f.__doc__
+ return wrapper
+ return lambda f: command(*args, **kwargs)(_log(f))
+
+
class CliHandler(TelnetHandler):
PROMPT = 'ryu-manager %s> ' % version
- @command('set-log-level')
+ def __init__(self, request, client_address, server):
+ self.client_address = client_address
+ logger = logging.getLogger("ryu.app.Cli")
+ plogger = PrefixedLogger(logger, "CLI %s" % (client_address,))
+ self.logger = plogger # for us
+ self.logging = plogger # for TelnetHandler
+ TelnetHandler.__init__(self, request, client_address, server)
+
+ def session_start(self):
+ self.logger.info("session start")
+
+ def session_end(self):
+ # XXX due to a bug in telnetsrv 0.4, this isn't called on
+ # a forcible disconnect.
+ # see https://github.com/yamt/telnetsrvlib/tree/fix-disconnect
+ # for a fix.
+ self.logger.info("session end")
+
+ @command_log('set-log-level')
def command_set_log_level(self, params):
'''<logger> <level>
set log level of the specified logger
'''
- import logging
import ryu.logger
try:
name = params[0]
@@ -61,7 +105,7 @@ class CliHandler(TelnetHandler):
self.writeresponse('logger %s level %s -> %s' %
(name, oldlvl, newlvl))
- @command('show-bricks')
+ @command_log('show-bricks')
def command_show_bricks(self, params):
'''
show a list of configured bricks
@@ -70,12 +114,11 @@ class CliHandler(TelnetHandler):
for b, x in SERVICE_BRICKS.iteritems():
self.writeresponse('%s' % (b,))
- @command('show-loggers')
+ @command_log('show-loggers')
def command_show_loggers(self, params):
'''
show loggers
'''
- import logging
import ryu.logger
def show_logger(name):
@@ -84,7 +127,7 @@ class CliHandler(TelnetHandler):
(name, logger.getEffectiveLevel()))
map(show_logger, ryu.logger.RyuLogger.loggers)
- @command('show-options')
+ @command_log('show-options')
def command_show_options(self, params):
'''
show options
--
1.7.12
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel