mercurial/loggingutil.py
author Anton Shestakov <av6@dwimlabs.net>
Fri, 07 Jan 2022 11:53:23 +0300
changeset 48687 f8f2ecdde4b5
parent 46892 4a6024b87dfc
child 48875 6000f5b25c9b
permissions -rw-r--r--
branchmap: skip obsolete revisions while computing heads It's time to make this part of core Mercurial obsolescence-aware. Not considering obsolete revisions when computing heads is clearly what Mercurial should do. But there are a couple of small issues: - Let's say tip of the repo is obsolete. There are two ways of finding tiprev for branchcache (both are in use): looking at input data for update() and looking at computed heads after update(). Previously, repo tip would be tiprev of the branchcache. With this patch, an obsolete revision can no longer be tiprev. And depending on what way we use for finding tiprev (input data vs computed heads) we'll get a different result. This is relevant when recomputing cache key from cache contents, and may lead to updating cache for obsolete revisions multiple times (not from scratch, because it still would be considered valid for a subset of revisions in the repo). - If all commits on a branch are obsolete, the branchcache will include that branch, but the list of heads will be empty (that's why there's now `if not heads` when recomputing tiprev/tipnode from cache contents). Having an entry for every branch is currently required for notify extension (and test-notify.t to pass), because notify doesn't handle revsets in its subscription config very well and will throw an error if e.g. a branch doesn't exist. - Cloning static HTTP repos may try to stat() a non-existent obsstore file. The issue is that we now care about obsolescence during clone, but statichttpvfs doesn't implement a stat method, so a regular vfs.stat() is used, and it assumes that file is local and calls os.stat(). During a clone, we're trying to stat() .hg/store/obsstore, but in static HTTP case we provide a literal URL to the obsstore file on the remote as if it were a local file path. On windows it actually results in a failure in test-static-http.t. The first issue is going to be addressed in a series dedicated to making sure branchcache is properly and timely written on disk (it wasn't perfect even before this patch, but there aren't enough tests to demonstrate that). The second issue will be addressed in a future patch for notify extension that will make it not raise an exception if a branch doesn't exist. And the third one was partially addressed in the previous patch in this series and will be properly fixed in a future patch when this series is accepted. filteredhash() grows a keyword argument to make sure that branchcache is also invalidated when there are new obsolete revisions in its repo view. This way the on-disk cache format is unchanged and compatible between versions (although it will obviously be recomputed when switching versions before/after this patch and the repo has obsolete revisions). There's one test that uses plain `hg up` without arguments while updated to a pruned commit. To make this test pass, simply return current working directory parent. Later in this series this code will be replaced by what prune command does: updating to the closest non-obsolete ancestor. Test changes: test-branch-change.t: update branch head and cache update message. The head of default listed in hg heads is changed because revision 2 was rewritten as 7, and 1 is the closest ancestor on the same branch, so it's the head of default now. The cache invalidation message appears now because of the cache hash change, since we're now accounting for obsolete revisions. Here's some context: "served.hidden" repo filter means everything is visible (no filtered revisions), so before this series branch2-served.hidden file would not contain any cache hash, only revnum and node. Now it also has a hash when there are obsolete changesets in the repo. The command that the message appears for is changing branch of 5 and 6, which are now obsolete, so the cache hash changes. In general, when cache is simply out-of-date, it can be updated using the old version as a base. But if cache hash differs, then the cache for that particular repo filter is recomputed (at least with the current implementation). This is what happens here. test-obsmarker-template.t: the pull reports 2 heads changed, but after that the repo correctly sees only 1. The new message could be better, but it's still an improvement over the previous one where hg pull suggested merging with an obsolete revision. test-obsolete.t: we can see these revisions in hg log --hidden, but they shouldn't be considered heads even with --hidden. test-rebase-obsolete{,2}.t: there were new heads created previously after making new orphan changesets, but they weren't detected. Now we are properly detecting and reporting them. test-rebase-obsolete4.t: there's only one head now because the other head is pruned and was falsely reported before. test-static-http.t: add obsstore to the list of requested files. This file doesn't exist on the remotes, but clients want it anyway (they get 404). This is fine, because there are other nonexistent files that clients request, like .hg/bookmarks or .hg/cache/tags2-served. Differential Revision: https://phab.mercurial-scm.org/D12097
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
40799
03127e580980 loggingutil: extract openlogfile() and proxylogger to new module
Yuya Nishihara <yuya@tcha.org>
parents: 40798
diff changeset
     1
