7
7
msgstr ""
8
8
"Project-Id-Version : Python 3.13\n "
9
9
"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 "
11
11
"PO-Revision-Date : 2018-05-23 14:36+0000\n "
12
12
"
Last-Translator :
Adrian Liaw <[email protected] >\n "
13
13
"Language-Team : Chinese - TAIWAN (https://github.com/python/python-docs-zh- "
@@ -5368,56 +5368,107 @@ msgid ""
5368
5368
"2025-07-02 13:54:47,234 DEBUG can't get fooled again"
5369
5369
msgstr ""
5370
5370
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
+
5371
5378
#: ../../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
5372
5423
msgid "Patterns to avoid"
5373
5424
msgstr ""
5374
5425
5375
- #: ../../howto/logging-cookbook.rst:4136
5426
+ #: ../../howto/logging-cookbook.rst:4172
5376
5427
msgid ""
5377
5428
"Although the preceding sections have described ways of doing things you "
5378
5429
"might need to do or deal with, it is worth mentioning some usage patterns "
5379
5430
"which are *unhelpful*, and which should therefore be avoided in most cases. "
5380
5431
"The following sections are in no particular order."
5381
5432
msgstr ""
5382
5433
5383
- #: ../../howto/logging-cookbook.rst:4142
5434
+ #: ../../howto/logging-cookbook.rst:4178
5384
5435
msgid "Opening the same log file multiple times"
5385
5436
msgstr ""
5386
5437
5387
- #: ../../howto/logging-cookbook.rst:4144
5438
+ #: ../../howto/logging-cookbook.rst:4180
5388
5439
msgid ""
5389
5440
"On Windows, you will generally not be able to open the same file multiple "
5390
5441
"times as this will lead to a \" file is in use by another process\" error. "
5391
5442
"However, on POSIX platforms you'll not get any errors if you open the same "
5392
5443
"file multiple times. This could be done accidentally, for example by:"
5393
5444
msgstr ""
5394
5445
5395
- #: ../../howto/logging-cookbook.rst:4149
5446
+ #: ../../howto/logging-cookbook.rst:4185
5396
5447
msgid ""
5397
5448
"Adding a file handler more than once which references the same file (e.g. by "
5398
5449
"a copy/paste/forget-to-change error)."
5399
5450
msgstr ""
5400
5451
5401
- #: ../../howto/logging-cookbook.rst:4152
5452
+ #: ../../howto/logging-cookbook.rst:4188
5402
5453
msgid ""
5403
5454
"Opening two files that look different, as they have different names, but are "
5404
5455
"the same because one is a symbolic link to the other."
5405
5456
msgstr ""
5406
5457
5407
- #: ../../howto/logging-cookbook.rst:4155
5458
+ #: ../../howto/logging-cookbook.rst:4191
5408
5459
msgid ""
5409
5460
"Forking a process, following which both parent and child have a reference to "
5410
5461
"the same file. This might be through use of the :mod:`multiprocessing` "
5411
5462
"module, for example."
5412
5463
msgstr ""
5413
5464
5414
- #: ../../howto/logging-cookbook.rst:4159
5465
+ #: ../../howto/logging-cookbook.rst:4195
5415
5466
msgid ""
5416
5467
"Opening a file multiple times might *appear* to work most of the time, but "
5417
5468
"can lead to a number of problems in practice:"
5418
5469
msgstr ""
5419
5470
5420
- #: ../../howto/logging-cookbook.rst:4162
5471
+ #: ../../howto/logging-cookbook.rst:4198
5421
5472
msgid ""
5422
5473
"Logging output can be garbled because multiple threads or processes try to "
5423
5474
"write to the same file. Although logging guards against concurrent use of "
@@ -5426,7 +5477,7 @@ msgid ""
5426
5477
"different handler instances which happen to point to the same file."
5427
5478
msgstr ""
5428
5479
5429
- #: ../../howto/logging-cookbook.rst:4168
5480
+ #: ../../howto/logging-cookbook.rst:4204
5430
5481
msgid ""
5431
5482
"An attempt to delete a file (e.g. during file rotation) silently fails, "
5432
5483
"because there is another reference pointing to it. This can lead to "
@@ -5436,17 +5487,17 @@ msgid ""
5436
5487
"being supposedly in place."
5437
5488
msgstr ""
5438
5489
5439
- #: ../../howto/logging-cookbook.rst:4175
5490
+ #: ../../howto/logging-cookbook.rst:4211
5440
5491
msgid ""
5441
5492
"Use the techniques outlined in :ref:`multiple-processes` to circumvent such "
5442
5493
"issues."
5443
5494
msgstr ""
5444
5495
5445
- #: ../../howto/logging-cookbook.rst:4179
5496
+ #: ../../howto/logging-cookbook.rst:4215
5446
5497
msgid "Using loggers as attributes in a class or passing them as parameters"
5447
5498
msgstr ""
5448
5499
5449
- #: ../../howto/logging-cookbook.rst:4181
5500
+ #: ../../howto/logging-cookbook.rst:4217
5450
5501
msgid ""
5451
5502
"While there might be unusual cases where you'll need to do this, in general "
5452
5503
"there is no point because loggers are singletons. Code can always access a "
@@ -5457,25 +5508,25 @@ msgid ""
5457
5508
"module (and not the class) is the unit of software decomposition."
5458
5509
msgstr ""
5459
5510
5460
- #: ../../howto/logging-cookbook.rst:4190
5511
+ #: ../../howto/logging-cookbook.rst:4226
5461
5512
msgid ""
5462
5513
"Adding handlers other than :class:`~logging.NullHandler` to a logger in a "
5463
5514
"library"
5464
5515
msgstr ""
5465
5516
5466
- #: ../../howto/logging-cookbook.rst:4192
5517
+ #: ../../howto/logging-cookbook.rst:4228
5467
5518
msgid ""
5468
5519
"Configuring logging by adding handlers, formatters and filters is the "
5469
5520
"responsibility of the application developer, not the library developer. If "
5470
5521
"you are maintaining a library, ensure that you don't add handlers to any of "
5471
5522
"your loggers other than a :class:`~logging.NullHandler` instance."
5472
5523
msgstr ""
5473
5524
5474
- #: ../../howto/logging-cookbook.rst:4198
5525
+ #: ../../howto/logging-cookbook.rst:4234
5475
5526
msgid "Creating a lot of loggers"
5476
5527
msgstr ""
5477
5528
5478
- #: ../../howto/logging-cookbook.rst:4200
5529
+ #: ../../howto/logging-cookbook.rst:4236
5479
5530
msgid ""
5480
5531
"Loggers are singletons that are never freed during a script execution, and "
5481
5532
"so creating lots of loggers will use up memory which can't then be freed. "
@@ -5486,38 +5537,38 @@ msgid ""
5486
5537
"occasionally slightly more fine-grained than that)."
5487
5538
msgstr ""
5488
5539
5489
- #: ../../howto/logging-cookbook.rst:4211
5540
+ #: ../../howto/logging-cookbook.rst:4247
5490
5541
msgid "Other resources"
5491
5542
msgstr "其他資源"
5492
5543
5493
- #: ../../howto/logging-cookbook.rst:4215
5544
+ #: ../../howto/logging-cookbook.rst:4251
5494
5545
msgid "Module :mod:`logging`"
5495
5546
msgstr ":mod:`logging` 模組"
5496
5547
5497
- #: ../../howto/logging-cookbook.rst:4216
5548
+ #: ../../howto/logging-cookbook.rst:4252
5498
5549
msgid "API reference for the logging module."
5499
5550
msgstr ""
5500
5551
5501
- #: ../../howto/logging-cookbook.rst:4218
5552
+ #: ../../howto/logging-cookbook.rst:4254
5502
5553
msgid "Module :mod:`logging.config`"
5503
5554
msgstr ":mod:`logging.config` 模組"
5504
5555
5505
- #: ../../howto/logging-cookbook.rst:4219
5556
+ #: ../../howto/logging-cookbook.rst:4255
5506
5557
msgid "Configuration API for the logging module."
5507
5558
msgstr ""
5508
5559
5509
- #: ../../howto/logging-cookbook.rst:4221
5560
+ #: ../../howto/logging-cookbook.rst:4257
5510
5561
msgid "Module :mod:`logging.handlers`"
5511
5562
msgstr ":mod:`logging.handlers` 模組"
5512
5563
5513
- #: ../../howto/logging-cookbook.rst:4222
5564
+ #: ../../howto/logging-cookbook.rst:4258
5514
5565
msgid "Useful handlers included with the logging module."
5515
5566
msgstr ""
5516
5567
5517
- #: ../../howto/logging-cookbook.rst:4224
5568
+ #: ../../howto/logging-cookbook.rst:4260
5518
5569
msgid ":ref:`Basic Tutorial <logging-basic-tutorial>`"
5519
5570
msgstr ":ref:`基礎教學 <logging-basic-tutorial>`"
5520
5571
5521
- #: ../../howto/logging-cookbook.rst:4226
5572
+ #: ../../howto/logging-cookbook.rst:4262
5522
5573
msgid ":ref:`Advanced Tutorial <logging-advanced-tutorial>`"
5523
5574
msgstr ":ref:`進階教學 <logging-advanced-tutorial>`"
0 commit comments