-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathlogging-cookbook.po
1924 lines (1732 loc) · 109 KB
/
logging-cookbook.po
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# SOME DESCRIPTIVE TITLE.
# Copyright (C) 2001-2020, Python Software Foundation
# This file is distributed under the same license as the Python package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
# Translators:
# tomo, 2018
# mollinaca, 2020
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Python 3.6\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-02-09 18:48+0900\n"
"PO-Revision-Date: 2018-06-29 17:46+0000\n"
"Last-Translator: mollinaca, 2020\n"
"Language-Team: Japanese (https://www.transifex.com/python-doc/teams/5390/"
"ja/)\n"
"Language: ja\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n"
#: ../../howto/logging-cookbook.rst:5
msgid "Logging Cookbook"
msgstr "Logging クックブック"
#: ../../howto/logging-cookbook.rst:0
msgid "Author"
msgstr "著者"
#: ../../howto/logging-cookbook.rst:7
msgid "Vinay Sajip <vinay_sajip at red-dove dot com>"
msgstr "Vinay Sajip <vinay_sajip at red-dove dot com>"
#: ../../howto/logging-cookbook.rst:9
msgid ""
"This page contains a number of recipes related to logging, which have been "
"found useful in the past."
msgstr ""
"このページでは、過去に見つかった logging に関するいくつかの便利なレシピを紹介"
"します。"
#: ../../howto/logging-cookbook.rst:15
msgid "Using logging in multiple modules"
msgstr "複数のモジュールで logging を使う"
#: ../../howto/logging-cookbook.rst:17
msgid ""
"Multiple calls to ``logging.getLogger('someLogger')`` return a reference to "
"the same logger object. This is true not only within the same module, but "
"also across modules as long as it is in the same Python interpreter "
"process. It is true for references to the same object; additionally, "
"application code can define and configure a parent logger in one module and "
"create (but not configure) a child logger in a separate module, and all "
"logger calls to the child will pass up to the parent. Here is a main "
"module::"
msgstr ""
"``logging.getLogger('someLogger')`` の複数回の呼び出しは同じ logger への参照"
"を返します。これは同じ Python インタプリタプロセス上で動いている限り、一つの"
"モジュールの中からに限らず、モジュールをまたいでも当てはまります。同じオブ"
"ジェクトへの参照という点でも正しいです。さらに、一つのモジュールの中で親 "
"logger を定義して設定し、別のモジュールで子 logger を定義する (ただし設定はし"
"ない) ことが可能で、すべての子 logger への呼び出しは親にまで渡されます。まず"
"はメインのモジュールです::"
#: ../../howto/logging-cookbook.rst:55
msgid "Here is the auxiliary module::"
msgstr "そして補助モジュール (auxiliary module) がこちらです::"
#: ../../howto/logging-cookbook.rst:75
msgid "The output looks like this:"
msgstr "出力はこのようになります:"
#: ../../howto/logging-cookbook.rst:101
msgid "Logging from multiple threads"
msgstr "複数のスレッドからのロギング"
#: ../../howto/logging-cookbook.rst:103
msgid ""
"Logging from multiple threads requires no special effort. The following "
"example shows logging from the main (initial) thread and another thread::"
msgstr ""
"複数スレッドからのロギングでは特別に何かをする必要はありません。\n"
"次の例はmain (初期) スレッドとそれ以外のスレッドからのロギングの例です::"
#: ../../howto/logging-cookbook.rst:132
msgid "When run, the script should print something like the following:"
msgstr "実行すると、出力は以下のようになるはずです:"
#: ../../howto/logging-cookbook.rst:154
msgid ""
"This shows the logging output interspersed as one might expect. This "
"approach works for more threads than shown here, of course."
msgstr ""
"予想した通りかもしれませんが、ログ出力が散らばっているのが分かります。\n"
"もちろん、この手法はより多くのスレッドでも上手くいきます。"
#: ../../howto/logging-cookbook.rst:158
msgid "Multiple handlers and formatters"
msgstr "複数の handler と formatter"
#: ../../howto/logging-cookbook.rst:160
msgid ""
"Loggers are plain Python objects. The :meth:`~Logger.addHandler` method has "
"no minimum or maximum quota for the number of handlers you may add. "
"Sometimes it will be beneficial for an application to log all messages of "
"all severities to a text file while simultaneously logging errors or above "
"to the console. To set this up, simply configure the appropriate handlers. "
"The logging calls in the application code will remain unchanged. Here is a "
"slight modification to the previous simple module-based configuration "
"example::"
msgstr ""
"logger は通常の Python オブジェクトです。 :meth:`~Logger.addHandler` メソッド"
"は追加されるハンドラの個数について最小値も最大値も定めていません。時にアプリ"
"ケーションがすべての深刻度のすべてのメッセージをテキストファイルに記録しつ"
"つ、同時にエラーやそれ以上のものをコンソールに出力することが役に立ちます。こ"
"れを実現する方法は、単に適切なハンドラを設定するだけです。アプリケーション"
"コードの中のログ記録の呼び出しは変更されずに残ります。少し前に取り上げた単純"
"なモジュール式の例を少し変えるとこうなります::"
#: ../../howto/logging-cookbook.rst:193
msgid ""
"Notice that the 'application' code does not care about multiple handlers. "
"All that changed was the addition and configuration of a new handler named "
"*fh*."
msgstr ""
"'application' 部分のコードは複数の handler について何も気にしていないことに注"
"目してください。変更した箇所は新しい *fh* という名の handler を追加して設定し"
"たところがすべてです。"
#: ../../howto/logging-cookbook.rst:196
msgid ""
"The ability to create new handlers with higher- or lower-severity filters "
"can be very helpful when writing and testing an application. Instead of "
"using many ``print`` statements for debugging, use ``logger.debug``: Unlike "
"the print statements, which you will have to delete or comment out later, "
"the logger.debug statements can remain intact in the source code and remain "
"dormant until you need them again. At that time, the only change that needs "
"to happen is to modify the severity level of the logger and/or handler to "
"debug."
msgstr ""
"新しい handler を、異なる深刻度に対する filter と共に生成できることは、アプリ"
"ケーションを書いてテストを行うときとても助けになります。デバッグ用にたくさん"
"の ``print`` 文を使う代わりに ``logger.debug`` を使いましょう。あとで消したり"
"コメントアウトしたりしなければならない print 文と違って、logger.debug 命令は"
"ソースコードの中にそのまま残しておいて再び必要になるまで休眠させておけます。"
"その時必要になるのはただ logger および/または handler の深刻度の設定をいじる"
"ことだけです。"
#: ../../howto/logging-cookbook.rst:207
msgid "Logging to multiple destinations"
msgstr "複数の出力先にログを出力する"
#: ../../howto/logging-cookbook.rst:209
msgid ""
"Let's say you want to log to console and file with different message formats "
"and in differing circumstances. Say you want to log messages with levels of "
"DEBUG and higher to file, and those messages at level INFO and higher to the "
"console. Let's also assume that the file should contain timestamps, but the "
"console messages should not. Here's how you can achieve this::"
msgstr ""
"コンソールとファイルに、別々のメッセージ書式で、別々の状況に応じたログ出力を"
"行わせたいとしましょう。例えば DEBUG よりも高いレベルのメッセージはファイルに"
"記録し、INFO 以上のレベルのメッセージはコンソールに出力したいという場合です。"
"また、ファイルにはタイムスタンプを記録し、コンソールには出力しないとします。"
"以下のようにすれば、こうした挙動を実現できます::"
#: ../../howto/logging-cookbook.rst:247
msgid "When you run this, on the console you will see"
msgstr "これを実行すると、コンソールには以下のように出力されます。"
#: ../../howto/logging-cookbook.rst:256
msgid "and in the file you will see something like"
msgstr "そして、ファイルには以下のように出力されるはずです:"
#: ../../howto/logging-cookbook.rst:266
msgid ""
"As you can see, the DEBUG message only shows up in the file. The other "
"messages are sent to both destinations."
msgstr ""
"これを見て分かる通り、DEBUG メッセージはファイルだけに出力され、その他のメッ"
"セージは両方に出力されます。"
#: ../../howto/logging-cookbook.rst:269
msgid ""
"This example uses console and file handlers, but you can use any number and "
"combination of handlers you choose."
msgstr ""
"この例ではコンソールとファイルのハンドラだけを使っていますが、実際には任意の"
"数のハンドラや組み合わせを使えます。"
#: ../../howto/logging-cookbook.rst:274
msgid "Configuration server example"
msgstr "設定サーバの例"
#: ../../howto/logging-cookbook.rst:276
msgid "Here is an example of a module using the logging configuration server::"
msgstr "ログ記録設定サーバを使うモジュールの例です::"
#: ../../howto/logging-cookbook.rst:307
msgid ""
"And here is a script that takes a filename and sends that file to the "
"server, properly preceded with the binary-encoded length, as the new logging "
"configuration::"
msgstr ""
"そしてファイル名を受け取ってそのファイルをサーバに送るスクリプトですが、それ"
"に先だってバイナリエンコード長を新しいログ記録の設定として先に送っておきま"
"す::"
#: ../../howto/logging-cookbook.rst:330
msgid "Dealing with handlers that block"
msgstr "ブロックする handler を扱う"
#: ../../howto/logging-cookbook.rst:334
msgid ""
"Sometimes you have to get your logging handlers to do their work without "
"blocking the thread you're logging from. This is common in Web applications, "
"though of course it also occurs in other scenarios."
msgstr ""
"ときどき、logging を行っているスレッドをブロックせずに、handler が動くように"
"しないといけないときがあります。これは Web アプリケーションではよくあることで"
"すし、もちろん他のシナリオでも起きる話です。"
#: ../../howto/logging-cookbook.rst:338
msgid ""
"A common culprit which demonstrates sluggish behaviour is the :class:"
"`SMTPHandler`: sending emails can take a long time, for a number of reasons "
"outside the developer's control (for example, a poorly performing mail or "
"network infrastructure). But almost any network-based handler can block: "
"Even a :class:`SocketHandler` operation may do a DNS query under the hood "
"which is too slow (and this query can be deep in the socket library code, "
"below the Python layer, and outside your control)."
msgstr ""
"動作が鈍くなるときの元凶はたいてい、開発者のコントロール外にあるいくつもの理"
"由で (例えば、残念なパフォーマンスのメールやネットワークのインフラ) 、 :"
"class:`SMTPHandler`: が電子メールを送るのに時間がかかることです。しかし、ほと"
"んどのネットワークをまたぐ handler はブロックする可能性があります: :class:"
"`SocketHandler` による処理でさえ、裏で DNS への問い合わせというとても遅い処理"
"を行うことがあります (そしてこの問い合わせ処理は、 Python の層より下のあなた"
"の手の届かない、ソケットライブラリの深いところにある可能性もあります)。"
#: ../../howto/logging-cookbook.rst:346
msgid ""
"One solution is to use a two-part approach. For the first part, attach only "
"a :class:`QueueHandler` to those loggers which are accessed from performance-"
"critical threads. They simply write to their queue, which can be sized to a "
"large enough capacity or initialized with no upper bound to their size. The "
"write to the queue will typically be accepted quickly, though you will "
"probably need to catch the :exc:`queue.Full` exception as a precaution in "
"your code. If you are a library developer who has performance-critical "
"threads in their code, be sure to document this (together with a suggestion "
"to attach only ``QueueHandlers`` to your loggers) for the benefit of other "
"developers who will use your code."
msgstr ""
"解決策の1つは、2パートに分離したアプローチを用いることです。最初のパートは、"
"パフォーマンスが重要なスレッドからアクセスされる、 :class:`QueueHandler` だけ"
"をアタッチした logger です。この logger は単に、十分大きい、あるいは無制限の"
"容量を持ったキューに書き込むだけです。キューへの書き込みは通常すぐに完了しま"
"すが、念の為に :exc:`queue.Full` 例外をキャッチする必要があるかもしれません。"
"もしパフォーマンスクリティカルなスレッドを持つライブラリの開発者であるなら、"
"このことを (``QueueHandler`` だけをアタッチした logger についての言及を添え"
"て) ドキュメントに書いておきましょう。"
#: ../../howto/logging-cookbook.rst:357
msgid ""
"The second part of the solution is :class:`QueueListener`, which has been "
"designed as the counterpart to :class:`QueueHandler`. A :class:"
"`QueueListener` is very simple: it's passed a queue and some handlers, and "
"it fires up an internal thread which listens to its queue for LogRecords "
"sent from ``QueueHandlers`` (or any other source of ``LogRecords``, for that "
"matter). The ``LogRecords`` are removed from the queue and passed to the "
"handlers for processing."
msgstr ""
"2つ目のパートは :class:`QueueHandler` の対向として作られた :class:"
"`QueueListener` です。 :class:`QueueListener` はとてもシンプルで、キューと "
"handler を渡され、内部で ``QueueHandler`` (もしくは他の ``LogRecord`` の出力"
"元) から送られた LogRecord をキューから受け取るスレッドを起動します。 "
"``LogRecord`` をキューから取り出して、 handler に渡して処理させます。"
#: ../../howto/logging-cookbook.rst:365
msgid ""
"The advantage of having a separate :class:`QueueListener` class is that you "
"can use the same instance to service multiple ``QueueHandlers``. This is "
"more resource-friendly than, say, having threaded versions of the existing "
"handler classes, which would eat up one thread per handler for no particular "
"benefit."
msgstr ""
"分離した :class:`QueueListener` クラスを持つメリットは、複数の "
"``QueueHandler`` に対して1つのインスタンスで logging できることです。既存の "
"handler のスレッド利用版を使って handler ごとにスレッドを持つよりはずっとリ"
"ソースにやさしくなります。"
#: ../../howto/logging-cookbook.rst:370
msgid "An example of using these two classes follows (imports omitted)::"
msgstr "この2つのクラスを利用する例です (import は省略)::"
#: ../../howto/logging-cookbook.rst:388
msgid "which, when run, will produce:"
msgstr "実行すると次のように出力します:"
#: ../../howto/logging-cookbook.rst:394
msgid ""
"Prior to Python 3.5, the :class:`QueueListener` always passed every message "
"received from the queue to every handler it was initialized with. (This was "
"because it was assumed that level filtering was all done on the other side, "
"where the queue is filled.) From 3.5 onwards, this behaviour can be changed "
"by passing a keyword argument ``respect_handler_level=True`` to the "
"listener's constructor. When this is done, the listener compares the level "
"of each message with the handler's level, and only passes a message to a "
"handler if it's appropriate to do so."
msgstr ""
"Python 3.5 以前は、 :class:`QueueListener` クラスは常にキューから受け取った"
"メッセージを、初期化元となっているそれぞれのハンドラーに受け渡していました。 "
"( というのも、レベルフィルターリングは別サイド、つまり、キューが満たされてい"
"る場所で処理されるということが想定されているからです) Python 3.5以降では、"
"キーワードとなる引数 ``respect_handler_level=True`` をリスナーのコントラク"
"ターに受け渡すことで、この挙動を変更することができるようになっています。これ"
"が行われると、各メッセージのレベルをハンドラーのレベルと比較して、そうするこ"
"とが適切な場合のみ、メッセージをハンドラーに渡します。"
#: ../../howto/logging-cookbook.rst:407
msgid "Sending and receiving logging events across a network"
msgstr "ネットワーク越しの logging イベントの送受信"
#: ../../howto/logging-cookbook.rst:409
msgid ""
"Let's say you want to send logging events across a network, and handle them "
"at the receiving end. A simple way of doing this is attaching a :class:"
"`SocketHandler` instance to the root logger at the sending end::"
msgstr ""
"ログイベントをネットワーク越しに送信し、受信端でそれを処理したいとしましょ"
"う。 :class:`SocketHandler` インスタンスを送信端の root logger にアタッチすれ"
"ば、簡単に実現できます::"
#: ../../howto/logging-cookbook.rst:437
msgid ""
"At the receiving end, you can set up a receiver using the :mod:"
"`socketserver` module. Here is a basic working example::"
msgstr ""
"受信端では :mod:`socketserver` モジュールを使って受信プログラムを作成しておき"
"ます。簡単な実用プログラムを以下に示します::"
#: ../../howto/logging-cookbook.rst:525
msgid ""
"First run the server, and then the client. On the client side, nothing is "
"printed on the console; on the server side, you should see something like:"
msgstr ""
"先にサーバを起動しておき、次にクライアントを起動します。クライアント側では、"
"コンソールには何も出力されません; サーバ側では以下のようなメッセージを目にす"
"るはずです::"
#: ../../howto/logging-cookbook.rst:537
msgid ""
"Note that there are some security issues with pickle in some scenarios. If "
"these affect you, you can use an alternative serialization scheme by "
"overriding the :meth:`~handlers.SocketHandler.makePickle` method and "
"implementing your alternative there, as well as adapting the above script to "
"use your alternative serialization."
msgstr ""
"特定のシナリオでは pickle にはいくつかのセキュリティ上の問題があることに注意"
"してください。これが問題になる場合、 :meth:`~handlers.SocketHandler."
"makePickle` メソッドをオーバーライドして代替手段を実装することで異なるシリア"
"ライズ手法を使用できます。代替シリアライズ手法を使うように上記のスクリプトを"
"修正することもできます。"
#: ../../howto/logging-cookbook.rst:547
msgid "Adding contextual information to your logging output"
msgstr "コンテキスト情報をログ記録出力に付加する"
#: ../../howto/logging-cookbook.rst:549
msgid ""
"Sometimes you want logging output to contain contextual information in "
"addition to the parameters passed to the logging call. For example, in a "
"networked application, it may be desirable to log client-specific "
"information in the log (e.g. remote client's username, or IP address). "
"Although you could use the *extra* parameter to achieve this, it's not "
"always convenient to pass the information in this way. While it might be "
"tempting to create :class:`Logger` instances on a per-connection basis, this "
"is not a good idea because these instances are not garbage collected. While "
"this is not a problem in practice, when the number of :class:`Logger` "
"instances is dependent on the level of granularity you want to use in "
"logging an application, it could be hard to manage if the number of :class:"
"`Logger` instances becomes effectively unbounded."
msgstr ""
"時にはログ記録出力にログ関数の呼び出し時に渡されたパラメータに加えてコンテキ"
"スト情報を含めたいこともあるでしょう。たとえば、ネットワークアプリケーション"
"で、クライアント固有の情報 (例: リモートクライアントの名前、 IP アドレス) も"
"ログ記録に残しておきたいと思ったとしましょう。 *extra* パラメータをこの目的に"
"使うこともできますが、いつでもこの方法で情報を渡すのが便利なやり方とも限りま"
"せん。また接続ごとに :class:`Logger` インスタンスを生成する誘惑に駆られるかも"
"しれませんが、生成した :class:`Logger` インスタンスはガーベジコレクションで回"
"収されないので、これは良いアイデアとは言えません。この例は現実的な問題ではな"
"いかもしれませんが、 :class:`Logger` インスタンスの個数がアプリケーションの中"
"でログ記録が行われるレベルの粒度に依存する場合、 :class:`Logger` インスタンス"
"の個数が事実上無制限にならないと、管理が難しくなります。"
#: ../../howto/logging-cookbook.rst:564
msgid "Using LoggerAdapters to impart contextual information"
msgstr "LoggerAdapter を使ったコンテキスト情報の伝達"
#: ../../howto/logging-cookbook.rst:566
msgid ""
"An easy way in which you can pass contextual information to be output along "
"with logging event information is to use the :class:`LoggerAdapter` class. "
"This class is designed to look like a :class:`Logger`, so that you can call :"
"meth:`debug`, :meth:`info`, :meth:`warning`, :meth:`error`, :meth:"
"`exception`, :meth:`critical` and :meth:`log`. These methods have the same "
"signatures as their counterparts in :class:`Logger`, so you can use the two "
"types of instances interchangeably."
msgstr ""
"logging イベントの情報と一緒に出力されるコンテキスト情報を渡す簡単な方法"
"は、 :class:`LoggerAdapter` を使うことです。このクラスは :class:`Logger` のよ"
"うに見えるように設計されていて、 :meth:`debug`, :meth:`info`, :meth:"
"`warning`, :meth:`error`, :meth:`exception`, :meth:`critical`, :meth:`log` の"
"各メソッドを呼び出せるようになっています。これらのメソッドは対応する :class:"
"`Logger` のメソッドと同じ引数を取るので、二つの型を取り替えて使うことができま"
"す。"
#: ../../howto/logging-cookbook.rst:574
msgid ""
"When you create an instance of :class:`LoggerAdapter`, you pass it a :class:"
"`Logger` instance and a dict-like object which contains your contextual "
"information. When you call one of the logging methods on an instance of :"
"class:`LoggerAdapter`, it delegates the call to the underlying instance of :"
"class:`Logger` passed to its constructor, and arranges to pass the "
"contextual information in the delegated call. Here's a snippet from the code "
"of :class:`LoggerAdapter`::"
msgstr ""
":class:`LoggerAdapter` のインスタンスを生成する際には、 :class:`Logger` イン"
"スタンスとコンテキスト情報を収めた辞書風 (dict-like) のオブジェクトを渡しま"
"す。 :class:`LoggerAdapter` のログ記録メソッドを呼び出すと、呼び出しをコンス"
"トラクタに渡された配下の :class:`Logger` インスタンスに委譲し、その際コンテキ"
"スト情報をその委譲された呼び出しに埋め込みます。 :class:`LoggerAdapter` の"
"コードから少し抜き出してみます::"
#: ../../howto/logging-cookbook.rst:590
msgid ""
"The :meth:`~LoggerAdapter.process` method of :class:`LoggerAdapter` is where "
"the contextual information is added to the logging output. It's passed the "
"message and keyword arguments of the logging call, and it passes back "
"(potentially) modified versions of these to use in the call to the "
"underlying logger. The default implementation of this method leaves the "
"message alone, but inserts an 'extra' key in the keyword argument whose "
"value is the dict-like object passed to the constructor. Of course, if you "
"had passed an 'extra' keyword argument in the call to the adapter, it will "
"be silently overwritten."
msgstr ""
":class:`LoggerAdapter` の :meth:`~LoggerAdapter.process` メソッドがコンテキス"
"ト情報をログ出力に加える場所です。そこではログ記録呼び出しのメッセージとキー"
"ワード引数が渡され、加工された (可能性のある) それらの情報を配下のロガーへの"
"呼び出しに渡し直します。このメソッドのデフォルト実装ではメッセージは元のまま"
"ですが、キーワード引数にはコンストラクタに渡された辞書風オブジェクトを値とし"
"て \"extra\" キーが挿入されます。もちろん、呼び出し時に \"extra\" キーワード"
"を使った場合には何事もなかったかのように上書きされます。"
#: ../../howto/logging-cookbook.rst:599
msgid ""
"The advantage of using 'extra' is that the values in the dict-like object "
"are merged into the :class:`LogRecord` instance's __dict__, allowing you to "
"use customized strings with your :class:`Formatter` instances which know "
"about the keys of the dict-like object. If you need a different method, e.g. "
"if you want to prepend or append the contextual information to the message "
"string, you just need to subclass :class:`LoggerAdapter` and override :meth:"
"`~LoggerAdapter.process` to do what you need. Here is a simple example::"
msgstr ""
"\"extra\" を用いる利点は辞書風オブジェクトの中の値が :class:`LogRecord` イン"
"スタンスの __dict__ にマージされることで、辞書風オブジェクトのキーを知ってい"
"る :class:`Formatter` を用意して文字列をカスタマイズするようにできることで"
"す。それ以外のメソッドが必要なとき、たとえばコンテキスト情報をメッセージの前"
"や後ろにつなげたい場合には、 :class:`LoggerAdapter` から :meth:"
"`~LoggerAdapter.process` を望むようにオーバライドしたサブクラスを作ることが必"
"要なだけです。次に挙げるのはこのクラスを使った例で、コンストラクタで使われる"
"「辞書風」オブジェクトにどの振る舞いが必要なのかも示しています::"
#: ../../howto/logging-cookbook.rst:615
msgid "which you can use like this::"
msgstr "これを次のように使うことができます::"
#: ../../howto/logging-cookbook.rst:620
msgid ""
"Then any events that you log to the adapter will have the value of "
"``some_conn_id`` prepended to the log messages."
msgstr ""
"これで、この adapter 経由でログした全てのイベントに対して、``some_conn_id`` "
"の値がログメッセージの前に追加されます。"
#: ../../howto/logging-cookbook.rst:624
msgid "Using objects other than dicts to pass contextual information"
msgstr "コンテキスト情報を渡すために dict 以外のオブジェクトを使う"
#: ../../howto/logging-cookbook.rst:626
msgid ""
"You don't need to pass an actual dict to a :class:`LoggerAdapter` - you "
"could pass an instance of a class which implements ``__getitem__`` and "
"``__iter__`` so that it looks like a dict to logging. This would be useful "
"if you want to generate values dynamically (whereas the values in a dict "
"would be constant)."
msgstr ""
":class:`LoggerAdapter` に渡すのは本物の dict でなくても構いません。 "
"``__getitem__`` と ``__iter__`` を実装していて logging が辞書のように扱えるク"
"ラスのインスタンスを利用することができます。これは (dict の値が固定されるのに"
"対して) 値を動的に生成できるので便利です。"
#: ../../howto/logging-cookbook.rst:635
msgid "Using Filters to impart contextual information"
msgstr "Filter を使ったコンテキスト情報の伝達"
#: ../../howto/logging-cookbook.rst:637
msgid ""
"You can also add contextual information to log output using a user-defined :"
"class:`Filter`. ``Filter`` instances are allowed to modify the "
"``LogRecords`` passed to them, including adding additional attributes which "
"can then be output using a suitable format string, or if needed a custom :"
"class:`Formatter`."
msgstr ""
"ユーザ定義の :class:`Filter` を使ってログ出力にコンテキスト情報を加えることも"
"できます。 ``Filter`` インスタンスは、渡された ``LogRecords`` を修正すること"
"ができます。これにより、適切なフォーマット文字列や必要なら :class:"
"`Formatter` を使って、出力となる属性を新しく追加することも出来ます。"
#: ../../howto/logging-cookbook.rst:642
msgid ""
"For example in a web application, the request being processed (or at least, "
"the interesting parts of it) can be stored in a threadlocal (:class:"
"`threading.local`) variable, and then accessed from a ``Filter`` to add, "
"say, information from the request - say, the remote IP address and remote "
"user's username - to the ``LogRecord``, using the attribute names 'ip' and "
"'user' as in the ``LoggerAdapter`` example above. In that case, the same "
"format string can be used to get similar output to that shown above. Here's "
"an example script::"
msgstr ""
"例えば、web アプリケーションで、処理されるリクエスト (または、少なくともその"
"重要な部分) は、スレッドローカル (:class:`threading.local`) な変数に保存し"
"て、 ``Filter`` からアクセスすることで、 ``LogRecord`` にリクエストの情報を追"
"加できます。例えば、リモート IP アドレスやリモートユーザのユーザ名にアクセス"
"したいなら、上述の ``LoggerAdapter`` の例のように属性名 'ip' や 'user' を使う"
"といったようにです。その場合、同じフォーマット文字列を使って以下に示すように"
"似たような出力を得られます。これはスクリプトの例です::"
#: ../../howto/logging-cookbook.rst:688
msgid "which, when run, produces something like:"
msgstr "実行すると、以下のようになります:"
#: ../../howto/logging-cookbook.rst:709
msgid "Logging to a single file from multiple processes"
msgstr "複数のプロセスからの単一ファイルへのログ記録"
#: ../../howto/logging-cookbook.rst:711
msgid ""
"Although logging is thread-safe, and logging to a single file from multiple "
"threads in a single process *is* supported, logging to a single file from "
"*multiple processes* is *not* supported, because there is no standard way to "
"serialize access to a single file across multiple processes in Python. If "
"you need to log to a single file from multiple processes, one way of doing "
"this is to have all the processes log to a :class:`~handlers.SocketHandler`, "
"and have a separate process which implements a socket server which reads "
"from the socket and logs to file. (If you prefer, you can dedicate one "
"thread in one of the existing processes to perform this function.) :ref:"
"`This section <network-logging>` documents this approach in more detail and "
"includes a working socket receiver which can be used as a starting point for "
"you to adapt in your own applications."
msgstr ""
"ログ記録はスレッドセーフであり、単一プロセスの複数のスレッドからの単一ファイ"
"ルへのログ記録はサポート *されています* が、 *複数プロセス* からの単一ファイ"
"ルへのログ記録はサポート *されません* 。なぜなら、複数のプロセスをまたいで単"
"一のファイルへのアクセスを直列化する標準の方法が Python には存在しないからで"
"す。複数のプロセスから単一ファイルへログ記録しなければならないなら、最も良い"
"方法は、すべてのプロセスが :class:`~handlers.SocketHandler` に対してログ記録"
"を行い、独立したプロセスとしてソケットサーバを動かすことです。ソケットサーバ"
"はソケットから読み取ってファイルにログを書き出します。 (この機能を実行するた"
"めに、既存のプロセスの 1 つのスレッドを割り当てることもできます) :ref:`この"
"節 <network-logging>` では、このアプローチをさらに詳細に文書化しています。動"
"作するソケット受信プログラムが含まれているので、アプリケーションに組み込むた"
"めの出発点として使用できるでしょう。"
#: ../../howto/logging-cookbook.rst:724
msgid ""
"If you are using a recent version of Python which includes the :mod:"
"`multiprocessing` module, you could write your own handler which uses the :"
"class:`~multiprocessing.Lock` class from this module to serialize access to "
"the file from your processes. The existing :class:`FileHandler` and "
"subclasses do not make use of :mod:`multiprocessing` at present, though they "
"may do so in the future. Note that at present, the :mod:`multiprocessing` "
"module does not provide working lock functionality on all platforms (see "
"https://bugs.python.org/issue3770)."
msgstr ""
":mod:`multiprocessing` モジュールを含む最近のバージョンの Python を使用してい"
"るなら、複数のプロセスからファイルへのアクセスを直列化するために :class:"
"`~multiprocessing.Lock` クラスを使って独自のハンドラを書くことができます。既"
"存の :class:`FileHandler` とそのサブクラスは現在のところ :mod:"
"`multiprocessing` を利用していませんが、将来は利用するようになるかもしれませ"
"ん。現在のところ :mod:`multiprocessing` モジュールが提供するロック機能はすべ"
"てのプラットホームで動作するわけではないことに注意してください (https://bugs."
"python.org/issue3770 参照)。"
#: ../../howto/logging-cookbook.rst:735
msgid ""
"Alternatively, you can use a ``Queue`` and a :class:`QueueHandler` to send "
"all logging events to one of the processes in your multi-process "
"application. The following example script demonstrates how you can do this; "
"in the example a separate listener process listens for events sent by other "
"processes and logs them according to its own logging configuration. Although "
"the example only demonstrates one way of doing it (for example, you may want "
"to use a listener thread rather than a separate listener process -- the "
"implementation would be analogous) it does allow for completely different "
"logging configurations for the listener and the other processes in your "
"application, and can be used as the basis for code meeting your own specific "
"requirements::"
msgstr ""
"別の方法として、 ``Queue`` と :class:`QueueHandler` を使って、マルチプロセス"
"アプリケーションの1つのプロセスに全ての logging イベントを送る事ができます。"
"次の例はこれを行う方法を示します。この例では独立した listener プロセスが他の"
"プロセスから送られた event を受け取り、それを独自の logging 設定にしたがって"
"保存します。この例は実装の方法の1つを示しているだけ (例えば、 listener プロセ"
"スを分離する代わりに listener スレッドを使うこともできます) ですが、これは "
"listener とアプリケーション内の他のプロセスで完全に異なる設定を使う例になって"
"いるので、各自の要求に応じたコードを書く叩き台になるでしょう::"
#: ../../howto/logging-cookbook.rst:851
msgid ""
"A variant of the above script keeps the logging in the main process, in a "
"separate thread::"
msgstr "上のスクリプトの亜種で、logging をメインプロセスの別スレッドで行う例::"
#: ../../howto/logging-cookbook.rst:946
msgid ""
"This variant shows how you can e.g. apply configuration for particular "
"loggers - e.g. the ``foo`` logger has a special handler which stores all "
"events in the ``foo`` subsystem in a file ``mplog-foo.log``. This will be "
"used by the logging machinery in the main process (even though the logging "
"events are generated in the worker processes) to direct the messages to the "
"appropriate destinations."
msgstr ""
"こちらは特定の logger に設定を適用する例になっています。``foo`` logger は "
"``foo`` サブシステムの中の全てのイベントを ``mplog-foo.log`` に保存する特別"
"な handler を持っています。これはメインプロセス側の log 処理で使われ、"
"(logging イベントは worker プロセス側で生成されますが) 各メッセージを適切な出"
"力先に出力します。"
#: ../../howto/logging-cookbook.rst:953
msgid "Using file rotation"
msgstr "ファイルをローテートする"
#: ../../howto/logging-cookbook.rst:958
msgid ""
"Sometimes you want to let a log file grow to a certain size, then open a new "
"file and log to that. You may want to keep a certain number of these files, "
"and when that many files have been created, rotate the files so that the "
"number of files and the size of the files both remain bounded. For this "
"usage pattern, the logging package provides a :class:`~handlers."
"RotatingFileHandler`::"
msgstr ""
"ログファイルがある大きさに達したら、新しいファイルを開いてそこにログを取りた"
"いことがあります。そのファイルをある数だけ残し、その数のファイルが生成された"
"らファイルを循環し、ファイルの数も大きさも制限したいこともあるでしょう。この"
"利用パターンのために、logging パッケージは :class:`~handlers."
"RotatingFileHandler` を提供しています::"
#: ../../howto/logging-cookbook.rst:990
msgid ""
"The result should be 6 separate files, each with part of the log history for "
"the application:"
msgstr ""
#: ../../howto/logging-cookbook.rst:1002
msgid ""
"The most current file is always :file:`logging_rotatingfile_example.out`, "
"and each time it reaches the size limit it is renamed with the suffix "
"``.1``. Each of the existing backup files is renamed to increment the suffix "
"(``.1`` becomes ``.2``, etc.) and the ``.6`` file is erased."
msgstr ""
"最新のファイルはいつでも :file:`logging_rotatingfile_example.out` で、サイズ"
"の上限に達するたびに拡張子 ``.1`` を付けた名前に改名されます。既にあるバック"
"アップファイルはその拡張子がインクリメントされ (``.1`` が ``.2`` になるな"
"ど)、 ``.6`` ファイルは消去されます。"
#: ../../howto/logging-cookbook.rst:1007
msgid ""
"Obviously this example sets the log length much too small as an extreme "
"example. You would want to set *maxBytes* to an appropriate value."
msgstr ""
"明らかに、ここでは極端な例示のためにファイルの大きさをかなり小さな値に設定し"
"ています。実際に使うときは *maxBytes* を適切な値に設定してください。"
#: ../../howto/logging-cookbook.rst:1013
msgid "Use of alternative formatting styles"
msgstr "別の format スタイルを利用する"
#: ../../howto/logging-cookbook.rst:1015
msgid ""
"When logging was added to the Python standard library, the only way of "
"formatting messages with variable content was to use the %-formatting "
"method. Since then, Python has gained two new formatting approaches: :class:"
"`string.Template` (added in Python 2.4) and :meth:`str.format` (added in "
"Python 2.6)."
msgstr ""
"logging が Python 標準ライブラリに追加された時、メッセージを動的な内容で"
"フォーマットする唯一の方法は % を使ったフォーマットでした。その後、 Python に"
"は新しい文字列フォーマット機構として :class:`string.Template` (Python 2.4 で"
"追加) と :meth:`str.format` (Python 2.6 で追加) が加わりました。"
#: ../../howto/logging-cookbook.rst:1021
msgid ""
"Logging (as of 3.2) provides improved support for these two additional "
"formatting styles. The :class:`Formatter` class been enhanced to take an "
"additional, optional keyword parameter named ``style``. This defaults to "
"``'%'``, but other possible values are ``'{'`` and ``'$'``, which correspond "
"to the other two formatting styles. Backwards compatibility is maintained by "
"default (as you would expect), but by explicitly specifying a style "
"parameter, you get the ability to specify format strings which work with :"
"meth:`str.format` or :class:`string.Template`. Here's an example console "
"session to show the possibilities:"
msgstr ""
"logging は (3.2 から) この2つの追加されたフォーマット方法をサポートしていま"
"す。 :class:`Formatter` クラスが ``style`` という名前のオプションのキーワード"
"引数を受け取ります。このデフォルト値は ``'%'`` ですが、他に ``'{'`` と "
"``'$'`` が指定可能で、それぞれのフォーマット方法に対応しています。後方互換性"
"はデフォルト値によって維持されていますが、明示的に style 引数を指定すること"
"で、 :meth:`str.format` か :class:`string.Template` を使った format を指定す"
"る事ができます。次の例はこの機能を使ってみています:"
#: ../../howto/logging-cookbook.rst:1055
msgid ""
"Note that the formatting of logging messages for final output to logs is "
"completely independent of how an individual logging message is constructed. "
"That can still use %-formatting, as shown here::"
msgstr ""
"最終的に出力されるログメッセージの format と、各メッセージを生成する部分は完"
"全に独立していることに注意してください。次の例でわかるように、メッセージを生"
"成する部分では % を使い続けています::"
#: ../../howto/logging-cookbook.rst:1063
msgid ""
"Logging calls (``logger.debug()``, ``logger.info()`` etc.) only take "
"positional parameters for the actual logging message itself, with keyword "
"parameters used only for determining options for how to handle the actual "
"logging call (e.g. the ``exc_info`` keyword parameter to indicate that "
"traceback information should be logged, or the ``extra`` keyword parameter "
"to indicate additional contextual information to be added to the log). So "
"you cannot directly make logging calls using :meth:`str.format` or :class:"
"`string.Template` syntax, because internally the logging package uses %-"
"formatting to merge the format string and the variable arguments. There "
"would no changing this while preserving backward compatibility, since all "
"logging calls which are out there in existing code will be using %-format "
"strings."
msgstr ""
"logging の呼び出し (``logger.debug()`` や ``logger.info()`` など) は、ログ"
"メッセージのために位置引数しか受け取らず、キーワード引数はそれを処理するとき"
"のオプションを指定するためだけに使われます。 (例えば、 ``exc_info`` キーワー"
"ド引数を使ってログを取るトレースバック情報を指定したり、 ``extra`` キーワード"
"引数を使ってログに付与する追加のコンテキスト情報を指定します。) logging パッ"
"ケージは内部で % を使って format 文字列と引数をマージしているので、 :meth:"
"`str.format` や :class:`string.Template` を使って logging を呼び出す事はでき"
"ません。既存の logging 呼び出しは %-format を使っているので、後方互換性のため"
"にこの部分を変更することはできません。"
#: ../../howto/logging-cookbook.rst:1076
msgid ""
"There is, however, a way that you can use {}- and $- formatting to construct "
"your individual log messages. Recall that for a message you can use an "
"arbitrary object as a message format string, and that the logging package "
"will call ``str()`` on that object to get the actual format string. Consider "
"the following two classes::"
msgstr ""
"しかし、{} や $ を使ってログメッセージをフォーマットする方法はあります。ログ"
"メッセージには任意のオブジェクトを format 文字列として渡すことができ、"
"logging パッケージはそのオブジェクトに対して ``str()`` を使って実際の format "
"文字列を生成します。次の2つのクラスを見てください::"
#: ../../howto/logging-cookbook.rst:1100
msgid ""
"Either of these can be used in place of a format string, to allow {}- or $-"
"formatting to be used to build the actual \"message\" part which appears in "
"the formatted log output in place of \"%(message)s\" or \"{message}\" or "
"\"$message\". It's a little unwieldy to use the class names whenever you "
"want to log something, but it's quite palatable if you use an alias such as "
"__ (double underscore --- not to be confused with _, the single underscore "
"used as a synonym/alias for :func:`gettext.gettext` or its brethren)."
msgstr ""
"どちらのクラスも format 文字列の代わりに利用して、 {} や $ を使って実際のログ"
"の \"%(message)s\", \"{message}\", \"$message\" で指定された \"message\" 部分"
"を生成することができます。これは何かログを取りたいときに常に使うには使いにく"
"いクラス名ですが、 __ (アンダースコア2つ --- :func:`gettext.gettext` やその仲"
"間によくエイリアスとして使われるアンダースコア1つと混同しないように) などの使"
"いやすいエイリアスを使うことができます。"
#: ../../howto/logging-cookbook.rst:1108
msgid ""
"The above classes are not included in Python, though they're easy enough to "
"copy and paste into your own code. They can be used as follows (assuming "
"that they're declared in a module called ``wherever``):"
msgstr ""
"上のクラスは Python には含まれませんが、自分のコードにコピペして使うのは簡単"
"です。これらは次の例のようにして利用できます。(上のクラスが ``wherever`` とい"
"うモジュールで定義されていると仮定します):"
#: ../../howto/logging-cookbook.rst:1130
msgid ""
"While the above examples use ``print()`` to show how the formatting works, "
"you would of course use ``logger.debug()`` or similar to actually log using "
"this approach."
msgstr ""
"上の例ではフォーマットの動作を示すために ``print()`` を使っていますが、もちろ"
"ん実際にこの方法でログを出力するには ``logger.debug()`` などを使います。"
#: ../../howto/logging-cookbook.rst:1134
msgid ""
"One thing to note is that you pay no significant performance penalty with "
"this approach: the actual formatting happens not when you make the logging "
"call, but when (and if) the logged message is actually about to be output to "
"a log by a handler. So the only slightly unusual thing which might trip you "
"up is that the parentheses go around the format string and the arguments, "
"not just the format string. That's because the __ notation is just syntax "
"sugar for a constructor call to one of the XXXMessage classes."
msgstr ""
"注意点として、この方法には大きなパフォーマンスのペナルティはありません。実際"
"のフォーマット操作は logging の呼び出し時ではなくて、メッセージが実際に "
"handler によって出力されるときに起こります。(出力されないならフォーマットもさ"
"れません) そのため、この方法で注意しないといけないのは、追加の括弧がフォー"
"マット文字列だけではなく引数も囲わないといけないことだけです。これは __ が "
"XXXMessage クラスのコンストラクタ呼び出しのシンタックスシュガーでしか無いから"
"です。"
#: ../../howto/logging-cookbook.rst:1142
msgid ""
"If you prefer, you can use a :class:`LoggerAdapter` to achieve a similar "
"effect to the above, as in the following example::"
msgstr ""
"次の例のように、 :class:`LoggerAdapter` を利用して上と似たような効果を実現す"
"る方法もあります::"
#: ../../howto/logging-cookbook.rst:1173
msgid ""
"The above script should log the message ``Hello, world!`` when run with "
"Python 3.2 or later."
msgstr ""
"上のスクリプトは Python 3.2 以降では ``Hello, world!`` というメッセージをログ"
"するはずです。"
#: ../../howto/logging-cookbook.rst:1182
msgid "Customizing ``LogRecord``"
msgstr "``LogRecord`` のカスタマイズ"
#: ../../howto/logging-cookbook.rst:1184
msgid ""
"Every logging event is represented by a :class:`LogRecord` instance. When an "
"event is logged and not filtered out by a logger's level, a :class:"
"`LogRecord` is created, populated with information about the event and then "
"passed to the handlers for that logger (and its ancestors, up to and "
"including the logger where further propagation up the hierarchy is "
"disabled). Before Python 3.2, there were only two places where this creation "
"was done:"
msgstr ""
"全ての logging イベントは :class:`LogRecord` のインスタンスとして表現されま"
"す。イベントのログが取られて logger のレベルでフィルタされなかった場合、イベ"
"ントの情報を含む :class:`LogRecord` が生成され、その logger (と、 propagate "
"が無効になるまでの上位 logger) の handler に渡されます。 Python 3.2 までは、"
"この生成が行われているのは2箇所だけでした:"
#: ../../howto/logging-cookbook.rst:1191
msgid ""
":meth:`Logger.makeRecord`, which is called in the normal process of logging "
"an event. This invoked :class:`LogRecord` directly to create an instance."
msgstr ""
":meth:`Logger.makeRecord`: 通常のイベント logging プロセスで呼ばれます。これ"
"は :class:`LogRecord` を直接読んでインスタンスを生成します。"
#: ../../howto/logging-cookbook.rst:1194
msgid ""
":func:`makeLogRecord`, which is called with a dictionary containing "
"attributes to be added to the LogRecord. This is typically invoked when a "
"suitable dictionary has been received over the network (e.g. in pickle form "
"via a :class:`~handlers.SocketHandler`, or in JSON form via an :class:"
"`~handlers.HTTPHandler`)."
msgstr ""
":func:`makeLogRecord`: LogRecord に追加される属性を含む辞書を渡して呼び出され"
"ます。これはネットワーク越しに (pickle 形式で :class:`~handlers."
"SocketHandler` 経由で、あるいは JSON 形式で :class:`~handlers.HTTPHandler` 経"
"由で) 辞書を受け取った場合などに利用されます。"
#: ../../howto/logging-cookbook.rst:1200
msgid ""
"This has usually meant that if you need to do anything special with a :class:"
"`LogRecord`, you've had to do one of the following."
msgstr ""
"そのために :class:`LogRecord` で何か特別なことをしたい場合は、次のどちらかを"
"しなければなりません。"
#: ../../howto/logging-cookbook.rst:1203
msgid ""
"Create your own :class:`Logger` subclass, which overrides :meth:`Logger."
"makeRecord`, and set it using :func:`~logging.setLoggerClass` before any "
"loggers that you care about are instantiated."
msgstr ""
":meth:`Logger.makeRecord` をオーバーライドした独自の :class:`Logger` のサブク"
"ラスを作り、利用したい logger のどれかがインスタンス化される前に、それを :"
"func:`~logging.setLoggerClass` を使って登録する。"
#: ../../howto/logging-cookbook.rst:1206
msgid ""
"Add a :class:`Filter` to a logger or handler, which does the necessary "
"special manipulation you need when its :meth:`~Filter.filter` method is "
"called."
msgstr ""
":meth:`~Filter.filter` メソッドで必要な特殊な処理を行う :class:`Filter` を "
"logger か handler に追加する。"
#: ../../howto/logging-cookbook.rst:1210
msgid ""
"The first approach would be a little unwieldy in the scenario where (say) "
"several different libraries wanted to do different things. Each would "
"attempt to set its own :class:`Logger` subclass, and the one which did this "
"last would win."
msgstr ""
"最初の方法は、複数の異なるライブラリが別々のことをしようとした場合にうまく行"
"きません。各ライブラリが独自の :class:`Logger` のサブクラスを登録しようとし"
"て、最後に登録されたライブラリが生き残ります。"
#: ../../howto/logging-cookbook.rst:1215
msgid ""
"The second approach works reasonably well for many cases, but does not allow "
"you to e.g. use a specialized subclass of :class:`LogRecord`. Library "
"developers can set a suitable filter on their loggers, but they would have "
"to remember to do this every time they introduced a new logger (which they "
"would do simply by adding new packages or modules and doing ::"
msgstr ""
"2つ目の方法はほとんどのケースでうまくいきますが、たとえば :class:`LogRecord` "
"を特殊化したサブクラスを使うことなどはできません。ライブラリの開発者は利用し"
"ている logger に適切な filter を設定できますが、新しい logger を作るたびに忘"
"れずに設定しないといけなくなります。 (新しいパッケージやモジュールを追加し、"
"モジュールレベルで次の式を実行することで、新しい logger が作られます) ::"
#: ../../howto/logging-cookbook.rst:1223
msgid ""
"at module level). It's probably one too many things to think about. "
"Developers could also add the filter to a :class:`~logging.NullHandler` "
"attached to their top-level logger, but this would not be invoked if an "
"application developer attached a handler to a lower-level library logger --- "
"so output from that handler would not reflect the intentions of the library "
"developer."
msgstr ""
"これでは考えることが余計に1つ増えてしまうでしょう。開発者は、最も高いレベルの"
"ロガーに取り付けられた :class:`~logging.NullHandler` に、フィルタを追加するこ"
"ともできますが、アプリケーション開発者が、より低いレベルに対するライブラリの"
"ロガーにハンドラを取り付けた場合、フィルタは呼び出されません --- 従って、その"
"ハンドラからの出力はライブラリ開発者の意図を反映したものにはなりません。"
#: ../../howto/logging-cookbook.rst:1229
msgid ""
"In Python 3.2 and later, :class:`~logging.LogRecord` creation is done "
"through a factory, which you can specify. The factory is just a callable you "
"can set with :func:`~logging.setLogRecordFactory`, and interrogate with :"
"func:`~logging.getLogRecordFactory`. The factory is invoked with the same "
"signature as the :class:`~logging.LogRecord` constructor, as :class:"
"`LogRecord` is the default setting for the factory."
msgstr ""
"Python 3.2 以降では、 :class:`~logging.LogRecord` の生成は、指定できるファク"
"トリ経由になります。ファクトリは callable で、 :func:`~logging."
"setLogRecordFactory` で登録でき、 :func:`~logging.getLogRecordFactory` で現在"
"のファクトリを取得できます。ファクトリは :class:`~logging.LogRecord` コンスト"
"ラクタと同じシグネチャで呼び出され、 :class:`LogRecord` がデフォルトのファク"
"トリとして設定されています。"
#: ../../howto/logging-cookbook.rst:1236
msgid ""
"This approach allows a custom factory to control all aspects of LogRecord "
"creation. For example, you could return a subclass, or just add some "
"additional attributes to the record once created, using a pattern similar to "
"this::"
msgstr ""
"このアプローチはカスタムのファクトリが LogRecord の生成のすべての面を制御でき"
"るようにしています。たとえば、サブクラスを返したり、次のようなパターンを使っ"
"て単に属性を追加することができます::"
#: ../../howto/logging-cookbook.rst:1249
msgid ""
"This pattern allows different libraries to chain factories together, and as "
"long as they don't overwrite each other's attributes or unintentionally "
"overwrite the attributes provided as standard, there should be no surprises. "
"However, it should be borne in mind that each link in the chain adds run-"
"time overhead to all logging operations, and the technique should only be "
"used when the use of a :class:`Filter` does not provide the desired result."
msgstr ""
"このアプローチでは複数の異なるライブラリがファクトリをチェインさせて、お互い"
"に同じ属性を上書きしたり、標準で提供されている属性を意図せず上書きしない限り"
"はうまくいきます。しかし、チェインのつながり全てが、全ての logging の操作に対"
"しての実行時のオーバーヘッドになることを念頭に置き、このテクニックは :class:"
"`Filter` を利用するだけでは望む結果が得られない場合にのみ使うべきです。"
#: ../../howto/logging-cookbook.rst:1260
msgid "Subclassing QueueHandler - a ZeroMQ example"
msgstr "QueueHandler を継承する - ZeroMQ を使う例"
#: ../../howto/logging-cookbook.rst:1262
msgid ""
"You can use a :class:`QueueHandler` subclass to send messages to other kinds "
"of queues, for example a ZeroMQ 'publish' socket. In the example below,the "