# loggingutil.py - utility for logging events
18669
18242716a014 blackbox: adds a blackbox extension
Durham Goode <durham@fb.com>
parents:
diff changeset
     2
#
18676
1506eb487ddd blackbox: fix copyright
Bryan O'Sullivan <bryano@fb.com>
parents: 18675
diff changeset
     3
# Copyright 2010 Nicolas Dumazet
18669
18242716a014 blackbox: adds a blackbox extension
Durham Goode <durham@fb.com>
parents:
diff changeset
     4
# Copyright 2013 Facebook, Inc.
18242716a014 blackbox: adds a blackbox extension
Durham Goode <durham@fb.com>
parents:
diff changeset
     5
#
18242716a014 blackbox: adds a blackbox extension
Durham Goode <durham@fb.com>
parents:
diff changeset
     6
# This software may be used and distributed according to the terms of the
18242716a014 blackbox: adds a blackbox extension
Durham Goode <durham@fb.com>
parents:
diff changeset
     7
# GNU General Public License version 2 or any later version.
18242716a014 blackbox: adds a blackbox extension
Durham Goode <durham@fb.com>
parents:
diff changeset
     8
28090
8113c88b8e6d blackbox: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28027
diff changeset
     9
from __future__ import absolute_import
8113c88b8e6d blackbox: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28027
diff changeset
    10
8113c88b8e6d blackbox: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28027
diff changeset
    11
import errno
8113c88b8e6d blackbox: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28027
diff changeset
    12
46892
4a6024b87dfc blackbox: fix type error on log rotation on read-only filesystem
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents: 43077
diff changeset
    13
from . import (
4a6024b87dfc blackbox: fix type error on log rotation on read-only filesystem
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents: 43077
diff changeset
    14
    encoding,
4a6024b87dfc blackbox: fix type error on log rotation on read-only filesystem
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents: 43077
diff changeset
    15
    pycompat,
4a6024b87dfc blackbox: fix type error on log rotation on read-only filesystem
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents: 43077
diff changeset
    16
)
18669
18242716a014 blackbox: adds a blackbox extension
Durham Goode <durham@fb.com>
parents:
diff changeset
    17
40821
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
    18
from .utils import (
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
    19
    dateutil,
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
    20
    procutil,
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
    21
    stringutil,
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
    22
)
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
    23
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40821
diff changeset
    24
40799
03127e580980 loggingutil: extract openlogfile() and proxylogger to new module
Yuya Nishihara <yuya@tcha.org>
parents: 40798
diff changeset
    25
def openlogfile(ui, vfs, name, maxfiles=0, maxsize=0):
40800
698477777883 loggingutil: document openlogfile()
Yuya Nishihara <yuya@tcha.org>
parents: 40799
diff changeset
    26
    """Open log file in append mode, with optional rotation
698477777883 loggingutil: document openlogfile()
Yuya Nishihara <yuya@tcha.org>
parents: 40799
diff changeset
    27
698477777883 loggingutil: document openlogfile()
Yuya Nishihara <yuya@tcha.org>
parents: 40799
diff changeset
    28
    If maxsize > 0, the log file will be rotated up to maxfiles.
698477777883 loggingutil: document openlogfile()
Yuya Nishihara <yuya@tcha.org>
parents: 40799
diff changeset
    29
    """
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40821
diff changeset
    30
34300
e6723c939344 blackbox: move _openlogfile to a separate method
Jun Wu <quark@fb.com>
parents: 34299
diff changeset
    31
    def rotate(oldpath, newpath):
e6723c939344 blackbox: move _openlogfile to a separate method
Jun Wu <quark@fb.com>
parents: 34299
diff changeset
    32
        try:
e6723c939344 blackbox: move _openlogfile to a separate method
Jun Wu <quark@fb.com>
parents: 34299
diff changeset
    33
            vfs.unlink(newpath)
e6723c939344 blackbox: move _openlogfile to a separate method
Jun Wu <quark@fb.com>
parents: 34299
diff changeset
    34
        except OSError as err:
e6723c939344 blackbox: move _openlogfile to a separate method
Jun Wu <quark@fb.com>
parents: 34299
diff changeset
    35
            if err.errno != errno.ENOENT:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40821
diff changeset
    36
                ui.debug(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    37
                    b"warning: cannot remove '%s': %s\n"
46892
4a6024b87dfc blackbox: fix type error on log rotation on read-only filesystem
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents: 43077
diff changeset
    38
                    % (newpath, encoding.strtolocal(err.strerror))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40821
diff changeset
    39
                )
