Expand Up @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.13\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2025-07-07 10:49 +0000\n" "POT-Creation-Date: 2025-07-10 00:16 +0000\n" "PO-Revision-Date: 2018-05-23 14:36+0000\n" "Last-Translator: Adrian Liaw <adrianliaw2000@gmail.com>\n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" Expand Down Expand Up @@ -5368,56 +5368,107 @@ msgid "" "2025-07-02 13:54:47,234 DEBUG can't get fooled again" msgstr "" #: ../../howto/logging-cookbook.rst:4130 msgid "" "If, on the other hand, you are concerned about `log injection <https://owasp." "org/www-community/attacks/Log_Injection>`_, you can use a formatter which " "escapes newlines, as per the following example:" msgstr "" #: ../../howto/logging-cookbook.rst:4134 msgid "" "import logging\n" "\n" "logger = logging.getLogger(__name__)\n" "\n" "class EscapingFormatter(logging.Formatter):\n" " def format(self, record):\n" " s = super().format(record)\n" " return s.replace('\\n', r'\\n')\n" "\n" "if __name__ == '__main__':\n" " h = logging.StreamHandler()\n" " h.setFormatter(EscapingFormatter('%(asctime)s %(levelname)-9s " "%(message)s'))\n" " logging.basicConfig(level=logging.DEBUG, handlers = [h])\n" " logger.debug('Single line')\n" " logger.debug('Multiple lines:\\nfool me once ...')\n" " logger.debug('Another single line')\n" " logger.debug('Multiple lines:\\n%s', 'fool me ...\\ncan\\'t get fooled " "again')" msgstr "" #: ../../howto/logging-cookbook.rst:4154 msgid "" "You can, of course, use whatever escaping scheme makes the most sense for " "you. The script, when run, should produce output like this:" msgstr "" #: ../../howto/logging-cookbook.rst:4157 msgid "" "2025-07-09 06:47:33,783 DEBUG Single line\n" "2025-07-09 06:47:33,783 DEBUG Multiple lines:\\nfool me once ...\n" "2025-07-09 06:47:33,783 DEBUG Another single line\n" "2025-07-09 06:47:33,783 DEBUG Multiple lines:\\nfool me ...\\ncan't get " "fooled again" msgstr "" #: ../../howto/logging-cookbook.rst:4164 msgid "" "Escaping behaviour can't be the stdlib default , as it would break backwards " "compatibility." msgstr "" #: ../../howto/logging-cookbook.rst:4170 msgid "Patterns to avoid" msgstr "" #: ../../howto/logging-cookbook.rst:4136 #: ../../howto/logging-cookbook.rst:4172 msgid "" "Although the preceding sections have described ways of doing things you " "might need to do or deal with, it is worth mentioning some usage patterns " "which are *unhelpful*, and which should therefore be avoided in most cases. " "The following sections are in no particular order." msgstr "" #: ../../howto/logging-cookbook.rst:4142 #: ../../howto/logging-cookbook.rst:4178 msgid "Opening the same log file multiple times" msgstr "" #: ../../howto/logging-cookbook.rst:4144 #: ../../howto/logging-cookbook.rst:4180 msgid "" "On Windows, you will generally not be able to open the same file multiple " "times as this will lead to a \"file is in use by another process\" error. " "However, on POSIX platforms you'll not get any errors if you open the same " "file multiple times. This could be done accidentally, for example by:" msgstr "" #: ../../howto/logging-cookbook.rst:4149 #: ../../howto/logging-cookbook.rst:4185 msgid "" "Adding a file handler more than once which references the same file (e.g. by " "a copy/paste/forget-to-change error)." msgstr "" #: ../../howto/logging-cookbook.rst:4152 #: ../../howto/logging-cookbook.rst:4188 msgid "" "Opening two files that look different, as they have different names, but are " "the same because one is a symbolic link to the other." msgstr "" #: ../../howto/logging-cookbook.rst:4155 #: ../../howto/logging-cookbook.rst:4191 msgid "" "Forking a process, following which both parent and child have a reference to " "the same file. This might be through use of the :mod:`multiprocessing` " "module, for example." msgstr "" #: ../../howto/logging-cookbook.rst:4159 #: ../../howto/logging-cookbook.rst:4195 msgid "" "Opening a file multiple times might *appear* to work most of the time, but " "can lead to a number of problems in practice:" msgstr "" #: ../../howto/logging-cookbook.rst:4162 #: ../../howto/logging-cookbook.rst:4198 msgid "" "Logging output can be garbled because multiple threads or processes try to " "write to the same file. Although logging guards against concurrent use of " Expand All @@ -5426,7 +5477,7 @@ msgid "" "different handler instances which happen to point to the same file." msgstr "" #: ../../howto/logging-cookbook.rst:4168 #: ../../howto/logging-cookbook.rst:4204 msgid "" "An attempt to delete a file (e.g. during file rotation) silently fails, " "because there is another reference pointing to it. This can lead to " Expand All @@ -5436,17 +5487,17 @@ msgid "" "being supposedly in place." msgstr "" #: ../../howto/logging-cookbook.rst:4175 #: ../../howto/logging-cookbook.rst:4211 msgid "" "Use the techniques outlined in :ref:`multiple-processes` to circumvent such " "issues." msgstr "" #: ../../howto/logging-cookbook.rst:4179 #: ../../howto/logging-cookbook.rst:4215 msgid "Using loggers as attributes in a class or passing them as parameters" msgstr "" #: ../../howto/logging-cookbook.rst:4181 #: ../../howto/logging-cookbook.rst:4217 msgid "" "While there might be unusual cases where you'll need to do this, in general " "there is no point because loggers are singletons. Code can always access a " Expand All @@ -5457,25 +5508,25 @@ msgid "" "module (and not the class) is the unit of software decomposition." msgstr "" #: ../../howto/logging-cookbook.rst:4190 #: ../../howto/logging-cookbook.rst:4226 msgid "" "Adding handlers other than :class:`~logging.NullHandler` to a logger in a " "library" msgstr "" #: ../../howto/logging-cookbook.rst:4192 #: ../../howto/logging-cookbook.rst:4228 msgid "" "Configuring logging by adding handlers, formatters and filters is the " "responsibility of the application developer, not the library developer. If " "you are maintaining a library, ensure that you don't add handlers to any of " "your loggers other than a :class:`~logging.NullHandler` instance." msgstr "" #: ../../howto/logging-cookbook.rst:4198 #: ../../howto/logging-cookbook.rst:4234 msgid "Creating a lot of loggers" msgstr "" #: ../../howto/logging-cookbook.rst:4200 #: ../../howto/logging-cookbook.rst:4236 msgid "" "Loggers are singletons that are never freed during a script execution, and " "so creating lots of loggers will use up memory which can't then be freed. " Expand All @@ -5486,38 +5537,38 @@ msgid "" "occasionally slightly more fine-grained than that)." msgstr "" #: ../../howto/logging-cookbook.rst:4211 #: ../../howto/logging-cookbook.rst:4247 msgid "Other resources" msgstr "其他資源" #: ../../howto/logging-cookbook.rst:4215 #: ../../howto/logging-cookbook.rst:4251 msgid "Module :mod:`logging`" msgstr ":mod:`logging` 模組" #: ../../howto/logging-cookbook.rst:4216 #: ../../howto/logging-cookbook.rst:4252 msgid "API reference for the logging module." msgstr "" #: ../../howto/logging-cookbook.rst:4218 #: ../../howto/logging-cookbook.rst:4254 msgid "Module :mod:`logging.config`" msgstr ":mod:`logging.config` 模組" #: ../../howto/logging-cookbook.rst:4219 #: ../../howto/logging-cookbook.rst:4255 msgid "Configuration API for the logging module." msgstr "" #: ../../howto/logging-cookbook.rst:4221 #: ../../howto/logging-cookbook.rst:4257 msgid "Module :mod:`logging.handlers`" msgstr ":mod:`logging.handlers` 模組" #: ../../howto/logging-cookbook.rst:4222 #: ../../howto/logging-cookbook.rst:4258 msgid "Useful handlers included with the logging module." msgstr "" #: ../../howto/logging-cookbook.rst:4224 #: ../../howto/logging-cookbook.rst:4260 msgid ":ref:`Basic Tutorial <logging-basic-tutorial>`" msgstr ":ref:`基礎教學 <logging-basic-tutorial>`" #: ../../howto/logging-cookbook.rst:4226 #: ../../howto/logging-cookbook.rst:4262 msgid ":ref:`Advanced Tutorial <logging-advanced-tutorial>`" msgstr ":ref:`進階教學 <logging-advanced-tutorial>`"