Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mitogen
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
mitogen
Commits
09eb3fd9
Commit
09eb3fd9
authored
Feb 13, 2018
by
David Wilson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
utils: support log_to_file(usec=True)
parent
2848d35a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
2 deletions
+15
-2
docs/api.rst
docs/api.rst
+5
-1
mitogen/utils.py
mitogen/utils.py
+10
-1
No files found.
docs/api.rst
View file @
09eb3fd9
...
...
@@ -873,7 +873,7 @@ A random assortment of utility functions useful on masters and children.
OS X bundles some ancient version of the :py:mod:`six` module.
.. currentmodule:: mitogen.utils
.. function:: log_to_file (path=None, io=True, level='INFO')
.. function:: log_to_file (path=None, io=True,
usec=False,
level='INFO')
Install a new :py:class:`logging.Handler` writing applications logs to the
filesystem. Useful when debugging slave IO problems.
...
...
@@ -886,6 +886,10 @@ A random assortment of utility functions useful on masters and children.
If ``True``, include extremely verbose IO logs in the output. Useful
for debugging hangs, less useful for debugging application code.
:parm bool usec:
If ``True``, include microsecond timestamps. This greatly helps when
debugging races and similar determinism issues.
:param str level:
Name of the :py:mod:`logging` package constant that is the minimum
level to log at. Useful levels are ``DEBUG``, ``INFO``, ``WARNING``,
...
...
mitogen/utils.py
View file @
09eb3fd9
...
...
@@ -25,6 +25,7 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import
datetime
import
logging
import
sys
...
...
@@ -42,7 +43,12 @@ def disable_site_packages():
sys
.
path
.
remove
(
entry
)
def
log_to_file
(
path
=
None
,
io
=
True
,
level
=
'INFO'
):
def
_formatTime
(
record
,
datefmt
=
None
):
dt
=
datetime
.
datetime
.
fromtimestamp
(
record
.
created
)
return
dt
.
strftime
(
datefmt
)
def
log_to_file
(
path
=
None
,
io
=
True
,
usec
=
False
,
level
=
'INFO'
):
log
=
logging
.
getLogger
(
''
)
if
path
:
fp
=
open
(
path
,
'w'
,
1
)
...
...
@@ -57,8 +63,11 @@ def log_to_file(path=None, io=True, level='INFO'):
fmt
=
'%(asctime)s %(levelname).1s %(name)s: %(message)s'
datefmt
=
'%H:%M:%S'
if
usec
:
datefmt
+=
'.%f'
handler
=
logging
.
StreamHandler
(
fp
)
handler
.
formatter
=
logging
.
Formatter
(
fmt
,
datefmt
)
handler
.
formatter
.
formatTime
=
_formatTime
log
.
handlers
.
insert
(
0
,
handler
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment