Commit fa0036a4 authored by Peter V. Saveliev's avatar Peter V. Saveliev

logging: use specific loggers

Bug-Url: https://github.com/svinota/pyroute2/issues/246
parent d8115182
......@@ -16,6 +16,9 @@ from pyroute2.netlink.exceptions import \
NetlinkError, \
NetlinkDecodeError
logging.basicConfig()
log = logging.getLogger('pyroute2')
# reexport exceptions
exceptions = [NetlinkError,
NetlinkDecodeError,
......@@ -120,8 +123,8 @@ for name in _modules:
class __common(object):
def __getattribute__(self, key):
logging.warning('module pyroute2.ipdb.common is deprecated, '
'use pyroute2.ipdb.exceptions instead')
log.warning('module pyroute2.ipdb.common is deprecated, '
'use pyroute2.ipdb.exceptions instead')
return getattr(globals()['ipdb'].exceptions, key)
globals()['ipdb'].common = __common()
......
......@@ -353,6 +353,9 @@ from pyroute2.ipdb.linkedset import IPaddrSet
from pyroute2.ipdb.exceptions import CreateException
from pyroute2.ipdb.transactional import SYNC_TIMEOUT
logging.basicConfig()
log = logging.getLogger('pyroute2.ipdb.main')
def get_addr_nla(msg):
###
......@@ -431,6 +434,7 @@ class IPDB(object):
self.iclass = Interface
self._nl_async = config.ipdb_nl_async if nl_async is None else True
self._stop = False
log.warning("started")
# see also 'register_callback'
self._post_callbacks = {}
self._pre_callbacks = {}
......@@ -499,8 +503,8 @@ class IPDB(object):
for msg in self.nl.get_routes(family=AF_MPLS):
self._route_add(msg)
except Exception as e:
logging.error('initdb error: %s', e)
logging.error(traceback.format_exc())
log.error('initdb error: %s', e)
log.error(traceback.format_exc())
try:
self.nl.close()
self.mnl.close()
......@@ -975,14 +979,14 @@ class IPDB(object):
if self._stop:
break
except:
logging.error('Restarting IPDB instance after '
'error:\n%s', traceback.format_exc())
log.error('Restarting IPDB instance after '
'error:\n%s', traceback.format_exc())
if self.restart_on_error:
try:
self.initdb()
except:
logging.error('Error restarting DB:\n%s',
traceback.format_exc())
log.error('Error restarting DB:\n%s',
traceback.format_exc())
return
continue
else:
......
......@@ -17,6 +17,9 @@ from pyroute2.ipdb.transactional import Transactional
from pyroute2.ipdb.transactional import with_transaction
from pyroute2.ipdb.linkedset import LinkedSet
logging.basicConfig()
log = logging.getLogger('pyroute2.ipdb.route')
class Metrics(Transactional):
_fields = [rtmsg.metrics.nla2name(i[0]) for i in rtmsg.metrics.nla_map]
......@@ -844,8 +847,8 @@ class RoutingTableSet(object):
with record._direct_state:
record['ipdb_scope'] = 'detached'
except Exception as e:
logging.debug(e)
logging.debug(msg)
log.debug(e)
log.debug(msg)
return
# RTM_NEWROUTE
......
......@@ -123,6 +123,8 @@ from pyroute2.common import getbroadcast
from pyroute2.netlink.exceptions import NetlinkError
DEFAULT_TABLE = 254
logging.basicConfig()
log = logging.getLogger('pyroute2.iproute')
def transform_handle(handle):
......@@ -271,8 +273,8 @@ class IPRouteMixin(object):
'''
Alias of `get_neighbours()`, deprecated.
'''
logging.warning('The `get_neighbors()` call is deprecated')
logging.warning('Use `get_neighbours() instead')
log.warning('The `get_neighbors()` call is deprecated')
log.warning('Use `get_neighbours() instead')
return self.get_neighbours(family)
def get_neighbours(self, family=AF_UNSPEC, match=None, **kwarg):
......@@ -402,35 +404,35 @@ class IPRouteMixin(object):
# Create interface
#
# Obsoleted method. Use `link("add", ...)` instead.
logging.warning("link_create() is obsoleted, use link('add', ...)")
log.warning("link_create() is obsoleted, use link('add', ...)")
return self.link('add', **IPLinkRequest(kwarg))
def link_up(self, index):
# Link up.
#
# Obsoleted method. Use `link("set", ...)` instead.
logging.warning("link_up() is obsoleted, use link('set', ...)")
log.warning("link_up() is obsoleted, use link('set', ...)")
return self.link('set', index=index, state='up')
def link_down(self, index):
# Link up.
#
# Obsoleted method. Use `link("set", ...)` instead.
logging.warning("link_down() is obsoleted, use link('set', ...)")
log.warning("link_down() is obsoleted, use link('set', ...)")
return self.link('set', index=index, state='down')
def link_rename(self, index, name):
# Rename interface.
#
# Obsoleted method. Use `link("set", ...)` instead.
logging.warning("link_rename() is obsoleted, use link('set', ...)")
log.warning("link_rename() is obsoleted, use link('set', ...)")
return self.link('set', index=index, ifname=name)
def link_remove(self, index):
# Remove interface.
#
# Obsoleted method. Use `link("del", ...)` instead.
logging.warning("link_remove() is obsoleted, use link('del', ...)")
log.warning("link_remove() is obsoleted, use link('del', ...)")
return self.link('del', index=index)
def link_lookup(self, **kwarg):
......@@ -1032,8 +1034,8 @@ class IPRouteMixin(object):
'''
if command[:4] == 'vlan':
logging.warning('vlan filters are managed via `vlan_filter()`')
logging.warning('this compatibility hack will be removed soon')
log.warning('vlan filters are managed via `vlan_filter()`')
log.warning('this compatibility hack will be removed soon')
return self.vlan_filter(command[5:], **kwarg)
flags_dump = NLM_F_REQUEST | NLM_F_DUMP
......@@ -1590,7 +1592,7 @@ class IPRouteMixin(object):
if argv:
# this code block will be removed in some release
logging.warning('rule(): positional parameters are deprecated')
log.warning('rule(): positional parameters are deprecated')
names = ['table', 'priority', 'action', 'family',
'src', 'src_len', 'dst', 'dst_len', 'fwmark',
'iifname', 'oifname']
......
......@@ -408,6 +408,8 @@ from pyroute2.netlink.exceptions import NetlinkHeaderDecodeError
from pyroute2.netlink.exceptions import NetlinkDataDecodeError
from pyroute2.netlink.exceptions import NetlinkNLADecodeError
logging.basicConfig()
log = logging.getLogger('pyroute2.netlink.parser')
# make pep8 happy
_ne = NetlinkError # reexport for compatibility
_de = NetlinkDecodeError #
......@@ -673,8 +675,8 @@ class nlmsg_base(dict):
try:
cb()
except:
logging.error('Cleanup callback fail: %s' % (cb))
logging.error(traceback.format_exc())
log.error('Cleanup callback fail: %s' % (cb))
log.error(traceback.format_exc())
del clean_cbs[seq]
def _strip_one(self, name):
......@@ -914,7 +916,7 @@ class nlmsg_base(dict):
self.buf.seek(self.msg_align(self.buf.tell()))
self.decode_nlas()
except Exception as e:
logging.warning(traceback.format_exc())
log.warning(traceback.format_exc())
raise NetlinkNLADecodeError(e)
if len(self['attrs']) == 0:
del self['attrs']
......@@ -985,10 +987,10 @@ class nlmsg_base(dict):
else:
payload += struct.pack(fmt, value)
except struct.error:
logging.error(''.join(traceback.format_stack()))
logging.error(traceback.format_exc())
logging.error("error pack: %s %s %s" %
(fmt, value, type(value)))
log.error(''.join(traceback.format_stack()))
log.error(traceback.format_exc())
log.error("error pack: %s %s %s" %
(fmt, value, type(value)))
raise
diff = self.msg_align(len(payload)) - len(payload)
......@@ -1259,8 +1261,8 @@ class nlmsg_base(dict):
NLA_F_NET_BYTEORDER)
msg_name = prime['name']
except Exception:
logging.warning("decoding %s" % (prime['name']))
logging.warning(traceback.format_exc())
log.warning("decoding %s" % (prime['name']))
log.warning(traceback.format_exc())
self.buf.seek(init)
msg_name = 'UNDECODED'
msg_value = hexdump(self.buf.read(length))
......
......@@ -117,6 +117,9 @@ try:
except ImportError:
from queue import Queue
logging.basicConfig()
log = logging.getLogger('pyroute2.netlink.nlsocket')
class Marshal(object):
'''
......@@ -341,8 +344,8 @@ class NetlinkMixin(object):
self.close()
def release(self):
logging.warning("The `release()` call is deprecated")
logging.warning("Use `close()` instead")
log.warning("The `release()` call is deprecated")
log.warning("Use `close()` instead")
self.close()
def register_callback(self, callback,
......@@ -694,9 +697,9 @@ class NetlinkMixin(object):
"delta=%s qsize=%s delay=%s "
% (delta, current, delay))
if delay < 1:
logging.debug(message)
log.debug(message)
else:
logging.warning(message)
log.warning(message)
time.sleep(delay)
self.qsize = current
......@@ -716,8 +719,8 @@ class NetlinkMixin(object):
if cr[0](msg):
cr[1](msg, *cr[2])
except:
logging.warning("Callback fail: %s" % (cr))
logging.warning(traceback.format_exc())
log.warning("Callback fail: %s" % (cr))
log.warning(traceback.format_exc())
# 8<-----------------------------------------------
self.backlog[seq].append(msg)
# We finished with the backlog, so release the lock
......
......@@ -2,13 +2,16 @@ import re
import os
import struct
import logging
from math import log
from math import log as logfm
from pyroute2.common import size_suffixes
from pyroute2.common import time_suffixes
from pyroute2.common import rate_suffixes
from pyroute2.common import basestring
from pyroute2.netlink import nla
logging.basicConfig()
log = logging.getLogger('pyroute2.netlink.rtnl.tcmsg')
LINKLAYER_UNSPEC = 0
LINKLAYER_ETHERNET = 1
LINKLAYER_ATM = 2
......@@ -28,8 +31,8 @@ try:
clock_factor = float(clock_res) / TIME_UNITS_PER_SEC
tick_in_usec = float(t2us) / us2t * clock_factor
except IOError as e:
logging.warning("tcmsg: %s", e)
logging.warning("the tc subsystem functionality is limited")
log.warning("tcmsg: %s", e)
log.warning("the tc subsystem functionality is limited")
clock_res = 0
clock_factor = 1
tick_in_usec = 1
......@@ -124,7 +127,7 @@ def red_eval_P(qmin, qmax, probability):
def red_eval_idle_damping(Wlog, avpkt, bps):
# The code is ported from tc utility
xmit_time = calc_xmittime(bps, avpkt)
lW = -log(1.0 - 1.0 / (1 << Wlog)) / xmit_time
lW = -logfm(1.0 - 1.0 / (1 << Wlog)) / xmit_time
maxtime = 31.0 / lW
sbuf = []
for clog in range(32):
......
......@@ -32,6 +32,8 @@ from pyroute2.netlink.rtnl.tcmsg.common import red_eval_P
from pyroute2.netlink.rtnl.tcmsg.common import red_eval_idle_damping
from pyroute2.netlink.rtnl.tcmsg.common import stats2 as c_stats2
logging.basicConfig()
log = logging.getLogger('pyroute2.netlink.rtnl.tcmsg')
parent = TC_H_ROOT
......@@ -71,7 +73,7 @@ def get_parameters(kwarg):
if opt['Wlog'] < 0:
raise Exception('failed to calculate EWMA')
elif opt['Wlog'] > 10:
logging.warning('choke: burst %s seems to be too large' % burst)
log.warning('choke: burst %s seems to be too large' % burst)
# Plog
opt['Plog'] = red_eval_P(opt['qth_min']*avpkt,
opt['qth_max']*avpkt,
......
......@@ -4,6 +4,8 @@ from pyroute2.netlink.rtnl import TC_H_ROOT
from pyroute2.netlink.rtnl.tcmsg.common import get_time
from pyroute2.netlink.rtnl.tcmsg.common import stats2 as c_stats2
logging.basicConfig()
log = logging.getLogger('pyroute2.netlink.rtnl.tcmsg')
parent = TC_H_ROOT
......@@ -21,8 +23,8 @@ def get_parameters(kwarg):
'cdl_interval': get_time}
for key in transform.keys():
if key in kwarg:
logging.warning('codel parameters naming will be changed '
'in next releases (%s)' % key)
log.warning('codel parameters naming will be changed '
'in next releases (%s)' % key)
ret['attrs'].append(['TCA_CODEL_%s' % key[4:].upper(),
transform[key](kwarg[key])])
return ret
......
......@@ -5,6 +5,8 @@ from pyroute2.netlink.rtnl import TC_H_ROOT
from pyroute2.netlink.rtnl.tcmsg import common
from pyroute2.netlink.rtnl.tcmsg.common import get_time
logging.basicConfig()
log = logging.getLogger('pyroute2.netlink.rtnl.tcmsg')
parent = TC_H_ROOT
......@@ -24,8 +26,8 @@ def get_parameters(kwarg):
'fqc_interval': get_time}
for key in transform.keys():
if key in kwarg:
logging.warning('fq_codel parameters naming will be changed '
'in next releases (%s)' % key)
log.warning('fq_codel parameters naming will be changed '
'in next releases (%s)' % key)
ret['attrs'].append(['TCA_FQ_CODEL_%s' % key[4:].upper(),
transform[key](kwarg[key])])
return ret
......
......@@ -78,6 +78,9 @@ from pyroute2.netns import remove
from pyroute2.remote import Server
from pyroute2.remote import RemoteSocket
logging.basicConfig()
log = logging.getLogger('pyroute2.netns')
def NetNServer(netns, cmdch, brdch, flags=os.O_CREAT):
'''
......@@ -199,7 +202,7 @@ class NetNS(IPRouteMixin, RemoteSocket):
except:
# something went wrong, force server shutdown
self.cmdch.send({'stage': 'shutdown'})
logging.error('forced shutdown procedure, clean up netns manually')
log.error('forced shutdown procedure, clean up netns manually')
# force cleanup command channels
self.cmdch.close()
self.brdch.close()
......
......@@ -8,6 +8,9 @@ import traceback
import threading
from pyroute2.netlink.exceptions import NetlinkError
logging.basicConfig()
log = logging.getLogger('pyroute2.proxy')
class NetlinkProxy(object):
'''
......@@ -49,8 +52,8 @@ class NetlinkProxy(object):
return ret
except Exception as e:
logging.error(''.join(traceback.format_stack()))
logging.error(traceback.format_exc())
log.error(''.join(traceback.format_stack()))
log.error(traceback.format_exc())
# errmsg
if isinstance(e, (OSError, IOError)):
code = e.errno
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment