-
-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathlogging-cookbook.po
More file actions
1180 lines (1059 loc) · 66.3 KB
/
logging-cookbook.po
File metadata and controls
1180 lines (1059 loc) · 66.3 KB
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) 1990-2021, Python Software Foundation
# This file is distributed under the same license as the Python package.
#
# Translators:
# tomo, 2017
msgid ""
msgstr ""
"Project-Id-Version: Python 2.7\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-01-01 01:01+0900\n"
"PO-Revision-Date: 2019-09-01 05:18+0000\n"
"Last-Translator: Shun Sakurai\n"
"Language-Team: Japanese (http://www.transifex.com/python-doc/python-27/"
"language/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:99
msgid "Logging from multiple threads"
msgstr "複数のスレッドからのロギング"
#: ../../howto/logging-cookbook.rst:101
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:130
msgid "When run, the script should print something like the following::"
msgstr "実行すると、このスクリプトの出力は次のようなものになるはずです::"
#: ../../howto/logging-cookbook.rst:150
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:154
msgid "Multiple handlers and formatters"
msgstr "複数の handler と formatter"
#: ../../howto/logging-cookbook.rst:156
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:189
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:192
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:203
msgid "Logging to multiple destinations"
msgstr "複数の出力先にログを出力する"
#: ../../howto/logging-cookbook.rst:205
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:243
msgid "When you run this, on the console you will see ::"
msgstr ""
"このスクリプトを実行すると、コンソールには以下のように表示されるでしょう ::"
#: ../../howto/logging-cookbook.rst:250
msgid "and in the file you will see something like ::"
msgstr "そして、ファイルは以下のようになるはずです ::"
#: ../../howto/logging-cookbook.rst:258
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:261
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:266
msgid "Configuration server example"
msgstr "設定サーバの例"
#: ../../howto/logging-cookbook.rst:268
msgid "Here is an example of a module using the logging configuration server::"
msgstr "ログ記録設定サーバを使うモジュールの例です::"
#: ../../howto/logging-cookbook.rst:299
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:324
msgid "Sending and receiving logging events across a network"
msgstr "ネットワーク越しの logging イベントの送受信"
#: ../../howto/logging-cookbook.rst:326
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:354
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:442
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:452
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:462
msgid "Adding contextual information to your logging output"
msgstr "コンテキスト情報をログ記録出力に付加する"
#: ../../howto/logging-cookbook.rst:466
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:481
msgid "Using LoggerAdapters to impart contextual information"
msgstr "LoggerAdapter を使ったコンテキスト情報の伝達"
#: ../../howto/logging-cookbook.rst:483
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:491
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:507
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:516
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:532
msgid "which you can use like this::"
msgstr "これを次のように使うことができます::"
#: ../../howto/logging-cookbook.rst:537
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:541
msgid "Using objects other than dicts to pass contextual information"
msgstr "コンテキスト情報を渡すために dict 以外のオブジェクトを使う"
#: ../../howto/logging-cookbook.rst:543
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:552
msgid "Using Filters to impart contextual information"
msgstr "Filter を使ったコンテキスト情報の伝達"
#: ../../howto/logging-cookbook.rst:554
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:559
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:605
msgid "which, when run, produces something like::"
msgstr "そして、実行時に、以下のようになります::"
#: ../../howto/logging-cookbook.rst:624
msgid "Logging to a single file from multiple processes"
msgstr "複数のプロセスからの単一ファイルへのログ記録"
#: ../../howto/logging-cookbook.rst:626
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:639
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:650
msgid "Using file rotation"
msgstr "ファイルをローテートする"
#: ../../howto/logging-cookbook.rst:655
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:687
msgid ""
"The result should be 6 separate files, each with part of the log history for "
"the application::"
msgstr ""
"この結果として、アプリケーションのログ履歴の一部である、6 つに別れたファイル"
"が得られます::"
#: ../../howto/logging-cookbook.rst:697
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:702
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:706
msgid "An example dictionary-based configuration"
msgstr "辞書ベースで構成する例"
#: ../../howto/logging-cookbook.rst:708
msgid ""
"Below is an example of a logging configuration dictionary - it's taken from "
"the `documentation on the Django project <https://docs.djangoproject.com/"
"en/1.9/topics/logging/#configuring-logging>`_. This dictionary is passed to :"
"func:`~config.dictConfig` to put the configuration into effect::"
msgstr ""
"次の例は辞書を使った logging の構成です。この例は `Django プロジェクトのド"
"キュメント <https://docs.djangoproject.com/en/1.9/topics/logging/"
"#configuring-logging>`_ から持ってきました。この辞書を :func:`~config."
"dictConfig` に渡して設定を有効にします::"
#: ../../howto/logging-cookbook.rst:764
msgid ""
"For more information about this configuration, you can see the `relevant "
"section <https://docs.djangoproject.com/en/1.9/topics/logging/#configuring-"
"logging>`_ of the Django documentation."
msgstr ""
"この構成方法についてのより詳しい情報は、 Django のドキュメントの `該当のセク"
"ション <https://docs.djangoproject.com/en/1.9/topics/logging/#configuring-"
"logging>`_ で見ることができます。"
#: ../../howto/logging-cookbook.rst:769
msgid "Inserting a BOM into messages sent to a SysLogHandler"
msgstr "SysLogHandler に送るメッセージに BOM を挿入する"
#: ../../howto/logging-cookbook.rst:771
msgid ""
"`RFC 5424 <https://tools.ietf.org/html/rfc5424>`_ requires that a Unicode "
"message be sent to a syslog daemon as a set of bytes which have the "
"following structure: an optional pure-ASCII component, followed by a UTF-8 "
"Byte Order Mark (BOM), followed by Unicode encoded using UTF-8. (See the "
"`relevant section of the specification <https://tools.ietf.org/html/"
"rfc5424#section-6>`_.)"
msgstr ""
"`RFC 5424 <https://tools.ietf.org/html/rfc5424>`_ は syslog デーモンに "
"Unicode メッセージを送る時、次の構造を要求しています: オプショナルなピュア "
"ASCII部分、続けて UTF-8 の Byte Order Mark (BOM)、続けて UTF-8 でエンコードさ"
"れた Unicode. (`仕様の該当セクション <https://tools.ietf.org/html/"
"rfc5424#section-6>`_ を参照)"
#: ../../howto/logging-cookbook.rst:777
msgid ""
"In Python 2.6 and 2.7, code was added to :class:`~logging.handlers."
"SysLogHandler` to insert a BOM into the message, but unfortunately, it was "
"implemented incorrectly, with the BOM appearing at the beginning of the "
"message and hence not allowing any pure-ASCII component to appear before it."
msgstr ""
"Python 2.6, 2.7 で :class:`~logging.handlers.SysLogHandler` に、 message に "
"BOM を挿入するコードが追加されました。しかし、そのときの実装が悪くて、 "
"message の先頭に BOM をつけてしまうのでピュアASCII 部分をその前に書くことがで"
"きませんでした。"
#: ../../howto/logging-cookbook.rst:783
msgid ""
"As this behaviour is broken, the incorrect BOM insertion code is being "
"removed from Python 2.7.4 and later. However, it is not being replaced, and "
"if you want to produce RFC 5424-compliant messages which include a BOM, an "
"optional pure-ASCII sequence before it and arbitrary Unicode after it, "
"encoded using UTF-8, then you need to do the following:"
msgstr ""
"この動作は壊れているので、Python 2.7.4 以降では BOM を挿入するコードが、削除"
"されました。書き直されるのではなく削除されたので、RFC 5424 準拠の、BOM と、オ"
"プションのピュア ASCII部分をBOMの前に、任意の Unicode を BOM の後ろに持つ "
"UTF-8 でエンコードされた message を生成したい場合、次の手順に従う必要がありま"
"す:"
#: ../../howto/logging-cookbook.rst:789
msgid ""
"Attach a :class:`~logging.Formatter` instance to your :class:`~logging."
"handlers.SysLogHandler` instance, with a format string such as::"
msgstr ""
":class:`~logging.handlers.SysLogHandler` のインスタンスに、次のような format "
"文字列を持った :class:`~logging.Formatter` インスタンスをアタッチする::"
#: ../../howto/logging-cookbook.rst:795
msgid ""
"The Unicode code point ``u'\\ufeff'``, when encoded using UTF-8, will be "
"encoded as a UTF-8 BOM -- the byte-string ``'\\xef\\xbb\\xbf'``."
msgstr ""
"Unicode のコードポイント ``u'\\ufeff'`` は、UTF-8 でエンコードすると BOM -- "
"``'\\xef\\xbb\\xbf'`` -- になります。"
#: ../../howto/logging-cookbook.rst:798
msgid ""
"Replace the ASCII section with whatever placeholders you like, but make sure "
"that the data that appears in there after substitution is always ASCII (that "
"way, it will remain unchanged after UTF-8 encoding)."
msgstr ""
"ASCII セクションを好きなプレースホルダに変更する。ただしその部分の置換結果が"
"常に ASCII になるように注意する(UTF-8 でエンコードされてもその部分が変化しな"
"いようにする)。"
#: ../../howto/logging-cookbook.rst:802
msgid ""
"Replace the Unicode section with whatever placeholders you like; if the data "
"which appears there after substitution contains characters outside the ASCII "
"range, that's fine -- it will be encoded using UTF-8."
msgstr ""
"Unicode セクションを任意のプレースホルダに置き換える。この部分を置換したデー"
"タに ASCII 外の文字が含まれていても、それは単に UTF-8 でエンコードされるだけ"
"です。"
#: ../../howto/logging-cookbook.rst:806
msgid ""
"If the formatted message is Unicode, it *will* be encoded using UTF-8 "
"encoding by ``SysLogHandler``. If you follow the above rules, you should be "
"able to produce RFC 5424-compliant messages. If you don't, logging may not "
"complain, but your messages will not be RFC 5424-compliant, and your syslog "
"daemon may complain."
msgstr ""
"フォーマットされた message が Unicode の場合、 ``SysLogHandler`` によって "
"UTF-8 でエンコードされます。上のルールに従えば、RFC 5424 準拠のメッセージを生"
"成できます。上のルールに従わない場合、logging は何もエラーを起こしませんが、"
"message は RFC 5424 に準拠しない形で送られるので、syslog デーモン側で何かエ"
"ラーが起こる可能性があります。"
#: ../../howto/logging-cookbook.rst:814
msgid "Implementing structured logging"
msgstr "構造化ログを実装する"
#: ../../howto/logging-cookbook.rst:816
msgid ""
"Although most logging messages are intended for reading by humans, and thus "
"not readily machine-parseable, there might be circumstances where you want "
"to output messages in a structured format which *is* capable of being parsed "
"by a program (without needing complex regular expressions to parse the log "
"message). This is straightforward to achieve using the logging package. "
"There are a number of ways in which this could be achieved, but the "
"following is a simple approach which uses JSON to serialise the event in a "
"machine-parseable manner::"
msgstr ""
"多くのログメッセージは人間が読むために書かれるため、機械的に処理しにくくなっ"
"ていますが、場合によっては (複雑な正規表現を使ってログメッセージをパースしな"
"くても) プログラムがパース *できる* 構造化されたフォーマットでメッセージを出"
"力したい場合があります。\n"
"logging パッケージを使うと、これを簡単に実現できます。\n"
"実現する方法は幾つもありますが、次の例は JSON を使ってイベントを、機械でパー"
"スできる形にシリアライズする単純な方法です::"
#: ../../howto/logging-cookbook.rst:840
msgid "If the above script is run, it prints::"
msgstr "上のスクリプトを実行すると次のように出力されます::"
#: ../../howto/logging-cookbook.rst:844 ../../howto/logging-cookbook.rst:891
msgid ""
"Note that the order of items might be different according to the version of "
"Python used."
msgstr "要素の順序は Python のバージョンによって異なることに注意してください。"
#: ../../howto/logging-cookbook.rst:847
msgid ""
"If you need more specialised processing, you can use a custom JSON encoder, "
"as in the following complete example::"
msgstr ""
"より特殊な処理が必要な場合、次の例のように、カスタムの JSON エンコーダを作る"
"ことができます::"
#: ../../howto/logging-cookbook.rst:887
msgid "When the above script is run, it prints::"
msgstr "上のスクリプトを実行すると次のように出力されます::"
#: ../../howto/logging-cookbook.rst:900
msgid "Customizing handlers with :func:`dictConfig`"
msgstr "handler を :func:`dictConfig` を使ってカスタマイズする"
#: ../../howto/logging-cookbook.rst:902
msgid ""
"There are times when you want to customize logging handlers in particular "
"ways, and if you use :func:`dictConfig` you may be able to do this without "
"subclassing. As an example, consider that you may want to set the ownership "
"of a log file. On POSIX, this is easily done using :func:`os.chown`, but the "
"file handlers in the stdlib don't offer built-in support. You can customize "
"handler creation using a plain function such as::"
msgstr ""
"logging handler に特定のカスタマイズを何度もしたい場合で、 :func:"
"`dictConfig` を使っているなら、サブクラスを作らなくてもカスタマイズが可能で"
"す。例えば、ログファイルの owner を設定したいとします。これは POSIX 環境で"
"は :func:`os.chown` を使って簡単に実現できますが、標準ライブラリの file "
"handler はこの機能を組み込みでサポートしていません。 handler の生成を通常の関"
"数を使ってカスタマイズすることができます::"
#: ../../howto/logging-cookbook.rst:921
msgid ""
"You can then specify, in a logging configuration passed to :func:"
"`dictConfig`, that a logging handler be created by calling this function::"
msgstr ""
"そして、 :func:`dictConfig` に渡される構成設定の中で、この関数を使って "
"logging handler を生成するように指定することができます::"
#: ../../howto/logging-cookbook.rst:954
msgid ""
"In this example I am setting the ownership using the ``pulse`` user and "
"group, just for the purposes of illustration. Putting it together into a "
"working script, ``chowntest.py``::"
msgstr ""
"この例は説明用のものですが、owner の user と group を ``pulse`` に設定してい"
"ます。これを動くスクリプトに ``chowntest.py`` に組み込んでみます::"
#: ../../howto/logging-cookbook.rst:1001
msgid "To run this, you will probably need to run as ``root``:"
msgstr "これを実行するには、 ``root`` 権限で実行する必要があるかもしれません:"
#: ../../howto/logging-cookbook.rst:1011
msgid ""
"Note that this example uses Python 3.3 because that's where :func:`shutil."
"chown` makes an appearance. This approach should work with any Python "
"version that supports :func:`dictConfig` - namely, Python 2.7, 3.2 or later. "
"With pre-3.3 versions, you would need to implement the actual ownership "
"change using e.g. :func:`os.chown`."
msgstr ""
":func:`shutil.chown` が追加されたのが Python 3.3 からなので、この例は Python "
"3.3 を使っています。このアプローチ自体は :func:`dictConfig` をサポートした全"
"ての Python バージョン - Python 2.7, 3.2 以降 - で利用できます。 3.3 以前の"
"バージョンでは、オーナーを変更するのに :func:`os.chown` を利用する必要がある"
"でしょう。"
#: ../../howto/logging-cookbook.rst:1017
msgid ""
"In practice, the handler-creating function may be in a utility module "
"somewhere in your project. Instead of the line in the configuration::"
msgstr ""
"実際には、handler を生成する関数はプロジェクト内のどこかにあるユーティリティ"
"モジュールに置くことになるでしょう。設定の中で直接関数を参照する代わりに::"
#: ../../howto/logging-cookbook.rst:1022
msgid "you could use e.g.::"
msgstr "次のように書くこともできます::"
#: ../../howto/logging-cookbook.rst:1026
msgid ""
"where ``project.util`` can be replaced with the actual name of the package "
"where the function resides. In the above working script, using ``'ext://"
"__main__.owned_file_handler'`` should work. Here, the actual callable is "
"resolved by :func:`dictConfig` from the ``ext://`` specification."
msgstr ""
"``project.util`` は関数がある実際の場所に置き換えてください。上のスクリプトで"
"は ``'ext://__main__.owned_file_handler'`` で動くはずです。 :func:"
"`dictConfig` は ``ext://`` から実際の callable を見つけます。"
#: ../../howto/logging-cookbook.rst:1031
msgid ""
"This example hopefully also points the way to how you could implement other "
"types of file change - e.g. setting specific POSIX permission bits - in the "
"same way, using :func:`os.chmod`."
msgstr ""
"この例は他のファイルに対する変更を実装する例にもなっています。例えば :func:"
"`os.chmod` を使って、同じ方法で POSIX パーミッションを設定できるでしょう。"
#: ../../howto/logging-cookbook.rst:1035
msgid ""
"Of course, the approach could also be extended to types of handler other "
"than a :class:`~logging.FileHandler` - for example, one of the rotating file "
"handlers, or a different type of handler altogether."
msgstr ""
"もちろん、このアプローチは :class:`~logging.FileHandler` 以外の handler 、"
"ローテートする file handler のいずれかやその他の handler にも適用できます。"
#: ../../howto/logging-cookbook.rst:1043
msgid "Configuring filters with :func:`dictConfig`"
msgstr "filter を :func:`dictConfig` を使ってカスタマイズする"
#: ../../howto/logging-cookbook.rst:1045
msgid ""
"You *can* configure filters using :func:`~logging.config.dictConfig`, though "
"it might not be obvious at first glance how to do it (hence this recipe). "
"Since :class:`~logging.Filter` is the only filter class included in the "
"standard library, and it is unlikely to cater to many requirements (it's "
"only there as a base class), you will typically need to define your own :"
"class:`~logging.Filter` subclass with an overridden :meth:`~logging.Filter."
"filter` method. To do this, specify the ``()`` key in the configuration "
"dictionary for the filter, specifying a callable which will be used to "
"create the filter (a class is the most obvious, but you can provide any "
"callable which returns a :class:`~logging.Filter` instance). Here is a "
"complete example::"
msgstr ""
":func:`~logging.config.dictConfig` によってフィルタを設定 *出来ます* が、どう"
"やってそれを行うのかが初見では明快とは言えないでしょう(そのためのこのレシピで"
"す)。 :class:`~logging.Filter` のみが唯一標準ライブラリに含まれているだけです"
"し、それは何の要求にも応えてはくれません(ただの基底クラスですから)ので、典型"
"的には :meth:`~logging.Filter.filter` メソッドをオーバライドした :class:"
"`~logging.Filter` のサブクラスをあなた自身で定義する必要があります。これをす"
"るには、設定辞書内のフィルタ指定部分に、 ``()`` キーでそのフィルタを作るのに"
"使われる callable を指定してください(クラスを指定するのが最もわかりやすいです"
"が、 :class:`~logging.Filter` インスタンスを返却する callable を提供すること"
"でも出来ます)。以下に完全な例を示します::"
#: ../../howto/logging-cookbook.rst:1098
msgid ""
"This example shows how you can pass configuration data to the callable which "
"constructs the instance, in the form of keyword parameters. When run, the "
"above script will print::"
msgstr ""
"どのようにして設定データとして、そのインスタンスを構築する callable をキー"
"ワードパラメータの形で渡すのか、をこの例は教えてくれます。上記スクリプトは実"
"行すると、このような出力をします::"
#: ../../howto/logging-cookbook.rst:1104
msgid "which shows that the filter is working as configured."
msgstr "設定した通りに動いていますね。"
#: ../../howto/logging-cookbook.rst:1106
msgid "A couple of extra points to note:"
msgstr "ほかにもいくつか特筆すべき点があります:"
#: ../../howto/logging-cookbook.rst:1108
msgid ""
"If you can't refer to the callable directly in the configuration (e.g. if it "
"lives in a different module, and you can't import it directly where the "
"configuration dictionary is), you can use the form ``ext://...`` as "
"described in :ref:`logging-config-dict-externalobj`. For example, you could "
"have used the text ``'ext://__main__.MyFilter'`` instead of ``MyFilter`` in "
"the above example."
msgstr ""
"設定内で直接その callable を参照出来ない場合(例えばそれが異なるモジュール内に"
"あり、設定辞書のある場所からそれを直接インポート出来ない、など)には、 :ref:"
"`logging-config-dict-externalobj` に記述されている ``ext://...`` 形式を使えま"
"す。例えば、上記例のように ``MyFilter`` と指定する代わりに、 ``'ext://"
"__main__.MyFilter'`` と記述することが出来ます。"
#: ../../howto/logging-cookbook.rst:1115
msgid ""
"As well as for filters, this technique can also be used to configure custom "
"handlers and formatters. See :ref:`logging-config-dict-userdef` for more "
"information on how logging supports using user-defined objects in its "
"configuration, and see the other cookbook recipe :ref:`custom-handlers` "
"above."
msgstr ""
"フィルタについてとともに、このテクニックは、カスタムハンドラ、カスタムフォー"
"マッタに対しても同様に使えます。ロギングが設定において、どのようにユーザ定義"
"のオブジェクトをサポートするのかについてのさらなる詳細については、 :ref:"
"`logging-config-dict-userdef` と、本クックブックの上の方のレシピ :ref:"
"`custom-handlers` を参照してください。"
#: ../../howto/logging-cookbook.rst:1124
msgid "Customized exception formatting"
msgstr "例外の書式化をカスタマイズする"
#: ../../howto/logging-cookbook.rst:1126
msgid ""
"There might be times when you want to do customized exception formatting - "
"for argument's sake, let's say you want exactly one line per logged event, "
"even when exception information is present. You can do this with a custom "
"formatter class, as shown in the following example::"
msgstr ""
"例外の書式化をカスタマイズしたいことがあるでしょう - わかりやすさのために、例"
"外情報がある場合でもログイベントごとに一行に収まることを死守したいと望むとし"
"ましょう。フォーマッタのクラスをカスタマイズして、このように出来ます::"
#: ../../howto/logging-cookbook.rst:1167
msgid "When run, this produces a file with exactly two lines::"
msgstr "実行してみましょう。このように正確に2行の出力を生成します::"
#: ../../howto/logging-cookbook.rst:1172
msgid ""
"While the above treatment is simplistic, it points the way to how exception "
"information can be formatted to your liking. The :mod:`traceback` module may "
"be helpful for more specialized needs."
msgstr ""
"これは扱いとしては単純過ぎますが、例外情報をどのようにしてあなた好みの書式化"
"出来るかを示しています。さらに特殊なニーズが必要な場合には :mod:`traceback` "
"モジュールが有用です。"
#: ../../howto/logging-cookbook.rst:1179
msgid "Speaking logging messages"
msgstr "ロギングメッセージを喋る"
#: ../../howto/logging-cookbook.rst:1181
msgid ""
"There might be situations when it is desirable to have logging messages "
"rendered in an audible rather than a visible format. This is easy to do if "
"you have text-to-speech (TTS) functionality available in your system, even "
"if it doesn't have a Python binding. Most TTS systems have a command line "
"program you can run, and this can be invoked from a handler using :mod:"
"`subprocess`. It's assumed here that TTS command line programs won't expect "
"to interact with users or take a long time to complete, and that the "
"frequency of logged messages will be not so high as to swamp the user with "
"messages, and that it's acceptable to have the messages spoken one at a time "
"rather than concurrently, The example implementation below waits for one "
"message to be spoken before the next is processed, and this might cause "
"other handlers to be kept waiting. Here is a short example showing the "
"approach, which assumes that the ``espeak`` TTS package is available::"
msgstr ""
"ロギングメッセージを目で見る形式ではなく音で聴く形式として出力したい、という"
"状況があるかもしれません。これはあなたのシステムで text- to-speech (TTS) 機能"
"が利用可能であれば、容易です。それが Python バインディングを持っていなくと"
"も、です。ほとんどの TTS システムはあなたが実行出来るコマンドラインプログラム"
"を持っていて、このことで、 :mod:`subprocess` を使うことでハンドラが呼び出せま"
"す。ここでは、TTS コマンドラインプログラムはユーザとの対話を期待せず、完了に"
"は時間がかかり、そしてログメッセージの頻度はユーザをメッセージで圧倒してしま"
"うほどには高くはなく、そして並列で喋るよりはメッセージ一つにつき一回喋ること"
"が受け容れられる、としておきます。ここでお見せする実装例では、次が処理される"
"前に一つのメッセージを喋り終わるまで待ち、結果としてほかのハンドラを待たせる"
"ことになります。 ``espeak`` TTS パッケージが手許にあるとして、このアプローチ"
"による短い例はこのようなものです::"
#: ../../howto/logging-cookbook.rst:1223
msgid ""
"When run, this script should say \"Hello\" and then \"Goodbye\" in a female "
"voice."
msgstr "実行すれば、女性の声で \"Hello\" に続き \"Goodbye\" と喋るはずです。"
#: ../../howto/logging-cookbook.rst:1225
msgid ""
"The above approach can, of course, be adapted to other TTS systems and even "
"other systems altogether which can process messages via external programs "
"run from a command line."
msgstr ""
"このアプローチは、もちろんほかの TTS システムにも採用出来ますし、メッセージを"
"コマンドライン経由で外部プログラムに渡せるようなものであれば、ほかのシステム"
"であっても全く同じです。"
#: ../../howto/logging-cookbook.rst:1232
msgid "Buffering logging messages and outputting them conditionally"
msgstr "ロギングメッセージをバッファリングし、条件に従って出力する"
#: ../../howto/logging-cookbook.rst:1234
msgid ""
"There might be situations where you want to log messages in a temporary area "
"and only output them if a certain condition occurs. For example, you may "
"want to start logging debug events in a function, and if the function "
"completes without errors, you don't want to clutter the log with the "
"collected debug information, but if there is an error, you want all the "
"debug information to be output as well as the error."
msgstr ""
"メッセージを一次領域に記録し、ある種の特定の状況になった場合にだけ出力した"
"い、ということがあるかもしれません。たとえばある関数内でのデバッグのためのロ"
"グ出力をしたくても、エラーなしで終了する限りにおいては収集されたデバッグ情報"
"による混雑は喰らいたくはなく、エラーがあった場合にだけエラー出力とともにデ"
"バッグ情報を見たいのだ、のようなことがあるでしょう。"
#: ../../howto/logging-cookbook.rst:1241
msgid ""
"Here is an example which shows how you could do this using a decorator for "
"your functions where you want logging to behave this way. It makes use of "
"the :class:`logging.handlers.MemoryHandler`, which allows buffering of "
"logged events until some condition occurs, at which point the buffered "
"events are ``flushed`` - passed to another handler (the ``target`` handler) "
"for processing. By default, the ``MemoryHandler`` flushed when its buffer "
"gets filled up or an event whose level is greater than or equal to a "
"specified threshold is seen. You can use this recipe with a more specialised "
"subclass of ``MemoryHandler`` if you want custom flushing behavior."
msgstr ""
"このような振る舞いをするロギングをしたい関数に対して、デコレータを用いてこれ"
"を行う例をお見せします。それには :class:`logging.handlers.MemoryHandler` を使"
"います。これにより何か条件を満たすまでロギングイベントを溜め込むことが出来、"
"条件を満たせば溜め込まれたイベントが ``flushed`` として他のハンドラ "
"(``target`` のハンドラ)に渡されます。デフォルトでは、 ``MemoryHandler`` はそ"
"のバッファが一杯になるか、指定された閾値のレベル以上のイベントが起こるとフ"
"ラッシュされます。何か特別なフラッシュの振る舞いをしたければ、このレシピはさ"
"らに特殊化した ``MemoryHandler`` とともに利用出来ます。"
#: ../../howto/logging-cookbook.rst:1251
msgid ""
"The example script has a simple function, ``foo``, which just cycles through "
"all the logging levels, writing to ``sys.stderr`` to say what level it's "
"about to log at, and then actually logging a message at that level. You can "
"pass a parameter to ``foo`` which, if true, will log at ERROR and CRITICAL "
"levels - otherwise, it only logs at DEBUG, INFO and WARNING levels."
msgstr ""
"スクリプト例では、 ``foo`` という、単に全てのログレベルについて、 ``sys."
"stderr`` にもどのレベルを出力したのかについて書き出しながら実際のログ出力も行"
"う、という単純な関数を使っています。 ``foo`` に真を与えると ERROR と "
"CRITICAL の出力をし、そうでなければ DEBUG, INFO, WARNING だけを出力します。"