Show More
@@ -20,6 +20,7 b' from kallithea.config.middleware.simpleg' | |||
|
20 | 20 | from kallithea.config.middleware.simplehg import SimpleHg |
|
21 | 21 | from kallithea.config.middleware.wrapper import RequestWrapper |
|
22 | 22 | from kallithea.lib.utils2 import asbool |
|
23 | from kallithea.lib.vcs.utils import hgcompat | |
|
23 | 24 | |
|
24 | 25 | |
|
25 | 26 | __all__ = ['make_app'] |
@@ -50,6 +51,7 b' def wrap_app(app):' | |||
|
50 | 51 | def make_app(global_conf, **app_conf): |
|
51 | 52 | """Return WSGI app with logging Mercurial stdout/stderr - to be used as |
|
52 | 53 | Paste or mod_wsgi entry point""" |
|
54 | hgcompat.redirect_stdio_to_logging() | |
|
53 | 55 | return make_app_raw(global_conf, **app_conf) |
|
54 | 56 | |
|
55 | 57 |
@@ -2,10 +2,25 b'' | |||
|
2 | 2 | Mercurial libs compatibility |
|
3 | 3 | """ |
|
4 | 4 | |
|
5 | import logging | |
|
6 | ||
|
5 | 7 | import mercurial.encoding |
|
6 | 8 | import mercurial.localrepo |
|
7 | 9 | |
|
8 | 10 | |
|
11 | class MercurialStdLogger: | |
|
12 | def __init__(self, logger): | |
|
13 | self.logger = logger | |
|
14 | ||
|
15 | def write(self, message): | |
|
16 | try: | |
|
17 | self.logger(message.decode().rstrip()) | |
|
18 | except: | |
|
19 | self.logger(message) | |
|
20 | ||
|
21 | def flush(self): | |
|
22 | pass | |
|
23 | ||
|
9 | 24 | def monkey_do(): |
|
10 | 25 | """Apply some Mercurial monkey patching""" |
|
11 | 26 | # workaround for 3.3 94ac64bcf6fe and not calling largefiles reposetup correctly, and test_archival failing |
@@ -15,3 +30,18 b' def monkey_do():' | |||
|
15 | 30 | |
|
16 | 31 | # Minimize potential impact from custom configuration |
|
17 | 32 | mercurial.encoding.environ[b'HGPLAIN'] = b'1' |
|
33 | ||
|
34 | ||
|
35 | hglog = logging.getLogger("mercurial") | |
|
36 | ||
|
37 | ||
|
38 | def redirect_stdio_to_logging(): | |
|
39 | # Capture Mercurial stdout/stderr and send to a 'mercurial' logger | |
|
40 | try: | |
|
41 | import mercurial.utils.procutil as procutil | |
|
42 | if not isinstance(procutil.stdout, MercurialStdLogger): | |
|
43 | procutil.stdout = MercurialStdLogger(hglog.info) | |
|
44 | if not isinstance(procutil.stderr, MercurialStdLogger): | |
|
45 | procutil.stderr = MercurialStdLogger(hglog.warning) | |
|
46 | except Exception as e: | |
|
47 | hglog.error("Exception installing procutil stdout/stderr: %s", e) |
General Comments 0
You need to be logged in to leave comments.
Login now