corrections in debug logger
This commit is contained in:
parent
cab8dae15a
commit
4709ac5f01
|
@ -15,9 +15,16 @@
|
|||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# ____________________________________________________________
|
||||
from logging import getLogger
|
||||
from logging import getLogger, DEBUG, basicConfig, StreamHandler, Formatter
|
||||
import os
|
||||
|
||||
|
||||
log = getLogger('tiramisu')
|
||||
# import logging
|
||||
# logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)
|
||||
if os.environ.get('TIRAMISU_DEBUG') == 'True':
|
||||
log.setLevel(DEBUG)
|
||||
handler = StreamHandler()
|
||||
handler.setLevel(DEBUG)
|
||||
formatter = Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
handler.setFormatter(formatter)
|
||||
|
||||
log.addHandler(handler)
|
||||
|
|
|
@ -32,16 +32,16 @@ class Properties(Cache):
|
|||
|
||||
# properties
|
||||
def setproperties(self, path, properties):
|
||||
log.debug('setproperties', path, properties)
|
||||
log.debug('setproperties %s %s', path, properties)
|
||||
self._properties[path] = properties
|
||||
|
||||
def getproperties(self, path, default_properties):
|
||||
ret = self._properties.get(path, frozenset(default_properties))
|
||||
log.debug('getproperties', path, ret)
|
||||
log.debug('getproperties %s %s', path, ret)
|
||||
return ret
|
||||
|
||||
def delproperties(self, path):
|
||||
log.debug('delproperties', path)
|
||||
log.debug('delproperties %s', path)
|
||||
if path in self._properties:
|
||||
del(self._properties[path])
|
||||
|
||||
|
@ -64,7 +64,7 @@ class Permissives(Cache):
|
|||
super(Permissives, self).__init__(storage)
|
||||
|
||||
def setpermissives(self, path, permissives):
|
||||
log.debug('setpermissives', path, permissives)
|
||||
log.debug('setpermissives %s %s', path, permissives)
|
||||
if not permissives:
|
||||
if path in self._permissives:
|
||||
del self._permissives[path]
|
||||
|
@ -73,7 +73,7 @@ class Permissives(Cache):
|
|||
|
||||
def getpermissives(self, path=None):
|
||||
ret = self._permissives.get(path, frozenset())
|
||||
log.debug('getpermissives', path, ret)
|
||||
log.debug('getpermissives %s %s', path, ret)
|
||||
return ret
|
||||
|
||||
def exportation(self):
|
||||
|
@ -86,6 +86,6 @@ class Permissives(Cache):
|
|||
self._permissives = permissives
|
||||
|
||||
def delpermissive(self, path):
|
||||
log.debug('delpermissive', path)
|
||||
log.debug('delpermissive %s', path)
|
||||
if path in self._permissives:
|
||||
del(self._permissives[path])
|
||||
|
|
|
@ -76,7 +76,7 @@ class Values(Cache):
|
|||
"""set value for a path
|
||||
a specified value must be associated to an owner
|
||||
"""
|
||||
log.debug('setvalue', path, value, owner, index, id(self))
|
||||
log.debug('setvalue %s %s %s %s %s', path, value, owner, index, id(self))
|
||||
values = []
|
||||
vidx = None
|
||||
|
||||
|
@ -97,7 +97,7 @@ class Values(Cache):
|
|||
return: boolean
|
||||
"""
|
||||
has_path = path in self._values[0]
|
||||
log.debug('hasvalue', path, index, has_path, id(self))
|
||||
log.debug('hasvalue %s %s %s %s', path, index, has_path, id(self))
|
||||
if index is None:
|
||||
return has_path
|
||||
elif has_path:
|
||||
|
@ -110,7 +110,7 @@ class Values(Cache):
|
|||
"""
|
||||
_values == ((path1, path2), ((idx1_1, idx1_2), None), ((value1_1, value1_2), value2), ((owner1_1, owner1_2), owner2))
|
||||
"""
|
||||
log.debug('reduce_index', path, index, id(self))
|
||||
log.debug('reduce_index %s %s %s', path, index, id(self))
|
||||
path_idx = self._values[0].index(path)
|
||||
# get the "index" position
|
||||
subidx = self._values[1][path_idx].index(index)
|
||||
|
@ -129,7 +129,7 @@ class Values(Cache):
|
|||
path,
|
||||
index,
|
||||
commit):
|
||||
log.debug('resetvalue_index', path, index, id(self))
|
||||
log.debug('resetvalue_index %s %s %s', path, index, id(self))
|
||||
def _resetvalue(nb):
|
||||
values_idx = list(values[nb])
|
||||
del(values_idx[path_idx])
|
||||
|
@ -163,7 +163,7 @@ class Values(Cache):
|
|||
commit):
|
||||
"""remove value means delete value in storage
|
||||
"""
|
||||
log.debug('resetvalue', path, id(self))
|
||||
log.debug('resetvalue %s %s', path, id(self))
|
||||
def _resetvalue(nb):
|
||||
lst = list(self._values[nb])
|
||||
lst.pop(idx)
|
||||
|
@ -216,7 +216,7 @@ class Values(Cache):
|
|||
with_value)
|
||||
if owner is undefined:
|
||||
owner = default
|
||||
log.debug('getvalue', path, index, value, owner, id(self))
|
||||
log.debug('getvalue %s %s %s %s %s', path, index, value, owner, id(self))
|
||||
if with_value:
|
||||
return owner, value
|
||||
else:
|
||||
|
|
|
@ -81,7 +81,7 @@ class Permissives(Sqlite3DB):
|
|||
# permissive
|
||||
def setpermissives(self, path, permissive):
|
||||
path = self._sqlite_encode_path(path)
|
||||
log.debug('setpermissive', path, permissive, id(self))
|
||||
log.debug('setpermissive %s %s %s', path, permissive, id(self))
|
||||
self._storage.execute("DELETE FROM permissive WHERE path = ? AND session_id = ?",
|
||||
(path, self._session_id),
|
||||
False)
|
||||
|
@ -99,7 +99,7 @@ class Permissives(Sqlite3DB):
|
|||
ret = frozenset()
|
||||
else:
|
||||
ret = frozenset(self._sqlite_decode(permissives[0]))
|
||||
log.debug('getpermissive', path, ret, id(self))
|
||||
log.debug('getpermissive %s %s %s', path, ret, id(self))
|
||||
return ret
|
||||
|
||||
def delpermissive(self, path):
|
||||
|
|
|
@ -54,7 +54,7 @@ class Values(Sqlite3DB):
|
|||
"""set value for an option
|
||||
a specified value must be associated to an owner
|
||||
"""
|
||||
log.debug('setvalue', path, value, owner, index, commit)
|
||||
log.debug('setvalue %s %s %s %s %s', path, value, owner, index, commit)
|
||||
path = self._sqlite_encode_path(path)
|
||||
if index is not None:
|
||||
self.resetvalue_index(path,
|
||||
|
@ -81,7 +81,7 @@ class Values(Sqlite3DB):
|
|||
"""if opt has a value
|
||||
return: boolean
|
||||
"""
|
||||
log.debug('hasvalue', path, index)
|
||||
log.debug('hasvalue %s %s', path, index)
|
||||
path = self._sqlite_encode_path(path)
|
||||
return self._sqlite_select(path, index) is not None
|
||||
|
||||
|
@ -91,7 +91,7 @@ class Values(Sqlite3DB):
|
|||
_values == ((path1, path2), ((idx1_1, idx1_2), None),
|
||||
((value1_1, value1_2), value2), ((owner1_1, owner1_2), owner2))
|
||||
"""
|
||||
log.debug('reduce_index', path, index, id(self))
|
||||
log.debug('reduce_index %s %s %s', path, index, id(self))
|
||||
self._storage.execute("UPDATE value SET idx = ? WHERE path = ? and idx = ? "
|
||||
"AND session_id = ?",
|
||||
(index - 1, path, index, self._session_id))
|
||||
|
@ -102,7 +102,7 @@ class Values(Sqlite3DB):
|
|||
commit=True):
|
||||
"""remove value means delete value in storage
|
||||
"""
|
||||
log.debug('resetvalue_index', path, index, commit)
|
||||
log.debug('resetvalue_index %s %s %s', path, index, commit)
|
||||
path = self._sqlite_encode_path(path)
|
||||
self._storage.execute("DELETE FROM value WHERE path = ? AND session_id = ? AND idx = ?",
|
||||
(path, self._session_id, index),
|
||||
|
@ -113,7 +113,7 @@ class Values(Sqlite3DB):
|
|||
commit):
|
||||
"""remove value means delete value in storage
|
||||
"""
|
||||
log.debug('resetvalue', path, commit)
|
||||
log.debug('resetvalue %s %s', path, commit)
|
||||
path = self._sqlite_encode_path(path)
|
||||
self._storage.execute("DELETE FROM value WHERE path = ? AND session_id = ?",
|
||||
(path, self._session_id),
|
||||
|
@ -126,7 +126,7 @@ class Values(Sqlite3DB):
|
|||
index=None):
|
||||
"""change owner for an option
|
||||
"""
|
||||
log.debug('setowner', path, owner, index)
|
||||
log.debug('setowner %s %s %s', path, owner, index)
|
||||
path = self._sqlite_encode_path(path)
|
||||
if index is None:
|
||||
self._storage.execute("UPDATE value SET owner = ? WHERE path = ? AND session_id = ?",
|
||||
|
@ -143,7 +143,7 @@ class Values(Sqlite3DB):
|
|||
"""get owner for an option
|
||||
return: owner object
|
||||
"""
|
||||
log.debug('getowner', path, default, index, with_value)
|
||||
log.debug('getowner %s %s %s %s', path, default, index, with_value)
|
||||
path = self._sqlite_encode_path(path)
|
||||
request = "SELECT owner, value FROM value WHERE path = ? AND session_id = ?"
|
||||
if index is not None:
|
||||
|
@ -178,7 +178,7 @@ class Values(Sqlite3DB):
|
|||
:param key: information's key (ex: "help", "doc"
|
||||
:param value: information's value (ex: "the help string")
|
||||
"""
|
||||
log.debug('set_information', key, value)
|
||||
log.debug('set_information %s %s', key, value)
|
||||
path = self._sqlite_encode_path(path)
|
||||
self._storage.execute("DELETE FROM information WHERE key = ? AND session_id = ? AND path = ?",
|
||||
(key, self._session_id, path),
|
||||
|
@ -191,7 +191,7 @@ class Values(Sqlite3DB):
|
|||
|
||||
:param key: the item string (ex: "help")
|
||||
"""
|
||||
log.debug('get_information', key, default)
|
||||
log.debug('get_information %s %s', key, default)
|
||||
path = self._sqlite_encode_path(path)
|
||||
value = self._storage.select("SELECT value FROM information WHERE key = ? AND "
|
||||
"session_id = ? AND path = ?",
|
||||
|
@ -205,7 +205,7 @@ class Values(Sqlite3DB):
|
|||
return self._sqlite_decode(value[0])
|
||||
|
||||
def del_information(self, path, key, raises):
|
||||
log.debug('del_information', key, raises)
|
||||
log.debug('del_information %s %s', key, raises)
|
||||
path = self._sqlite_encode_path(path)
|
||||
if raises and self._storage.select("SELECT value FROM information WHERE key = ? "
|
||||
"AND session_id = ? AND path = ?",
|
||||
|
@ -282,7 +282,7 @@ class Values(Sqlite3DB):
|
|||
|
||||
def get_max_length(self,
|
||||
path):
|
||||
log.debug('get_max_length', path)
|
||||
log.debug('get_max_length %s', path)
|
||||
val_max = self._storage.select("SELECT max(idx) FROM value WHERE path = ? AND session_id = ?",
|
||||
(path, self._session_id), False)
|
||||
if val_max[0][0] is None:
|
||||
|
|
|
@ -75,16 +75,16 @@ class Cache(DictCache):
|
|||
'expire' in self_props):
|
||||
ntime = int(time())
|
||||
if timestamp + expiration_time >= ntime:
|
||||
log.debug('getcache in cache (1)', path, value, _display_classname(self),
|
||||
log.debug('getcache in cache (1) %s %s %s %s %s', path, value, _display_classname(self),
|
||||
id(self), index)
|
||||
return True, value
|
||||
#else:
|
||||
# log.debug('getcache expired value for path {} < {}'.format(
|
||||
# timestamp + expiration_time, ntime))
|
||||
# # if expired, remove from cache
|
||||
# #self.delcache(path)
|
||||
else:
|
||||
log.debug('getcache expired value for path {} < {}'.format(
|
||||
timestamp + expiration_time, ntime))
|
||||
# if expired, remove from cache
|
||||
#self.delcache(path)
|
||||
else:
|
||||
log.debug('getcache in cache (2)', path, value, _display_classname(self),
|
||||
log.debug('getcache in cache (2) %s %s %s %s %s', path, value, _display_classname(self),
|
||||
id(self), index)
|
||||
return True, value
|
||||
log.debug('getcache {} with index {} not in {} cache'.format(path, index,
|
||||
|
@ -94,13 +94,13 @@ class Cache(DictCache):
|
|||
def delcache(self, path):
|
||||
"""remove cache for a specified path
|
||||
"""
|
||||
log.debug('delcache', path, _display_classname(self), id(self))
|
||||
log.debug('delcache %s %s %s', path, _display_classname(self), id(self))
|
||||
if path in self._cache:
|
||||
self._delcache(path)
|
||||
|
||||
def reset_all_cache(self):
|
||||
"empty the cache"
|
||||
log.debug('reset_all_cache', _display_classname(self), id(self))
|
||||
log.debug('reset_all_cache %s %s', _display_classname(self), id(self))
|
||||
self._reset_all_cache()
|
||||
|
||||
def get_cached(self):
|
||||
|
|
Loading…
Reference in New Issue