34300
e6723c939344 blackbox: move _openlogfile to a separate method
Jun Wu <quark@fb.com>
parents: 34299
diff changeset
    40
        try:
e6723c939344 blackbox: move _openlogfile to a separate method
Jun Wu <quark@fb.com>
parents: 34299
diff changeset
    41
            if newpath:
e6723c939344 blackbox: move _openlogfile to a separate method
Jun Wu <quark@fb.com>
parents: 34299
diff changeset
    42
                vfs.rename(oldpath, newpath)
e6723c939344 blackbox: move _openlogfile to a separate method
Jun Wu <quark@fb.com>
parents: 34299
diff changeset
    43
        except OSError as err:
e6723c939344 blackbox: move _openlogfile to a separate method
Jun Wu <quark@fb.com>
parents: 34299
diff changeset
    44
            if err.errno != errno.ENOENT:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40821
diff changeset
    45
                ui.debug(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    46
                    b"warning: cannot rename '%s' to '%s': %s\n"
46892
4a6024b87dfc blackbox: fix type error on log rotation on read-only filesystem
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents: 43077
diff changeset
    47
                    % (newpath, oldpath, encoding.strtolocal(err.strerror))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40821
diff changeset
    48
                )
34300
e6723c939344 blackbox: move _openlogfile to a separate method
Jun Wu <quark@fb.com>
parents: 34299
diff changeset
    49
e6723c939344 blackbox: move _openlogfile to a separate method
Jun Wu <quark@fb.com>
parents: 34299
diff changeset
    50
    if maxsize > 0:
e6723c939344 blackbox: move _openlogfile to a separate method
Jun Wu <quark@fb.com>
parents: 34299
diff changeset
    51
        try:
e6723c939344 blackbox: move _openlogfile to a separate method
Jun Wu <quark@fb.com>
parents: 34299
diff changeset
    52
            st = vfs.stat(name)
e6723c939344 blackbox: move _openlogfile to a separate method
Jun Wu <quark@fb.com>
parents: 34299
diff changeset
    53
        except OSError:
e6723c939344 blackbox: move _openlogfile to a separate method
Jun Wu <quark@fb.com>
parents: 34299
diff changeset
    54
            pass
e6723c939344 blackbox: move _openlogfile to a separate method
Jun Wu <quark@fb.com>
parents: 34299
diff changeset
    55
        else:
e6723c939344 blackbox: move _openlogfile to a separate method
Jun Wu <quark@fb.com>
parents: 34299
diff changeset
    56
            if st.st_size >= maxsize:
e6723c939344 blackbox: move _openlogfile to a separate method
Jun Wu <quark@fb.com>
parents: 34299
diff changeset
    57
                path = vfs.join(name)
38783
e7aa113b14f7 global: use pycompat.xrange()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37120
diff changeset
    58
                for i in pycompat.xrange(maxfiles - 1, 1, -1):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40821
diff changeset
    59
                    rotate(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    60
                        oldpath=b'%s.%d' % (path, i - 1),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    61
                        newpath=b'%s.%d' % (path, i),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40821
diff changeset
    62
                    )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    63
                rotate(oldpath=path, newpath=maxfiles > 0 and path + b'.1')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    64
    return vfs(name, b'a', makeparentdirs=False)
34300
e6723c939344 blackbox: move _openlogfile to a separate method
Jun Wu <quark@fb.com>
parents: 34299
diff changeset
    65
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40821
diff changeset
    66
40821
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
    67
def _formatlogline(msg):
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
    68
    date = dateutil.datestr(format=b'%Y/%m/%d %H:%M:%S')
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
    69
    pid = procutil.getpid()
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
    70
    return b'%s (%d)> %s' % (date, pid, msg)
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
    71
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40821
diff changeset
    72
40821
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
    73
def _matchevent(event, tracked):
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
    74
    return b'*' in tracked or event in tracked
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
    75
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40821
diff changeset
    76
40821
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
    77
class filelogger(object):
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
    78
    """Basic logger backed by physical file with optional rotation"""
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
    79
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
    80
    def __init__(self, vfs, name, tracked, maxfiles=0, maxsize=0):
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
    81
        self._vfs = vfs
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
    82
        self._name = name
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
    83
        self._trackedevents = set(tracked)
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
    84
        self._maxfiles = maxfiles
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
    85
        self._maxsize = maxsize
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
    86
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
    87
    def tracked(self, event):
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
    88
        return _matchevent(event, self._trackedevents)
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
    89
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
    90
    def log(self, ui, event, msg, opts):
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
    91
        line = _formatlogline(msg)
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
    92
        try:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40821
