Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit10cdd03

Browse files
authored
Merge pull request#1813 from EliahKagan/logging
Don't suppress messages when logging is not configured
2 parents9a7cec1 +bc42ee5 commit10cdd03

File tree

11 files changed

+57
-68
lines changed

11 files changed

+57
-68
lines changed

‎git/cmd.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@
8181
"strip_newline_in_stdout",
8282
}
8383

84-
log=logging.getLogger(__name__)
85-
log.addHandler(logging.NullHandler())
84+
_logger=logging.getLogger(__name__)
8685

8786
__all__= ("Git",)
8887

@@ -146,7 +145,7 @@ def pump_stream(
146145
handler(line)
147146

148147
exceptExceptionasex:
149-
log.error(f"Pumping{name!r} of cmd({remove_password_if_present(cmdline)}) failed due to:{ex!r}")
148+
_logger.error(f"Pumping{name!r} of cmd({remove_password_if_present(cmdline)}) failed due to:{ex!r}")
150149
if"I/O operation on closed file"notinstr(ex):
151150
# Only reraise if the error was not due to the stream closing
152151
raiseCommandError([f"<{name}-pump>"]+remove_password_if_present(cmdline),ex)fromex
@@ -600,7 +599,7 @@ def _terminate(self) -> None:
600599
self.status=self._status_code_if_terminateorproc.poll()
601600
return
602601
exceptOSErrorasex:
603-
log.info("Ignored error after process had died: %r",ex)
602+
_logger.info("Ignored error after process had died: %r",ex)
604603

605604
# It can be that nothing really exists anymore...
606605
ifosisNoneorgetattr(os,"kill",None)isNone:
@@ -613,7 +612,7 @@ def _terminate(self) -> None:
613612

614613
self.status=self._status_code_if_terminateorstatus
615614
exceptOSErrorasex:
616-
log.info("Ignored error after process had died: %r",ex)
615+
_logger.info("Ignored error after process had died: %r",ex)
617616
# END exception handling
618617

619618
def__del__(self)->None:
@@ -654,7 +653,7 @@ def read_all_from_possibly_closed_stream(stream: Union[IO[bytes], None]) -> byte
654653

655654
ifstatus!=0:
656655
errstr=read_all_from_possibly_closed_stream(p_stderr)
657-
log.debug("AutoInterrupt wait stderr: %r"% (errstr,))
656+
_logger.debug("AutoInterrupt wait stderr: %r"% (errstr,))
658657
raiseGitCommandError(remove_password_if_present(self.args),status,errstr)
659658
returnstatus
660659

@@ -1018,7 +1017,7 @@ def execute(
10181017
# Remove password for the command if present.
10191018
redacted_command=remove_password_if_present(command)
10201019
ifself.GIT_PYTHON_TRACEand (self.GIT_PYTHON_TRACE!="full"oras_process):
1021-
log.info(" ".join(redacted_command))
1020+
_logger.info(" ".join(redacted_command))
10221021

10231022
# Allow the user to have the command executed in their working dir.
10241023
try:
@@ -1055,7 +1054,7 @@ def execute(
10551054
stdout_sink=PIPEifwith_stdoutelsegetattr(subprocess,"DEVNULL",None)oropen(os.devnull,"wb")
10561055
ifshellisNone:
10571056
shell=self.USE_SHELL
1058-
log.debug(
1057+
_logger.debug(
10591058
"Popen(%s, cwd=%s, stdin=%s, shell=%s, universal_newlines=%s)",
10601059
redacted_command,
10611060
cwd,
@@ -1167,17 +1166,17 @@ def as_text(stdout_value: Union[bytes, str]) -> str:
11671166
# END as_text
11681167

11691168
ifstderr_value:
1170-
log.info(
1169+
_logger.info(
11711170
"%s -> %d; stdout: '%s'; stderr: '%s'",
11721171
cmdstr,
11731172
status,
11741173
as_text(stdout_value),
11751174
safe_decode(stderr_value),
11761175
)
11771176
elifstdout_value:
1178-
log.info("%s -> %d; stdout: '%s'",cmdstr,status,as_text(stdout_value))
1177+
_logger.info("%s -> %d; stdout: '%s'",cmdstr,status,as_text(stdout_value))
11791178
else:
1180-
log.info("%s -> %d",cmdstr,status)
1179+
_logger.info("%s -> %d",cmdstr,status)
11811180
# END handle debug printing
11821181

11831182
ifwith_exceptionsandstatus!=0:

‎git/config.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,7 @@
6060

6161
__all__= ("GitConfigParser","SectionConstraint")
6262

63-
64-
log=logging.getLogger("git.config")
65-
log.addHandler(logging.NullHandler())
66-
63+
_logger=logging.getLogger(__name__)
6764

6865
CONFIG_LEVELS:ConfigLevels_Tup= ("system","user","global","repository")
6966
"""The configuration level of a configuration file."""
@@ -412,7 +409,7 @@ def release(self) -> None:
412409
try:
413410
self.write()
414411
exceptIOError:
415-
log.error("Exception during destruction of GitConfigParser",exc_info=True)
412+
_logger.error("Exception during destruction of GitConfigParser",exc_info=True)
416413
exceptReferenceError:
417414
# This happens in Python 3... and usually means that some state cannot be
418415
# written as the sections dict cannot be iterated. This usually happens when
@@ -712,7 +709,7 @@ def write(self) -> None:
712709
# END assert multiple files
713710

714711
ifself._has_includes():
715-
log.debug(
712+
_logger.debug(
716713
"Skipping write-back of configuration file as include files were merged in."
717714
+"Set merge_includes=False to prevent this."
718715
)

‎git/objects/commit.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@
5252

5353
# ------------------------------------------------------------------------
5454

55-
log=logging.getLogger("git.objects.commit")
56-
log.addHandler(logging.NullHandler())
55+
_logger=logging.getLogger(__name__)
5756

5857
__all__= ("Commit",)
5958

@@ -767,7 +766,7 @@ def _deserialize(self, stream: BytesIO) -> "Commit":
767766
self.author_tz_offset,
768767
)=parse_actor_and_date(author_line.decode(self.encoding,"replace"))
769768
exceptUnicodeDecodeError:
770-
log.error(
769+
_logger.error(
771770
"Failed to decode author line '%s' using encoding %s",
772771
author_line,
773772
self.encoding,
@@ -781,7 +780,7 @@ def _deserialize(self, stream: BytesIO) -> "Commit":
781780
self.committer_tz_offset,
782781
)=parse_actor_and_date(committer_line.decode(self.encoding,"replace"))
783782
exceptUnicodeDecodeError:
784-
log.error(
783+
_logger.error(
785784
"Failed to decode committer line '%s' using encoding %s",
786785
committer_line,
787786
self.encoding,
@@ -795,7 +794,7 @@ def _deserialize(self, stream: BytesIO) -> "Commit":
795794
try:
796795
self.message=self.message.decode(self.encoding,"replace")
797796
exceptUnicodeDecodeError:
798-
log.error(
797+
_logger.error(
799798
"Failed to decode message '%s' using encoding %s",
800799
self.message,
801800
self.encoding,

‎git/objects/submodule/base.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141

4242
# typing ----------------------------------------------------------------------
43+
4344
fromtypingimportCallable,Dict,Mapping,Sequence,TYPE_CHECKING,cast
4445
fromtypingimportAny,Iterator,Union
4546

@@ -50,14 +51,11 @@
5051
fromgit.repoimportRepo
5152
fromgit.refsimportHead
5253

53-
5454
# -----------------------------------------------------------------------------
5555

5656
__all__= ["Submodule","UpdateProgress"]
5757

58-
59-
log=logging.getLogger("git.objects.submodule.base")
60-
log.addHandler(logging.NullHandler())
58+
_logger=logging.getLogger(__name__)
6159

6260

6361
classUpdateProgress(RemoteProgress):
@@ -731,7 +729,7 @@ def update(
731729
)
732730
mrepo.head.reference.set_tracking_branch(remote_branch)
733731
except (IndexError,InvalidGitRepositoryError):
734-
log.warning("Failed to checkout tracking branch %s",self.branch_path)
732+
_logger.warning("Failed to checkout tracking branch %s",self.branch_path)
735733
# END handle tracking branch
736734

737735
# NOTE: Have to write the repo config file as well, otherwise the
@@ -761,14 +759,14 @@ def update(
761759
binsha=rcommit.binsha
762760
hexsha=rcommit.hexsha
763761
else:
764-
log.error(
762+
_logger.error(
765763
"%s a tracking branch was not set for local branch '%s'",
766764
msg_base,
767765
mrepo.head.reference,
768766
)
769767
# END handle remote ref
770768
else:
771-
log.error("%s there was no local tracking branch",msg_base)
769+
_logger.error("%s there was no local tracking branch",msg_base)
772770
# END handle detached head
773771
# END handle to_latest_revision option
774772

@@ -786,15 +784,15 @@ def update(
786784
ifforce:
787785
msg="Will force checkout or reset on local branch that is possibly in the future of"
788786
msg+=" the commit it will be checked out to, effectively 'forgetting' new commits"
789-
log.debug(msg)
787+
_logger.debug(msg)
790788
else:
791789
msg="Skipping %s on branch '%s' of submodule repo '%s' as it contains un-pushed commits"
792790
msg%= (
793791
is_detachedand"checkout"or"reset",
794792
mrepo.head,
795793
mrepo,
796794
)
797-
log.info(msg)
795+
_logger.info(msg)
798796
may_reset=False
799797
# END handle force
800798
# END handle if we are in the future
@@ -834,7 +832,7 @@ def update(
834832
exceptExceptionaserr:
835833
ifnotkeep_going:
836834
raise
837-
log.error(str(err))
835+
_logger.error(str(err))
838836
# END handle keep_going
839837

840838
# HANDLE RECURSION

‎git/objects/submodule/root.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222

2323
__all__= ["RootModule","RootUpdateProgress"]
2424

25-
log=logging.getLogger("git.objects.submodule.root")
26-
log.addHandler(logging.NullHandler())
25+
_logger=logging.getLogger(__name__)
2726

2827

2928
classRootUpdateProgress(UpdateProgress):
@@ -321,7 +320,7 @@ def update(
321320
# this way, it will be checked out in the next step.
322321
# This will change the submodule relative to us, so
323322
# the user will be able to commit the change easily.
324-
log.warning(
323+
_logger.warning(
325324
"Current sha %s was not contained in the tracking\
326325
branch at the new remote, setting it the the remote's tracking branch",
327326
sm.hexsha,
@@ -393,7 +392,7 @@ def update(
393392
exceptExceptionaserr:
394393
ifnotkeep_going:
395394
raise
396-
log.error(str(err))
395+
_logger.error(str(err))
397396
# END handle keep_going
398397

399398
# FINALLY UPDATE ALL ACTUAL SUBMODULES

‎git/remote.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@
5858

5959
# -------------------------------------------------------------
6060

61-
62-
log=logging.getLogger("git.remote")
63-
log.addHandler(logging.NullHandler())
64-
61+
_logger=logging.getLogger(__name__)
6562

6663
__all__= ("RemoteProgress","PushInfo","FetchInfo","Remote")
6764

@@ -846,7 +843,7 @@ def _get_fetch_info_from_stderr(
846843
stderr_text=progress.error_linesand"\n".join(progress.error_lines)or""
847844
proc.wait(stderr=stderr_text)
848845
ifstderr_text:
849-
log.warning("Error lines received while fetching: %s",stderr_text)
846+
_logger.warning("Error lines received while fetching: %s",stderr_text)
850847

851848
forlineinprogress.other_lines:
852849
line=force_text(line)
@@ -867,9 +864,9 @@ def _get_fetch_info_from_stderr(
867864
msg+="length of progress lines %i should be equal to lines in FETCH_HEAD file %i\n"
868865
msg+="Will ignore extra progress lines or fetch head lines."
869866
msg%= (l_fil,l_fhi)
870-
log.debug(msg)
871-
log.debug(b"info lines: "+str(fetch_info_lines).encode("UTF-8"))
872-
log.debug(b"head info: "+str(fetch_head_info).encode("UTF-8"))
867+
_logger.debug(msg)
868+
_logger.debug(b"info lines: "+str(fetch_info_lines).encode("UTF-8"))
869+
_logger.debug(b"head info: "+str(fetch_head_info).encode("UTF-8"))
873870
ifl_fil<l_fhi:
874871
fetch_head_info=fetch_head_info[:l_fil]
875872
else:
@@ -881,8 +878,8 @@ def _get_fetch_info_from_stderr(
881878
try:
882879
output.append(FetchInfo._from_line(self.repo,err_line,fetch_line))
883880
exceptValueErrorasexc:
884-
log.debug("Caught error while parsing line: %s",exc)
885-
log.warning("Git informed while fetching: %s",err_line.strip())
881+
_logger.debug("Caught error while parsing line: %s",exc)
882+
_logger.warning("Git informed while fetching: %s",err_line.strip())
886883
returnoutput
887884

888885
def_get_push_info(
@@ -924,7 +921,7 @@ def stdout_handler(line: str) -> None:
924921
ifnotoutput:
925922
raise
926923
elifstderr_text:
927-
log.warning("Error lines received while fetching: %s",stderr_text)
924+
_logger.warning("Error lines received while fetching: %s",stderr_text)
928925
output.error=e
929926

930927
returnoutput

‎git/repo/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989

9090
# -----------------------------------------------------------
9191

92-
log=logging.getLogger(__name__)
92+
_logger=logging.getLogger(__name__)
9393

9494
__all__= ("Repo",)
9595

@@ -772,7 +772,7 @@ def is_valid_object(self, sha: str, object_type: Union[str, None] = None) -> boo
772772
ifobject_info.type==object_type.encode():
773773
returnTrue
774774
else:
775-
log.debug(
775+
_logger.debug(
776776
"Commit hash points to an object of type '%s'. Requested were objects of type '%s'",
777777
object_info.type.decode(),
778778
object_type,
@@ -781,7 +781,7 @@ def is_valid_object(self, sha: str, object_type: Union[str, None] = None) -> boo
781781
else:
782782
returnTrue
783783
exceptBadObject:
784-
log.debug("Commit hash is invalid.")
784+
_logger.debug("Commit hash is invalid.")
785785
returnFalse
786786

787787
def_get_daemon_export(self)->bool:
@@ -1298,7 +1298,7 @@ def _clone(
12981298
cmdline=getattr(proc,"args","")
12991299
cmdline=remove_password_if_present(cmdline)
13001300

1301-
log.debug("Cmd(%s)'s unused stdout: %s",cmdline,stdout)
1301+
_logger.debug("Cmd(%s)'s unused stdout: %s",cmdline,stdout)
13021302
finalize_process(proc,stderr=stderr)
13031303

13041304
# Our git command could have a different working dir than our actual

‎git/util.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
"HIDE_WINDOWS_KNOWN_ERRORS",
105105
]
106106

107-
log=logging.getLogger(__name__)
107+
_logger=logging.getLogger(__name__)
108108

109109

110110
def_read_win_env_flag(name:str,default:bool)->bool:
@@ -124,7 +124,7 @@ def _read_win_env_flag(name: str, default: bool) -> bool:
124124
exceptKeyError:
125125
returndefault
126126

127-
log.warning(
127+
_logger.warning(
128128
"The %s environment variable is deprecated. Its effect has never been documented and changes without warning.",
129129
name,
130130
)
@@ -135,7 +135,7 @@ def _read_win_env_flag(name: str, default: bool) -> bool:
135135
returnFalse
136136
ifadjusted_valuein {"1","true","yes"}:
137137
returnTrue
138-
log.warning("%s has unrecognized value %r, treating as %r.",name,value,default)
138+
_logger.warning("%s has unrecognized value %r, treating as %r.",name,value,default)
139139
returndefault
140140

141141

@@ -466,7 +466,7 @@ def is_cygwin_git(git_executable: Union[None, PathLike]) -> bool:
466466
# retcode = process.poll()
467467
is_cygwin="CYGWIN"inuname_out
468468
exceptExceptionasex:
469-
log.debug("Failed checking if running in CYGWIN due to: %r",ex)
469+
_logger.debug("Failed checking if running in CYGWIN due to: %r",ex)
470470
_is_cygwin_cache[git_executable]=is_cygwin
471471

472472
returnis_cygwin

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp