##// END OF EJS Templates
blackbox: move _openlogfile to a separate method...
Jun Wu -
r34301:e6723c93 default
parent child Browse files
Show More
@@ -73,6 +73,40 b" configitem('blackbox', 'logsource',"
73
73
74 lastui = None
74 lastui = None
75
75
76 def _openlogfile(ui, vfs):
77 def rotate(oldpath, newpath):
78 try:
79 vfs.unlink(newpath)
80 except OSError as err:
81 if err.errno != errno.ENOENT:
82 ui.debug("warning: cannot remove '%s': %s\n" %
83 (newpath, err.strerror))
84 try:
85 if newpath:
86 vfs.rename(oldpath, newpath)
87 except OSError as err:
88 if err.errno != errno.ENOENT:
89 ui.debug("warning: cannot rename '%s' to '%s': %s\n" %
90 (newpath, oldpath, err.strerror))
91
92 maxsize = ui.configbytes('blackbox', 'maxsize')
93 name = 'blackbox.log'
94 if maxsize > 0:
95 try:
96 st = vfs.stat(name)
97 except OSError:
98 pass
99 else:
100 if st.st_size >= maxsize:
101 path = vfs.join(name)
102 maxfiles = ui.configint('blackbox', 'maxfiles', 7)
103 for i in xrange(maxfiles - 1, 1, -1):
104 rotate(oldpath='%s.%d' % (path, i - 1),
105 newpath='%s.%d' % (path, i))
106 rotate(oldpath=path,
107 newpath=maxfiles > 0 and path + '.1')
108 return vfs(name, 'a')
109
76 def wrapui(ui):
110 def wrapui(ui):
77 class blackboxui(ui.__class__):
111 class blackboxui(ui.__class__):
78 @property
112 @property
@@ -89,40 +123,6 b' def wrapui(ui):'
89 def track(self):
123 def track(self):
90 return self.configlist('blackbox', 'track', ['*'])
124 return self.configlist('blackbox', 'track', ['*'])
91
125
92 def _openlogfile(self):
93 def rotate(oldpath, newpath):
94 try:
95 self._bbvfs.unlink(newpath)
96 except OSError as err:
97 if err.errno != errno.ENOENT:
98 self.debug("warning: cannot remove '%s': %s\n" %
99 (newpath, err.strerror))
100 try:
101 if newpath:
102 self._bbvfs.rename(oldpath, newpath)
103 except OSError as err:
104 if err.errno != errno.ENOENT:
105 self.debug("warning: cannot rename '%s' to '%s': %s\n" %
106 (newpath, oldpath, err.strerror))
107
108 maxsize = self.configbytes('blackbox', 'maxsize')
109 name = 'blackbox.log'
110 if maxsize > 0:
111 try:
112 st = self._bbvfs.stat(name)
113 except OSError:
114 pass
115 else:
116 if st.st_size >= maxsize:
117 path = self._bbvfs.join(name)
118 maxfiles = self.configint('blackbox', 'maxfiles', 7)
119 for i in xrange(maxfiles - 1, 1, -1):
120 rotate(oldpath='%s.%d' % (path, i - 1),
121 newpath='%s.%d' % (path, i))
122 rotate(oldpath=path,
123 newpath=maxfiles > 0 and path + '.1')
124 return self._bbvfs(name, 'a')
125
126 def log(self, event, *msg, **opts):
126 def log(self, event, *msg, **opts):
127 global lastui
127 global lastui
128 super(blackboxui, self).log(event, *msg, **opts)
128 super(blackboxui, self).log(event, *msg, **opts)
@@ -172,7 +172,7 b' def wrapui(ui):'
172 try:
172 try:
173 fmt = '%s %s @%s%s (%s)%s> %s'
173 fmt = '%s %s @%s%s (%s)%s> %s'
174 args = (date, user, rev, changed, pid, src, formattedmsg)
174 args = (date, user, rev, changed, pid, src, formattedmsg)
175 with ui._openlogfile() as fp:
175 with _openlogfile(ui, vfs) as fp:
176 fp.write(fmt % args)
176 fp.write(fmt % args)
177 except (IOError, OSError) as err:
177 except (IOError, OSError) as err:
178 self.debug('warning: cannot write to blackbox.log: %s\n' %
178 self.debug('warning: cannot write to blackbox.log: %s\n' %
General Comments 0
You need to be logged in to leave comments. Login now