diff changeset
    93
            with openlogfile(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40821
diff changeset
    94
                ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40821
diff changeset
    95
                self._vfs,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40821
diff changeset
    96
                self._name,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40821
diff changeset
    97
                maxfiles=self._maxfiles,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40821
diff changeset
    98
                maxsize=self._maxsize,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40821
diff changeset
    99
            ) as fp:
40821
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
   100
                fp.write(line)
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
   101
        except IOError as err:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40821
diff changeset
   102
            ui.debug(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40821
diff changeset
   103
                b'cannot write to %s: %s\n'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40821
diff changeset
   104
                % (self._name, stringutil.forcebytestr(err))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40821
diff changeset
   105
            )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40821
diff changeset
   106
40821
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
   107
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
   108
class fileobjectlogger(object):
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
   109
    """Basic logger backed by file-like object"""
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
   110
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
   111
    def __init__(self, fp, tracked):
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
   112
        self._fp = fp
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
   113
        self._trackedevents = set(tracked)
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
   114
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
   115
    def tracked(self, event):
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
   116
        return _matchevent(event, self._trackedevents)
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
   117
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
   118
    def log(self, ui, event, msg, opts):
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
   119
        line = _formatlogline(msg)
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
   120
        try:
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
   121
            self._fp.write(line)
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
   122
            self._fp.flush()
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
   123
        except IOError as err:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40821
diff changeset
   124
            ui.debug(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40821
diff changeset
   125
                b'cannot write to %s: %s\n'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40821
diff changeset
   126
                % (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40821
diff changeset
   127
                    stringutil.forcebytestr(self._fp.name),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40821
diff changeset
   128
                    stringutil.forcebytestr(err),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40821
diff changeset
   129
                )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40821
diff changeset
   130
            )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40821
diff changeset
   131
40821
96be0ecad648 loggingutil: add basic logger backends
Yuya Nishihara <yuya@tcha.org>
parents: 40800
diff changeset
   132
40762
37d6ee46a965 blackbox: extract global last logger to proxylogger class
Yuya Nishihara <yuya@tcha.org>
parents: 40760
diff changeset
   133
class proxylogger(object):
37d6ee46a965 blackbox: extract global last logger to proxylogger class
Yuya Nishihara <yuya@tcha.org>
parents: 40760
diff changeset
   134
    """Forward log events to another logger to be set later"""
37d6ee46a965 blackbox: extract global last logger to proxylogger class
Yuya Nishihara <yuya@tcha.org>
parents: 40760
diff changeset
   135
37d6ee46a965 blackbox: extract global last logger to proxylogger class
Yuya Nishihara <yuya@tcha.org>
parents: 40760
diff changeset
   136
    def __init__(self):
37d6ee46a965 blackbox: extract global last logger to proxylogger class
Yuya Nishihara <yuya@tcha.org>
parents: 40760
diff changeset
   137
        self.logger = None
37d6ee46a965 blackbox: extract global last logger to proxylogger class
Yuya Nishihara <yuya@tcha.org>
parents: 40760
diff changeset
   138
37d6ee46a965 blackbox: extract global last logger to proxylogger class
Yuya Nishihara <yuya@tcha.org>
parents: 40760
diff changeset
   139
    def tracked(self, event):
37d6ee46a965 blackbox: extract global last logger to proxylogger class
Yuya Nishihara <yuya@tcha.org>
parents: 40760
diff changeset
   140
        return self.logger is not None and self.logger.tracked(event)
37d6ee46a965 blackbox: extract global last logger to proxylogger class
Yuya Nishihara <yuya@tcha.org>
parents: 40760
diff changeset
   141
37d6ee46a965 blackbox: extract global last logger to proxylogger class
Yuya Nishihara <yuya@tcha.org>
parents: 40760
diff changeset
   142
    def log(self, ui, event, msg, opts):
37d6ee46a965 blackbox: extract global last logger to proxylogger class
Yuya Nishihara <yuya@tcha.org>
parents: 40760
diff changeset
   143
        assert self.logger is not None
37d6ee46a965 blackbox: extract global last logger to proxylogger class
Yuya Nishihara <yuya@tcha.org>
parents: 40760
diff changeset
   144
        self.logger.log(ui, event, msg, opts)