77msgstr ""
88"Project-Id-Version :Python 3.13\n "
99"Report-Msgid-Bugs-To :\n "
10- "POT-Creation-Date :2025-07-07 10:49 +0000\n "
10+ "POT-Creation-Date :2025-07-10 00:16 +0000\n "
1111"PO-Revision-Date :2018-05-23 14:36+0000\n "
1212"Last-Translator :Adrian Liaw <adrianliaw2000@gmail.com>\n "
1313"Language-Team :Chinese - TAIWAN (https://github.com/python/python-docs-zh- "
@@ -5368,56 +5368,107 @@ msgid ""
53685368"2025-07-02 13:54:47,234 DEBUG can't get fooled again"
53695369msgstr ""
53705370
5371+ #: ../../howto/logging-cookbook.rst:4130
5372+ msgid ""
5373+ "If, on the other hand, you are concerned about `log injection <https://owasp."
5374+ "org/www-community/attacks/Log_Injection>`_, you can use a formatter which "
5375+ "escapes newlines, as per the following example:"
5376+ msgstr ""
5377+
53715378#: ../../howto/logging-cookbook.rst:4134
5379+ msgid ""
5380+ "import logging\n"
5381+ "\n"
5382+ "logger = logging.getLogger(__name__)\n"
5383+ "\n"
5384+ "class EscapingFormatter(logging.Formatter):\n"
5385+ " def format(self, record):\n"
5386+ " s = super().format(record)\n"
5387+ " return s.replace('\\ n', r'\\ n')\n"
5388+ "\n"
5389+ "if __name__ == '__main__':\n"
5390+ " h = logging.StreamHandler()\n"
5391+ " h.setFormatter(EscapingFormatter('%(asctime)s %(levelname)-9s "
5392+ "%(message)s'))\n"
5393+ " logging.basicConfig(level=logging.DEBUG, handlers = [h])\n"
5394+ " logger.debug('Single line')\n"
5395+ " logger.debug('Multiple lines:\\ nfool me once ...')\n"
5396+ " logger.debug('Another single line')\n"
5397+ " logger.debug('Multiple lines:\\ n%s', 'fool me ...\\ ncan\\ 't get fooled "
5398+ "again')"
5399+ msgstr ""
5400+
5401+ #: ../../howto/logging-cookbook.rst:4154
5402+ msgid ""
5403+ "You can, of course, use whatever escaping scheme makes the most sense for "
5404+ "you. The script, when run, should produce output like this:"
5405+ msgstr ""
5406+
5407+ #: ../../howto/logging-cookbook.rst:4157
5408+ msgid ""
5409+ "2025-07-09 06:47:33,783 DEBUG Single line\n"
5410+ "2025-07-09 06:47:33,783 DEBUG Multiple lines:\\ nfool me once ...\n"
5411+ "2025-07-09 06:47:33,783 DEBUG Another single line\n"
5412+ "2025-07-09 06:47:33,783 DEBUG Multiple lines:\\ nfool me ...\\ ncan't get "
5413+ "fooled again"
5414+ msgstr ""
5415+
5416+ #: ../../howto/logging-cookbook.rst:4164
5417+ msgid ""
5418+ "Escaping behaviour can't be the stdlib default , as it would break backwards "
5419+ "compatibility."
5420+ msgstr ""
5421+
5422+ #: ../../howto/logging-cookbook.rst:4170
53725423msgid "Patterns to avoid"
53735424msgstr ""
53745425
5375- #: ../../howto/logging-cookbook.rst:4136
5426+ #: ../../howto/logging-cookbook.rst:4172
53765427msgid ""
53775428"Although the preceding sections have described ways of doing things you "
53785429"might need to do or deal with, it is worth mentioning some usage patterns "
53795430"which are *unhelpful*, and which should therefore be avoided in most cases. "
53805431"The following sections are in no particular order."
53815432msgstr ""
53825433
5383- #: ../../howto/logging-cookbook.rst:4142
5434+ #: ../../howto/logging-cookbook.rst:4178
53845435msgid "Opening the same log file multiple times"
53855436msgstr ""
53865437
5387- #: ../../howto/logging-cookbook.rst:4144
5438+ #: ../../howto/logging-cookbook.rst:4180
53885439msgid ""
53895440"On Windows, you will generally not be able to open the same file multiple "
53905441"times as this will lead to a\" file is in use by another process\" error. "
53915442"However, on POSIX platforms you'll not get any errors if you open the same "
53925443"file multiple times. This could be done accidentally, for example by:"
53935444msgstr ""
53945445
5395- #: ../../howto/logging-cookbook.rst:4149
5446+ #: ../../howto/logging-cookbook.rst:4185
53965447msgid ""
53975448"Adding a file handler more than once which references the same file (e.g. by "
53985449"a copy/paste/forget-to-change error)."
53995450msgstr ""
54005451
5401- #: ../../howto/logging-cookbook.rst:4152
5452+ #: ../../howto/logging-cookbook.rst:4188
54025453msgid ""
54035454"Opening two files that look different, as they have different names, but are "
54045455"the same because one is a symbolic link to the other."
54055456msgstr ""
54065457
5407- #: ../../howto/logging-cookbook.rst:4155
5458+ #: ../../howto/logging-cookbook.rst:4191
54085459msgid ""
54095460"Forking a process, following which both parent and child have a reference to "
54105461"the same file. This might be through use of the :mod:`multiprocessing` "
54115462"module, for example."
54125463msgstr ""
54135464
5414- #: ../../howto/logging-cookbook.rst:4159
5465+ #: ../../howto/logging-cookbook.rst:4195
54155466msgid ""
54165467"Opening a file multiple times might *appear* to work most of the time, but "
54175468"can lead to a number of problems in practice:"
54185469msgstr ""
54195470
5420- #: ../../howto/logging-cookbook.rst:4162
5471+ #: ../../howto/logging-cookbook.rst:4198
54215472msgid ""
54225473"Logging output can be garbled because multiple threads or processes try to "
54235474"write to the same file. Although logging guards against concurrent use of "
@@ -5426,7 +5477,7 @@ msgid ""
54265477"different handler instances which happen to point to the same file."
54275478msgstr ""
54285479
5429- #: ../../howto/logging-cookbook.rst:4168
5480+ #: ../../howto/logging-cookbook.rst:4204
54305481msgid ""
54315482"An attempt to delete a file (e.g. during file rotation) silently fails, "
54325483"because there is another reference pointing to it. This can lead to "
@@ -5436,17 +5487,17 @@ msgid ""
54365487"being supposedly in place."
54375488msgstr ""
54385489
5439- #: ../../howto/logging-cookbook.rst:4175
5490+ #: ../../howto/logging-cookbook.rst:4211
54405491msgid ""
54415492"Use the techniques outlined in :ref:`multiple-processes` to circumvent such "
54425493"issues."
54435494msgstr ""
54445495
5445- #: ../../howto/logging-cookbook.rst:4179
5496+ #: ../../howto/logging-cookbook.rst:4215
54465497msgid "Using loggers as attributes in a class or passing them as parameters"
54475498msgstr ""
54485499
5449- #: ../../howto/logging-cookbook.rst:4181
5500+ #: ../../howto/logging-cookbook.rst:4217
54505501msgid ""
54515502"While there might be unusual cases where you'll need to do this, in general "
54525503"there is no point because loggers are singletons. Code can always access a "
@@ -5457,25 +5508,25 @@ msgid ""
54575508"module (and not the class) is the unit of software decomposition."
54585509msgstr ""
54595510
5460- #: ../../howto/logging-cookbook.rst:4190
5511+ #: ../../howto/logging-cookbook.rst:4226
54615512msgid ""
54625513"Adding handlers other than :class:`~logging.NullHandler` to a logger in a "
54635514"library"
54645515msgstr ""
54655516
5466- #: ../../howto/logging-cookbook.rst:4192
5517+ #: ../../howto/logging-cookbook.rst:4228
54675518msgid ""
54685519"Configuring logging by adding handlers, formatters and filters is the "
54695520"responsibility of the application developer, not the library developer. If "
54705521"you are maintaining a library, ensure that you don't add handlers to any of "
54715522"your loggers other than a :class:`~logging.NullHandler` instance."
54725523msgstr ""
54735524
5474- #: ../../howto/logging-cookbook.rst:4198
5525+ #: ../../howto/logging-cookbook.rst:4234
54755526msgid "Creating a lot of loggers"
54765527msgstr ""
54775528
5478- #: ../../howto/logging-cookbook.rst:4200
5529+ #: ../../howto/logging-cookbook.rst:4236
54795530msgid ""
54805531"Loggers are singletons that are never freed during a script execution, and "
54815532"so creating lots of loggers will use up memory which can't then be freed. "
@@ -5486,38 +5537,38 @@ msgid ""
54865537"occasionally slightly more fine-grained than that)."
54875538msgstr ""
54885539
5489- #: ../../howto/logging-cookbook.rst:4211
5540+ #: ../../howto/logging-cookbook.rst:4247
54905541msgid "Other resources"
54915542msgstr "其他資源"
54925543
5493- #: ../../howto/logging-cookbook.rst:4215
5544+ #: ../../howto/logging-cookbook.rst:4251
54945545msgid "Module :mod:`logging`"
54955546msgstr ":mod:`logging` 模組"
54965547
5497- #: ../../howto/logging-cookbook.rst:4216
5548+ #: ../../howto/logging-cookbook.rst:4252
54985549msgid "API reference for the logging module."
54995550msgstr ""
55005551
5501- #: ../../howto/logging-cookbook.rst:4218
5552+ #: ../../howto/logging-cookbook.rst:4254
55025553msgid "Module :mod:`logging.config`"
55035554msgstr ":mod:`logging.config` 模組"
55045555
5505- #: ../../howto/logging-cookbook.rst:4219
5556+ #: ../../howto/logging-cookbook.rst:4255
55065557msgid "Configuration API for the logging module."
55075558msgstr ""
55085559
5509- #: ../../howto/logging-cookbook.rst:4221
5560+ #: ../../howto/logging-cookbook.rst:4257
55105561msgid "Module :mod:`logging.handlers`"
55115562msgstr ":mod:`logging.handlers` 模組"
55125563
5513- #: ../../howto/logging-cookbook.rst:4222
5564+ #: ../../howto/logging-cookbook.rst:4258
55145565msgid "Useful handlers included with the logging module."
55155566msgstr ""
55165567
5517- #: ../../howto/logging-cookbook.rst:4224
5568+ #: ../../howto/logging-cookbook.rst:4260
55185569msgid ":ref:`Basic Tutorial <logging-basic-tutorial>`"
55195570msgstr ":ref:`基礎教學 <logging-basic-tutorial>`"
55205571
5521- #: ../../howto/logging-cookbook.rst:4226
5572+ #: ../../howto/logging-cookbook.rst:4262
55225573msgid ":ref:`Advanced Tutorial <logging-advanced-tutorial>`"
55235574msgstr ":ref:`進階教學 <logging-advanced-tutorial>`"