##// 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 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 93 def rotate(oldpath, newpath):
94 94 try:
95 95 vfs.unlink(newpath)
@@ -105,8 +105,6 b' def _openlogfile(ui, vfs):'
105 105 ui.debug("warning: cannot rename '%s' to '%s': %s\n" %
106 106 (newpath, oldpath, err.strerror))
107 107
108 maxsize = ui.configbytes('blackbox', 'maxsize')
109 name = 'blackbox.log'
110 108 if maxsize > 0:
111 109 try:
112 110 st = vfs.stat(name)
@@ -115,7 +113,6 b' def _openlogfile(ui, vfs):'
115 113 else:
116 114 if st.st_size >= maxsize:
117 115 path = vfs.join(name)
118 maxfiles = ui.configint('blackbox', 'maxfiles')
119 116 for i in pycompat.xrange(maxfiles - 1, 1, -1):
120 117 rotate(oldpath='%s.%d' % (path, i - 1),
121 118 newpath='%s.%d' % (path, i))
@@ -142,6 +139,8 b' class blackboxlogger(object):'
142 139 def __init__(self, ui, repo):
143 140 self._repo = repo
144 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 145 def tracked(self, event):
147 146 return b'*' in self._trackedevents or event in self._trackedevents
@@ -166,7 +165,9 b' class blackboxlogger(object):'
166 165 try:
167 166 fmt = '%s %s @%s%s (%s)%s> %s'
168 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 171 fp.write(fmt % args)
171 172 except (IOError, OSError) as err:
172 173 # deactivate this to avoid failed logging again
General Comments 0
You need to be logged in to leave comments. Login now