##// END OF EJS Templates
blackbox: pass in options to _openlogfile() as arguments...
Yuya Nishihara -
r40829:644adf9c default
parent child Browse files
Show More
@@ -89,7 +89,7 b" configitem('blackbox', 'date-format',"
89 default='%Y/%m/%d %H:%M:%S',
89 default='%Y/%m/%d %H:%M:%S',
90 )
90 )
91
91
92 def _openlogfile(ui, vfs):
92 def _openlogfile(ui, vfs, name, maxfiles=0, maxsize=0):
93 def rotate(oldpath, newpath):
93 def rotate(oldpath, newpath):
94 try:
94 try:
95 vfs.unlink(newpath)
95 vfs.unlink(newpath)
@@ -105,8 +105,6 b' def _openlogfile(ui, vfs):'
105 ui.debug("warning: cannot rename '%s' to '%s': %s\n" %
105 ui.debug("warning: cannot rename '%s' to '%s': %s\n" %
106 (newpath, oldpath, err.strerror))
106 (newpath, oldpath, err.strerror))
107
107
108 maxsize = ui.configbytes('blackbox', 'maxsize')
109 name = 'blackbox.log'
110 if maxsize > 0:
108 if maxsize > 0:
111 try:
109 try:
112 st = vfs.stat(name)
110 st = vfs.stat(name)
@@ -115,7 +113,6 b' def _openlogfile(ui, vfs):'
115 else:
113 else:
116 if st.st_size >= maxsize:
114 if st.st_size >= maxsize:
117 path = vfs.join(name)
115 path = vfs.join(name)
118 maxfiles = ui.configint('blackbox', 'maxfiles')
119 for i in pycompat.xrange(maxfiles - 1, 1, -1):
116 for i in pycompat.xrange(maxfiles - 1, 1, -1):
120 rotate(oldpath='%s.%d' % (path, i - 1),
117 rotate(oldpath='%s.%d' % (path, i - 1),
121 newpath='%s.%d' % (path, i))
118 newpath='%s.%d' % (path, i))
@@ -142,6 +139,8 b' class blackboxlogger(object):'
142 def __init__(self, ui, repo):
139 def __init__(self, ui, repo):
143 self._repo = repo
140 self._repo = repo
144 self._trackedevents = set(ui.configlist('blackbox', 'track'))
141 self._trackedevents = set(ui.configlist('blackbox', 'track'))
142 self._maxfiles = ui.configint('blackbox', 'maxfiles')
143 self._maxsize = ui.configbytes('blackbox', 'maxsize')
145
144
146 def tracked(self, event):
145 def tracked(self, event):
147 return b'*' in self._trackedevents or event in self._trackedevents
146 return b'*' in self._trackedevents or event in self._trackedevents
@@ -166,7 +165,9 b' class blackboxlogger(object):'
166 try:
165 try:
167 fmt = '%s %s @%s%s (%s)%s> %s'
166 fmt = '%s %s @%s%s (%s)%s> %s'
168 args = (date, user, rev, changed, pid, src, msg)
167 args = (date, user, rev, changed, pid, src, msg)
169 with _openlogfile(ui, self._repo.vfs) as fp:
168 with _openlogfile(ui, self._repo.vfs, name='blackbox.log',
169 maxfiles=self._maxfiles,
170 maxsize=self._maxsize) as fp:
170 fp.write(fmt % args)
171 fp.write(fmt % args)
171 except (IOError, OSError) as err:
172 except (IOError, OSError) as err:
172 # deactivate this to avoid failed logging again
173 # deactivate this to avoid failed logging again
General Comments 0
You need to be logged in to leave comments. Login now