Signed-off-by: YAMAMOTO Takashi <[email protected]>
---
bin/ryu-manager | 1 +
ryu/app/cli.py | 36 ++++++++++++++++++++++++++++++++++++
ryu/logger.py | 31 +++++++++++++++++++++++++++++++
3 files changed, 68 insertions(+)
create mode 100644 ryu/logger.py
diff --git a/bin/ryu-manager b/bin/ryu-manager
index 03b1b79..18a38d6 100755
--- a/bin/ryu-manager
+++ b/bin/ryu-manager
@@ -33,6 +33,7 @@ from oslo.config import cfg
import logging
import sys
+import ryu.logger
from ryu import log
log.early_init_log(logging.DEBUG)
diff --git a/ryu/app/cli.py b/ryu/app/cli.py
index 3870d76..75dbdba 100644
--- a/ryu/app/cli.py
+++ b/ryu/app/cli.py
@@ -39,6 +39,28 @@ CONF.register_opts([
class CliHandler(TelnetHandler):
PROMPT = 'ryu-manager %s> ' % version
+ @command('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]
+ newlvl = int(params[1])
+ except (ValueError, IndexError):
+ self.writeerror('invalid parameter')
+ return
+ if not name in ryu.logger.RyuLogger.loggers:
+ self.writeerror('logger %s is unknown' % (name,))
+ return
+ logger = logging.getLogger(name)
+ oldlvl = logger.getEffectiveLevel()
+ logger.setLevel(newlvl)
+ self.writeresponse('logger %s level %s -> %s' %
+ (name, oldlvl, newlvl))
+
@command('show-bricks')
def command_show_bricks(self, params):
'''
@@ -48,6 +70,20 @@ class CliHandler(TelnetHandler):
for b, x in SERVICE_BRICKS.iteritems():
self.writeresponse('%s' % (b,))
+ @command('show-loggers')
+ def command_show_loggers(self, params):
+ '''
+ show loggers
+ '''
+ import logging
+ import ryu.logger
+
+ def show_logger(name):
+ logger = logging.getLogger(name)
+ self.writeresponse('logger %s level %s' %
+ (name, logger.getEffectiveLevel()))
+ map(show_logger, ryu.logger.RyuLogger.loggers)
+
@command('show-options')
def command_show_options(self, params):
'''
diff --git a/ryu/logger.py b/ryu/logger.py
new file mode 100644
index 0000000..2e2aa91
--- /dev/null
+++ b/ryu/logger.py
@@ -0,0 +1,31 @@
+# Copyright (C) 2013 Nippon Telegraph and Telephone Corporation.
+# Copyright (C) 2013 YAMAMOTO Takashi <yamamoto at valinux co jp>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import logging
+
+
+class RyuLogger(logging.getLoggerClass()):
+ loggers = set()
+
+ def __init__(self, name):
+ try:
+ super(RyuLogger, self).__init__(name)
+ except TypeError:
+ # probably our super class is old-type
+ logging.Logger.__init__(self, name)
+ RyuLogger.loggers.add(name)
+
+logging.setLoggerClass(RyuLogger)
--
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