From feca3a15a4fb6ae8c0e9f5488ba12f266690ac12 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 23 Jan 2026 08:06:58 +0000 Subject: [PATCH 1/3] feat: translate howto/logging.po Add Traditional Chinese translations for the logging HOWTO documentation. This includes: - Header updates with new translator credit (CTHua) - Translation of main sections and headings - Translation of logging level descriptions - Translation of handler and formatter documentation - Translation of configuration examples https://claude.ai/code/session_01FubLSJSpQ2mNDuK2cjMebE --- howto/logging.po | 389 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 325 insertions(+), 64 deletions(-) diff --git a/howto/logging.po b/howto/logging.po index 9337a55f28..6bb32c2cca 100644 --- a/howto/logging.po +++ b/howto/logging.po @@ -1,8 +1,9 @@ -# Copyright (C) 2001 Python Software Foundation +# Copyright (C) 2001-2024, Python Software Foundation # This file is distributed under the same license as the Python package. # # Translators: # 文俊 高 , 2016 +# CTHua , 2023 msgid "" msgstr "" "Project-Id-Version: Python 3.14\n" @@ -17,10 +18,11 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=1; plural=0;\n" +"X-Generator: Weblate 4.16.4\n" #: ../../howto/logging.rst:5 msgid "Logging HOWTO" -msgstr "如何使用 Logging 模組" +msgstr "如何使用日誌記錄 (Logging)" #: ../../howto/logging.rst:0 msgid "Author" @@ -31,10 +33,13 @@ msgid "Vinay Sajip " msgstr "Vinay Sajip " #: ../../howto/logging.rst:13 +#, fuzzy msgid "" "This page contains tutorial information. For links to reference information " "and a logging cookbook, please see :ref:`tutorial-ref-links`." msgstr "" +"此頁面包含教學資訊。有關參考資訊和日誌記錄手冊的鏈接,請參閱 :ref:`tutorial-" +"ref-links`。" #: ../../howto/logging.rst:17 msgid "Basic Logging Tutorial" @@ -68,19 +73,22 @@ msgid "" "to see which logger methods to use when, see the table below. It states, for " "each of a set of common tasks, the best tool to use for that task." msgstr "" +"日誌(Logging)提供方便使用的一組簡單紀錄函式。這些函式包括::func:`debug`、:" +"func:`info`、:func:`warning`、:func:`error` 和 :func:`critical`。如需確定何時" +"使用紀錄,請參見以下表格,其中列出每個常見工作的最佳工具。" #: ../../howto/logging.rst:38 msgid "Task you want to perform" -msgstr "" +msgstr "你想要執行的任務" #: ../../howto/logging.rst:38 msgid "The best tool for the task" -msgstr "" +msgstr "此任務最好的工具" #: ../../howto/logging.rst:40 msgid "" "Display console output for ordinary usage of a command line script or program" -msgstr "" +msgstr "對於命令行或程式的普通用法,結果會顯示在控制台" #: ../../howto/logging.rst:40 msgid ":func:`print`" @@ -90,43 +98,49 @@ msgstr ":func:`print`" msgid "" "Report events that occur during normal operation of a program (e.g. for " "status monitoring or fault investigation)" -msgstr "" +msgstr "報告在程式正常操作期間發生的事件(例如用於狀態監視或故障調查)" #: ../../howto/logging.rst:44 msgid "" "A logger's :meth:`~Logger.info` (or :meth:`~Logger.debug` method for very " "detailed output for diagnostic purposes)" msgstr "" +":func:`logging.info` (或者在需要診斷用的詳細輸出時使用 :func:`logging." +"debug` )" #: ../../howto/logging.rst:49 msgid "Issue a warning regarding a particular runtime event" -msgstr "" +msgstr "針對特定的運行時事件發出警告" #: ../../howto/logging.rst:49 msgid "" ":func:`warnings.warn` in library code if the issue is avoidable and the " "client application should be modified to eliminate the warning" msgstr "" +"如果問題是可以避免的,那麼客戶端應該修改以消除警告,請在庫程式碼中使用 :func:" +"`warnings.warn` 警告" #: ../../howto/logging.rst:54 msgid "" "A logger's :meth:`~Logger.warning` method if there is nothing the client " "application can do about the situation, but the event should still be noted" msgstr "" +"如果客戶端應用程式無法處理該情況,但該事件仍應注意,可以使用 :func:`logging." +"warning`" #: ../../howto/logging.rst:60 msgid "Report an error regarding a particular runtime event" -msgstr "" +msgstr "回報與特定執行階段事件相關的錯誤" #: ../../howto/logging.rst:60 msgid "Raise an exception" -msgstr "引發一個例外" +msgstr "引發例外" #: ../../howto/logging.rst:63 msgid "" "Report suppression of an error without raising an exception (e.g. error " "handler in a long-running server process)" -msgstr "" +msgstr "報告錯誤但不引發異常(如長時間執行的伺服器進程中的錯誤處理程序)" #: ../../howto/logging.rst:63 msgid "" @@ -134,6 +148,8 @@ msgid "" "or :meth:`~Logger.critical` method as appropriate for the specific error and " "application domain" msgstr "" +"根據錯誤及應用領域的特定需要,使用 :func:`logging.error`、:func:`logging." +"exception` 或 :func:`logging.critical`" #: ../../howto/logging.rst:70 msgid "" @@ -141,14 +157,16 @@ msgid "" "are used to track. The standard levels and their applicability are described " "below (in increasing order of severity):" msgstr "" +"日誌紀錄函式的命名方式是根據它們所用於追蹤的事件等級或嚴重程度。以下是標準等" +"級及其可應用的範圍說明(按嚴重程度遞增排序):" #: ../../howto/logging.rst:77 ../../howto/logging.rst:875 msgid "Level" -msgstr "" +msgstr "等級" #: ../../howto/logging.rst:77 msgid "When it's used" -msgstr "" +msgstr "何時使用" #: ../../howto/logging.rst:79 ../../howto/logging.rst:885 msgid "``DEBUG``" @@ -157,7 +175,7 @@ msgstr "``DEBUG``" #: ../../howto/logging.rst:79 msgid "" "Detailed information, typically of interest only when diagnosing problems." -msgstr "" +msgstr "詳細的資訊,僅在診斷問題時才會有用。" #: ../../howto/logging.rst:82 ../../howto/logging.rst:883 msgid "``INFO``" @@ -165,7 +183,7 @@ msgstr "``INFO``" #: ../../howto/logging.rst:82 msgid "Confirmation that things are working as expected." -msgstr "" +msgstr "確認一切都按預期運作。" #: ../../howto/logging.rst:85 ../../howto/logging.rst:881 msgid "``WARNING``" @@ -177,6 +195,8 @@ msgid "" "problem in the near future (e.g. 'disk space low'). The software is still " "working as expected." msgstr "" +"一種意外發生的徵兆,或是暗示著未來可能出現問題(例如:「磁碟空間不足」),程" +"式還在按照預期運作。" #: ../../howto/logging.rst:90 ../../howto/logging.rst:879 msgid "``ERROR``" @@ -186,7 +206,7 @@ msgstr "``ERROR``" msgid "" "Due to a more serious problem, the software has not been able to perform " "some function." -msgstr "" +msgstr "因為有更嚴重的問題,軟體無法執行某些功能。" #: ../../howto/logging.rst:93 ../../howto/logging.rst:877 msgid "``CRITICAL``" @@ -196,7 +216,7 @@ msgstr "``CRITICAL``" msgid "" "A serious error, indicating that the program itself may be unable to " "continue running." -msgstr "" +msgstr "嚴重錯誤,表示此程式本身可能無法繼續執行。" #: ../../howto/logging.rst:97 msgid "" @@ -204,6 +224,8 @@ msgid "" "severity and higher will be tracked, unless the logging package is " "configured to do otherwise." msgstr "" +"預設的級別是「警告」(``WARNING``),這意味著除非配置記錄器套件進行其他設定,否" +"則只會追蹤這個級別以上的事件。" #: ../../howto/logging.rst:100 msgid "" @@ -211,6 +233,8 @@ msgid "" "of handling tracked events is to print them to the console. Another common " "way is to write them to a disk file." msgstr "" +"被追蹤的事件可以採取不同的處理方式。處理追蹤事件最簡單的方法是將它們輸出到控" +"制台。另一個常見的方法是將它們寫入磁盤文件。" #: ../../howto/logging.rst:108 msgid "A simple example" @@ -232,7 +256,7 @@ msgstr "" #: ../../howto/logging.rst:116 msgid "If you type these lines into a script and run it, you'll see:" -msgstr "" +msgstr "若你將這幾行程式碼加入腳本中並且運行,你就能看到:" #: ../../howto/logging.rst:118 msgid "WARNING:root:Watch out!" @@ -246,6 +270,10 @@ msgid "" "i.e. 'Watch out!'. The actual output can be formatted quite flexibly if you " "need that; formatting options will also be explained later." msgstr "" +"這段訊息顯示在控制台上。由於預設級別為 ``WARNING``,所以 ``INFO`` 訊息並未出" +"現。印出的訊息包含級別以及在 logging 呼叫中提供的事件說明,例如 'Watch " +"out!'。目前不必擔心 'root' 部分,稍後將會說明。如果你需要的話,可以彈性地格式" +"化實際輸出;相關選項也將在稍後說明。" #: ../../howto/logging.rst:128 msgid "" @@ -258,10 +286,15 @@ msgid "" "reason as well as others, it's better to create loggers and call their " "methods." msgstr "" +"請注意,在這個範例中,我們直接在 ``logging`` 模組上使用函式,如 ``logging." +"debug``,而不是建立一個記錄器並在其上呼叫函式。這些函式在根記錄器上運作,但它" +"們很有用,因為它們會在尚未呼叫 :func:`~logging.basicConfig` 時(如此範例)為" +"你呼叫它。然而,在較大的程式中,你通常會希望明確控制日誌配置——因此基於這個原" +"因以及其他原因,最好建立記錄器並呼叫它們的方法。" #: ../../howto/logging.rst:137 msgid "Logging to a file" -msgstr "" +msgstr "將日誌寫入檔案" #: ../../howto/logging.rst:139 msgid "" @@ -270,6 +303,8 @@ msgid "" "Python interpreter, and don't just continue from the session described " "above::" msgstr "" +"一個非常普遍的情況是將日誌事件記錄在文件中,因此讓我們接著看看這個情況。請務" +"必在新啟動的 Python 直譯器中嘗試以下操作,而不是繼續以上描述的會話: ::" #: ../../howto/logging.rst:143 msgid "" @@ -299,12 +334,15 @@ msgid "" "passed, which determines how encoding errors are handled. For available " "values and the default, see the documentation for :func:`open`." msgstr "" +"新增了 *encoding* 引數。在早期的 Python 版本中,如果未指定,將使用 :func:" +"`open` 的預設編碼。儘管在上面的範例中沒有顯示,現在也可以傳遞 *errors* 引數," +"以決定如何處理編碼錯誤。可用的值與其預設值,請參閱 :func:`open` 的文件。" #: ../../howto/logging.rst:158 msgid "" "And now if we open the file and look at what we have, we should find the log " "messages:" -msgstr "" +msgstr "現在,如果我們打開文件並查看其內容,我們應該能夠找到日誌訊息:" #: ../../howto/logging.rst:161 msgid "" @@ -320,11 +358,13 @@ msgid "" "threshold for tracking. In this case, because we set the threshold to " "``DEBUG``, all of the messages were printed." msgstr "" +"這個範例同時也展示了如何設定日誌紀錄等級作為追蹤的門檻。在這個例子中,因為門" +"檻被設為 ``DEBUG``,所以所有的訊息都會被印出來。" #: ../../howto/logging.rst:172 msgid "" "If you want to set the logging level from a command-line option such as:" -msgstr "" +msgstr "如果你想要從命令列選項設置日誌級別,例如:" #: ../../howto/logging.rst:174 msgid "--log=INFO" @@ -335,6 +375,8 @@ msgid "" "and you have the value of the parameter passed for ``--log`` in some " "variable *loglevel*, you can use::" msgstr "" +"如果你已經將 ``--log`` 引數的值存儲在某個變數 *loglevel* 中,你可以使用以下方" +"式: ::" #: ../../howto/logging.rst:181 msgid "getattr(logging, loglevel.upper())" @@ -346,6 +388,8 @@ msgid "" "argument. You may want to error check any user input value, perhaps as in " "the following example::" msgstr "" +"要取得值以傳遞給 :func:`basicConfig` 的 *level* 引數,你可能會想檢查任何使用" +"者輸入的值,如下面的示例所示: ::" #: ../../howto/logging.rst:187 msgid "" @@ -364,6 +408,10 @@ msgid "" "methods such as :meth:`~Logger.debug`, :meth:`~Logger.info`, etc. Otherwise, " "that logging event may not be handled in the desired manner." msgstr "" +":func:`basicConfig` 的呼叫應該放在任何關於 :func:`debug` 、 :func:`info` 等的" +"呼叫 *之前* ,否則這些功能就會以預設選項自動呼叫 :func:`basicConfig`。由於它" +"旨在作為一次性的簡單配置工具,只有第一個呼叫才能真正執行:後續的呼叫基本上是" +"無操作(no-ops)。" #: ../../howto/logging.rst:199 msgid "" @@ -372,6 +420,9 @@ msgid "" "afresh, not remembering the messages from earlier runs, you can specify the " "*filemode* argument, by changing the call in the above example to::" msgstr "" +"如果你多次運行上面的腳本,就會將每次成功執行時的訊息添加到名為 *example.log* " +"檔案中。如果你希望每次都從頭開始,不記住以前運行時的訊息,則可以指定 " +"*filemode* 引數,在上面範例中更改呼叫方式如下所示: ::" #: ../../howto/logging.rst:204 msgid "" @@ -386,16 +437,19 @@ msgid "" "The output will be the same as before, but the log file is no longer " "appended to, so the messages from earlier runs are lost." msgstr "" +"輸出會和之前一樣,但不再新增在舊的紀錄檔內,因此之前執行的訊息都遺失了。" #: ../../howto/logging.rst:211 msgid "Logging variable data" -msgstr "" +msgstr "紀錄變數數據" #: ../../howto/logging.rst:213 msgid "" "To log variable data, use a format string for the event description message " "and append the variable data as arguments. For example::" msgstr "" +"為了紀錄變數資料,請使用格式字串作為事件描述訊息,並將變數資料逐一附加為引" +"數。例如: ::" #: ../../howto/logging.rst:216 msgid "" @@ -407,7 +461,7 @@ msgstr "" #: ../../howto/logging.rst:219 msgid "will display:" -msgstr "" +msgstr "會顯示:" #: ../../howto/logging.rst:221 msgid "WARNING:root:Look before you leap!" @@ -422,16 +476,21 @@ msgid "" "options *are* supported, but exploring them is outside the scope of this " "tutorial: see :ref:`formatting-styles` for more information." msgstr "" +"正如你所看到的,將變量數據合併到事件描述消息中使用的是舊的 `%` 樣式的字符串格" +"式化方式。這是出於向後兼容,logging 包的發布日期先於新的格式化選項,如 :meth:" +"`str.format` 方法和 :class:`string.Template` 類別。雖然支援這些新的格式化選" +"項,但是探索這些選項超出了本教程的範圍:請參閱 :ref:`formatting-styles` 獲取" +"更多信息。" #: ../../howto/logging.rst:234 msgid "Changing the format of displayed messages" -msgstr "" +msgstr "變更顯示訊息的格式" #: ../../howto/logging.rst:236 msgid "" "To change the format which is used to display messages, you need to specify " "the format you want to use::" -msgstr "" +msgstr "如果你要變更顯示訊息使用的格式,需要指定你想使用的格式,如下: ::" #: ../../howto/logging.rst:239 msgid "" @@ -451,7 +510,7 @@ msgstr "" #: ../../howto/logging.rst:245 msgid "which would print:" -msgstr "" +msgstr "將會印出:" #: ../../howto/logging.rst:247 msgid "" @@ -469,16 +528,21 @@ msgid "" "including variable data) and perhaps to display when the event occurred. " "This is described in the next section." msgstr "" +"需要注意的是,前面範例中出現的'root'已經消失。對於可以出現在格式字串中的完整" +"內容,你可以參閱 :ref:`logrecord-attributes` 的文件,簡單的使用方法是,只使" +"用 *levelname* (嚴重性)、*message* (事件描述,包括變數的值)和可能的顯示事" +"件發生時間。下一個段落會解釋這個。" #: ../../howto/logging.rst:262 msgid "Displaying the date/time in messages" -msgstr "" +msgstr "在訊息中顯示日期/時間" #: ../../howto/logging.rst:264 msgid "" "To display the date and time of an event, you would place '%(asctime)s' in " "your format string::" msgstr "" +"如果想要顯示事件的日期和時間,你可以在你的格式化字串中放置 '%(asctime)s': ::" #: ../../howto/logging.rst:267 msgid "" @@ -492,7 +556,7 @@ msgstr "" #: ../../howto/logging.rst:271 msgid "which should print something like this:" -msgstr "" +msgstr "會顯示以下訊息:" #: ../../howto/logging.rst:273 msgid "2010-12-12 11:41:42,612 is when this event was logged." @@ -504,6 +568,8 @@ msgid "" "or :rfc:`3339`. If you need more control over the formatting of the date/" "time, provide a *datefmt* argument to ``basicConfig``, as in this example::" msgstr "" +"預設的時間/日期格式遵照 ISO8601 或 :rfc:`3339`。如果你想要有更多的時間/日期自" +"訂性,可以在 ``basicConfig`` 傳入 *datefmt* 的引數,如以下範例: ::" #: ../../howto/logging.rst:281 msgid "" @@ -519,7 +585,7 @@ msgstr "" #: ../../howto/logging.rst:285 msgid "which would display something like this:" -msgstr "" +msgstr "會顯示以下訊息:" #: ../../howto/logging.rst:287 msgid "12/12/2010 11:46:36 AM is when this event was logged." @@ -529,11 +595,11 @@ msgstr "" msgid "" "The format of the *datefmt* argument is the same as supported " "by :func:`time.strftime`." -msgstr "" +msgstr "*datefmt* 引數的格式與 :func:`time.strftime` 支援的格式相同。" #: ../../howto/logging.rst:296 msgid "Next Steps" -msgstr "" +msgstr "下一步" #: ../../howto/logging.rst:298 msgid "" @@ -543,6 +609,9 @@ msgid "" "time in reading the following sections. If you're ready for that, grab some " "of your favourite beverage and carry on." msgstr "" +"這個基礎教學就到這裡了。它應該足以讓你開始使用記錄功能。日誌套件還提供了更多" +"功能,但如果想要充分利用它,你需要再花些時間閱讀以下部分。如果你準備好了,就" +"拿起你喜愛的飲料繼續閱讀吧。" #: ../../howto/logging.rst:304 msgid "" @@ -552,6 +621,9 @@ msgid "" "`Python discussion forum `_ and you " "should receive help before too long." msgstr "" +"如果你需要一個簡單的日誌記錄的功能,可以參考上面的例子將它添加到你自己的腳本" +"中。如果你遇到問題或不理解某些內容,可以在 `Python 討論論壇 `_ 的幫助類別中發問,你會很快得到幫助。" #: ../../howto/logging.rst:310 msgid "" @@ -559,42 +631,51 @@ msgid "" "slightly more advanced/in-depth tutorial than the basic one above. After " "that, you can take a look at the :ref:`logging-cookbook`." msgstr "" +"還在嗎?你可以繼續閱讀下面幾節,這比上面的基礎教學稍微進階/深入一些。之後,你" +"可以看看 :ref:`logging-cookbook`。" #: ../../howto/logging.rst:318 msgid "Advanced Logging Tutorial" -msgstr "" +msgstr "進階日誌記錄教學" #: ../../howto/logging.rst:320 +#, fuzzy msgid "" "The logging library takes a modular approach and offers several categories " "of components: loggers, handlers, filters, and formatters." msgstr "" +"日誌記錄庫採用模組化方法,並提供多種類別的元件:記錄器、處理程序、篩選器和格" +"式化程式。" #: ../../howto/logging.rst:323 msgid "Loggers expose the interface that application code directly uses." -msgstr "" +msgstr "記錄器(logger)公開應用程式可以直接使用的介面。" #: ../../howto/logging.rst:324 msgid "" "Handlers send the log records (created by loggers) to the appropriate " "destination." msgstr "" +"處理器 (handlers)將由記錄器 (loggers)建立的日誌紀錄 (log records) 傳送" +"到適當的目的地。" #: ../../howto/logging.rst:326 msgid "" "Filters provide a finer grained facility for determining which log records " "to output." -msgstr "" +msgstr "過濾器 (filters) 提供更精細的機制來決定輸出哪些日誌記錄。" #: ../../howto/logging.rst:328 msgid "Formatters specify the layout of log records in the final output." -msgstr "" +msgstr "格式化(formatters)器指定最終輸出中日誌記錄的佈局。" #: ../../howto/logging.rst:330 msgid "" "Log event information is passed between loggers, handlers, filters and " "formatters in a :class:`LogRecord` instance." msgstr "" +"日誌事件(log event)資訊在記錄器、處理器、 過濾器和格式化器之間透過 :class:" +"`LogRecord` 實例傳遞。" #: ../../howto/logging.rst:333 msgid "" @@ -606,12 +687,19 @@ msgid "" "want, and indicate the area of an application in which a logged message " "originates." msgstr "" +"紀錄是透過呼叫 :class:`Logger` 類別的實例方法(以下稱為 :dfn:`loggers` )來執" +"行。每個實例都有一個名稱,並藉由用點(句號)作為分隔符號的命名空間層次來進行" +"概念化排列。例如,名為 'scan' 的 logger 父級是記錄器 'scan.text'、'scan." +"html' 及 'scan.pdf'。記錄器名稱可以取任何你想要的,並且表示一個應用程式中產生" +"紀錄訊息的區域。" #: ../../howto/logging.rst:340 msgid "" "A good convention to use when naming loggers is to use a module-level " "logger, in each module which uses logging, named as follows::" msgstr "" +"命名記錄器的一個良好慣例是在每個使用記錄的模組中,使用模組級別的記錄器,命名" +"如下: ::" #: ../../howto/logging.rst:343 msgid "logger = logging.getLogger(__name__)" @@ -622,6 +710,7 @@ msgid "" "This means that logger names track the package/module hierarchy, and it's " "intuitively obvious where events are logged just from the logger name." msgstr "" +"這意味著日誌名稱追踪套件/模組階層,因此從日誌名稱可以直觀明瞭事件的記錄位置。" #: ../../howto/logging.rst:348 msgid "" @@ -632,6 +721,10 @@ msgid "" "logger. The functions and the methods have the same signatures. The root " "logger's name is printed as 'root' in the logged output." msgstr "" +"記錄器等級中階層的根稱為根記錄器。這是由函式 :func:`debug`、:func:`info`、:" +"func:`warning`、:func:`error` 和 :func:`critical` 使用的記錄器,這些函式僅調" +"用根記錄器的同名方法。這些函式和方法具有相同的簽章(signature)。根記錄器的名" +"稱在記錄輸出中顯示為 'root'。" #: ../../howto/logging.rst:354 msgid "" @@ -643,6 +736,11 @@ msgid "" "destination class if you have special requirements not met by any of the " "built-in handler classes." msgstr "" +"當然,以不同的目的地記錄訊息是可能的。該套件支援將日誌訊息寫入檔案、HTTP GET/" +"POST 位置、透過 SMTP 的電子郵件、通用的 sockets、隊列、或像 syslog 或 " +"Windows NT 事件日誌等作業系統特定的日誌機制。這些目的地由 :dfn:`handler` 類別" +"提供服務。如果你有特殊需求,而內建的 handler 類別無法滿足,則可以建立自己的日" +"誌目的地類別。" #: ../../howto/logging.rst:361 msgid "" @@ -655,10 +753,15 @@ msgid "" "(``sys.stderr``) and a default format for the displayed message before " "delegating to the root logger to do the actual message output." msgstr "" +"預設情況下,對於所有的日誌訊息都沒有設定目的地。你可以使用教程範例中的 :func:" +"`basicConfig` 指定目的地(例如控制台或檔案)。如果你呼叫 :func:`debug`、:" +"func:`info`、:func:`warning`、:func:`error` 和 :func:`critical` 函式,它們會" +"檢查是否設定目的地,如果沒有,它們會設置目的地為控制台(``sys.stderr``)以及" +"顯示信息的默認格式,然後委派給根記錄器來進行實際的訊息輸出。" #: ../../howto/logging.rst:369 msgid "The default format set by :func:`basicConfig` for messages is:" -msgstr "" +msgstr ":func:`basicConfig` 預設設定的訊息格式為:" #: ../../howto/logging.rst:371 msgid "severity:logger name:message" @@ -670,20 +773,22 @@ msgid "" "the *format* keyword argument. For all options regarding how a format string " "is constructed, see :ref:`formatter-objects`." msgstr "" +"你可以透過傳遞格式字符串到 :func:`basicConfig` 的 *format* 關鍵字引數來進行更" +"改。有關格式字符串構建的所有選項,請參閱 :ref:`formatter-objects`。" #: ../../howto/logging.rst:380 msgid "Logging Flow" -msgstr "" +msgstr "記錄流程" #: ../../howto/logging.rst:382 msgid "" "The flow of log event information in loggers and handlers is illustrated in " "the following diagram." -msgstr "" +msgstr "下面的圖表說明了記錄器(logger)和處理器(handler)中事件資訊的流動。" #: ../../howto/logging.rst:433 msgid "Loggers" -msgstr "" +msgstr "記錄器(Loggers)" #: ../../howto/logging.rst:435 msgid "" @@ -694,16 +799,20 @@ msgid "" "Third, logger objects pass along relevant log messages to all interested log " "handlers." msgstr "" +":class:`Logger` (紀錄器)物件有三個工作。首先,它們向應用程式程式碼公開多個" +"方法,讓應用程式可以在運行時記錄訊息。其次,紀錄器物件基於嚴重性(預設過濾方" +"式)或過濾器物件來決定要處理哪些日誌訊息。第三,紀錄器物件將相關的日誌訊息傳" +"遞給所有感興趣的日誌處理程序。" #: ../../howto/logging.rst:441 msgid "" "The most widely used methods on logger objects fall into two categories: " "configuration and message sending." -msgstr "" +msgstr "記錄器物件上最常使用的方法可分為兩類:配置和傳送訊息。" #: ../../howto/logging.rst:444 msgid "These are the most common configuration methods:" -msgstr "" +msgstr "以下是最常見的設定方法:" #: ../../howto/logging.rst:446 msgid "" @@ -713,6 +822,10 @@ msgid "" "INFO, the logger will handle only INFO, WARNING, ERROR, and CRITICAL " "messages and will ignore DEBUG messages." msgstr "" +":meth:`Logger.setLevel` 指定了一個 logger 所處理的最低嚴重性信息,其中 debug " +"是最低內建的嚴重性等級,而 critical 是最高內建的嚴重性等級。例如,如果嚴重性" +"等級是 INFO,logger 只處理 INFO、WARNING、ERROR 和 CRITICAL 訊息,而會忽略 " +"DEBUG 訊息。" #: ../../howto/logging.rst:452 msgid "" @@ -720,6 +833,9 @@ msgid "" "handler objects from the logger object. Handlers are covered in more detail " "in :ref:`handler-basic`." msgstr "" +":meth:`Logger.addHandler` 和 :meth:`Logger.removeHandler` 可以新增或移除處理" +"器物件到當前的記錄器物件(logger object)。有關處理器的詳細說明,請參閱 :ref:" +"`handler-basic`。" #: ../../howto/logging.rst:456 msgid "" @@ -727,17 +843,19 @@ msgid "" "filter objects from the logger object. Filters are covered in more detail " "in :ref:`filter`." msgstr "" +":meth:`Logger.addFilter` 和 :meth:`Logger.removeFilter` 分別是在記錄器對象中" +"新增和移除過濾器物件。更多關於過濾器的細節可以參閱 :ref:`filter`。" #: ../../howto/logging.rst:460 msgid "" "You don't need to always call these methods on every logger you create. See " "the last two paragraphs in this section." -msgstr "" +msgstr "你並不需要在每個你建立的記錄器上都呼叫這些方法,請參考此節的最後兩段。" #: ../../howto/logging.rst:463 msgid "" "With the logger object configured, the following methods create log messages:" -msgstr "" +msgstr "有了已配置的記錄器物件之後,下列這些方法可以產生日誌訊息:" #: ../../howto/logging.rst:465 msgid "" @@ -751,6 +869,12 @@ msgid "" "keyword of ``exc_info`` and use it to determine whether to log exception " "information." msgstr "" +":meth:`Logger.debug`、:meth:`Logger.info`、:meth:`Logger.warning`、:meth:" +"`Logger.error` 和 :meth:`Logger.critical` 建立一個包含訊息和相應名稱的日誌紀" +"錄。訊息實際上是格式化字串,可以包含 ``%s`` 、 ``%d`` 、 ``%f`` 等的標準字符" +"串替換語法。其餘引數都是對應於訊息中的替換欄位的物件列表。對於 ``**kwargs``," +"日誌記錄函式只關心參數中是否有 ``exc_info`` 的關鍵字,並使用它來確定是否記錄" +"異常訊息。" #: ../../howto/logging.rst:475 msgid "" @@ -759,6 +883,9 @@ msgid "" "dumps a stack trace along with it. Call this method only from an exception " "handler." msgstr "" +":meth:`Logger.exception` 這個方法建立的日誌訊息與 :meth:`Logger.error` 相近。" +"差別在於 :meth:`Logger.exception` 會附上一個程式執行時的堆疊(traceback)。請只" +"將此方法用於例外處理(exception handlers)。" #: ../../howto/logging.rst:479 msgid "" @@ -767,6 +894,8 @@ msgid "" "convenience methods listed above, but this is how to log at custom log " "levels." msgstr "" +":meth:`Logger.log` 需要額外的日誌級別當作明確引數。使用這種方式記錄日誌訊息會" +"比上述方法冗長一些,不過這是使用自定義日誌級別時如何記錄日誌的方式。" #: ../../howto/logging.rst:483 msgid "" @@ -779,6 +908,12 @@ msgid "" "loggers with names of ``foo.bar``, ``foo.bar.baz``, and ``foo.bam`` are all " "descendants of ``foo``." msgstr "" +":func:`getLogger` 會回傳一個指定名稱的日誌物件實例的參照,如果沒有指定名稱," +"則使用 ``root`` 當作其名稱。這些名稱是由點號分隔的層次結構。使用相同名字多次" +"呼叫 :func:`getLogger` 將回傳對相同日誌物件的參考。在層級 list(串列)中層級" +"更低的日誌物件是高級別日誌物件的子物件。例如,對於名稱為 ``foo`` 的日誌物件," +"名稱為 ``foo.bar``、``foo.bar.baz`` 和 ``foo.bam`` 的日誌物件都只是 ``foo`` " +"的子物件。" #: ../../howto/logging.rst:491 msgid "" @@ -791,6 +926,11 @@ msgid "" "the logger is used to determine whether the event is passed to the logger's " "handlers." msgstr "" +"記錄器有一個 *有效級別* 的概念。如果沒有在記錄器上明確設置級別,則使用其父級" +"別作為其有效級別。如果父級沒有設置明確的級別,則檢查 *它* 的父級別,依此類推 " +"- 搜索所有祖先(ancestors),直到找到明確設置的級別。根記錄器始終設置了明確的" +"級別(默認為 ``WARNING`` )。在決定是否處理事件時,記錄器的有效級別用於確定事" +"件是否傳遞給記錄器的處理器。" #: ../../howto/logging.rst:499 msgid "" @@ -801,10 +941,14 @@ msgid "" "needed. (You can, however, turn off propagation by setting the *propagate* " "attribute of a logger to ``False``.)" msgstr "" +"子記錄器會將訊息在其祖先(ancestor)記錄器所關聯的處理程式傳播,因此並不需要" +"為應用程式使用的所有記錄器定義和配置處理器。因此只需要為最高級別的記錄器配置" +"處理器,然後根據需要建立子記錄器即可。(你可以透過將記事本的 *propagate* 屬性" +"設置為 ``False`` 來關閉傳播)" #: ../../howto/logging.rst:510 msgid "Handlers" -msgstr "" +msgstr "處理器" #: ../../howto/logging.rst:512 msgid "" @@ -818,6 +962,12 @@ msgid "" "individual handlers where each handler is responsible for sending messages " "of a specific severity to a specific location." msgstr "" +":class:`~logging.Handler` 物件負責將適當的日誌訊息分派到處理器指定的目的地" +"(根據日誌訊息的嚴重性)。:class:`Logger` (日誌物件)可以使用 :meth:" +"`~Logger.addHandler` 方法向自己添加零個或多個處理器物件。作為一個範例場景,一" +"個應用程式可能想要將所有日誌訊息發送到一個日誌檔案、將所有錯誤或更高級別的日" +"誌訊息發送到 stdout、並將所有嚴重的日誌訊息發送到一個電子郵件地址。這種場景需" +"要三個獨立的處理器,其中每個處理器負責將特定嚴重性的訊息發送到特定位置。" #: ../../howto/logging.rst:522 msgid "" @@ -825,6 +975,8 @@ msgid "" "handlers`); the tutorials use mainly :class:`StreamHandler` " "and :class:`FileHandler` in its examples." msgstr "" +"標準函式庫中包含了相當多的處理器型別(請見 :ref:`useful-handlers`),本教學範" +"例主要會使用 :class:`StreamHandler` 與 :class:`FileHandler`。" #: ../../howto/logging.rst:526 msgid "" @@ -833,6 +985,8 @@ msgid "" "application developers who are using the built-in handler objects (that is, " "not creating custom handlers) are the following configuration methods:" msgstr "" +"對於應用程式開發人員而言,與處理器相關的方法非常少。當使用內置的處理程序物件 " +"(即未建立自定義處理程序) 時,似乎只有以下設置方法對應用程式開發人員有關:" #: ../../howto/logging.rst:531 msgid "" @@ -843,18 +997,25 @@ msgid "" "The level set in each handler determines which messages that handler will " "send on." msgstr "" +":meth:`~Handler.setLevel` 方法在日誌物件中同樣存在,它指定了將會被傳遞至目的" +"地的最低記錄等級。爲什麼有兩個 :func:`setLevel` 方法呢?記錄器中設置的等級決" +"定哪些消息程度會透過該日誌物件傳遞到其處理程序。每個處理器中設置的日誌等級則" +"決定該處理器需要發送哪些訊息。" #: ../../howto/logging.rst:537 msgid "" ":meth:`~Handler.setFormatter` selects a Formatter object for this handler to " "use." msgstr "" +":meth:`~Handler.setFormatter` 方法可為此處理器選擇一個格式化器物件使用。" #: ../../howto/logging.rst:540 msgid "" ":meth:`~Handler.addFilter` and :meth:`~Handler.removeFilter` respectively " "configure and deconfigure filter objects on handlers." msgstr "" +":meth:`~Handler.addFilter` 方法和 :meth:`~Handler.removeFilter` 方法可以分別" +"在處理器中設定或移除過濾物件。" #: ../../howto/logging.rst:543 msgid "" @@ -863,10 +1024,13 @@ msgid "" "that defines the interface that all handlers should have and establishes " "some default behavior that child classes can use (or override)." msgstr "" +"應用程式程式碼不應直接實例化和使用 :class:`Handler` 的實例。相反的,:class:" +"`Handler` 類別是一個基礎類別,它定義了所有處理器應具備的介面(interface),並" +"建立了某些子類別可以使用(或可以覆寫)的預設行為。" #: ../../howto/logging.rst:550 msgid "Formatters" -msgstr "" +msgstr "格式化器 (Formatters)" #: ../../howto/logging.rst:552 msgid "" @@ -877,12 +1041,18 @@ msgid "" "takes three optional arguments -- a message format string, a date format " "string and a style indicator." msgstr "" +"格式化器對象(Formatter objects)設置記錄訊息的最終順序、結構和內容。和基礎" +"的 :class:`logging.Handler` 類別不同,應用程式程式碼可以實例化格式化器類別," +"不過如果應用程式需要特殊行為,則可能需要子類別繼承格式化器。構造函式" +"(condtructor)有三個可選引數 -- 訊息格式字串、日期格式字串和樣式指示器。" #: ../../howto/logging.rst:561 msgid "" "If there is no message format string, the default is to use the raw " "message. If there is no date format string, the default date format is:" msgstr "" +"如果沒有訊息格式字串,預設使用原始訊息。如果沒有日期格式字串,預設的日期格式" +"為:" #: ../../howto/logging.rst:564 msgid "%Y-%m-%d %H:%M:%S" @@ -894,6 +1064,8 @@ msgid "" "``'{'``, or ``'$'``. If one of these is not specified, then ``'%'`` will be " "used." msgstr "" +"在結尾處附加了毫秒,``style`` 是 ``'%'``,``'{'`` 和 ``'$'`` 的其中一個。如果" +"未指定其中任一個,則使用 ``'%'``。" #: ../../howto/logging.rst:571 msgid "" @@ -904,6 +1076,11 @@ msgid "" "arguments), while if the style is ``'$'`` then the message format string " "should conform to what is expected by :meth:`string.Template.substitute`." msgstr "" +"如果 ``style`` 是 ``'%'``,則訊息格式字串使用 ``%()s`` 的樣式" +"字串替換;可能的鍵名已在 :ref:`logrecord-attributes` 中文件化。如果樣式是 " +"``'{'``,則假設訊息格式字串與 :meth:`str.format` 相容(使用關鍵字引數),而如" +"果樣式是 ``'$'``,則訊息格式字串應符合 :meth:`string.Template.substitute` 預" +"期的格式。" #: ../../howto/logging.rst:578 msgid "Added the ``style`` parameter." @@ -915,10 +1092,12 @@ msgid "" "format, the severity of the message, and the contents of the message, in " "that order::" msgstr "" +"下列訊息格式字串將以人類可讀的方式記錄訊息時間、訊息嚴重性和訊息內容,按照這" +"個順序: ::" #: ../../howto/logging.rst:585 msgid "'%(asctime)s - %(levelname)s - %(message)s'" -msgstr "" +msgstr "'%(asctime)s - %(levelname)s - %(message)s'" #: ../../howto/logging.rst:587 msgid "" @@ -930,32 +1109,40 @@ msgid "" "want all logging times to be shown in GMT, set the ``converter`` attribute " "in the Formatter class (to ``time.gmtime`` for GMT display)." msgstr "" +"格式化器使用可自訂的函式,將紀錄的建立時間轉換為元組。預設使用 :func:`time." +"localtime`;如果要針對特定格式化器實例更改此設定,則將該實例的 ``converter`` " +"屬性設置為一個與 :func:`time.localtime` 或 :func:`time.gmtime` 等具有相同簽名" +"的函式。如果要為所有格式化器更改此設定,像是要在所有記錄時間顯示為 GMT 時間," +"可以在格式化器類別中設置 ``converter`` 屬性(以 ``time.gmtime`` 為 GMT 顯" +"示)。" #: ../../howto/logging.rst:597 msgid "Configuring Logging" -msgstr "" +msgstr "設定日誌(Logging)" #: ../../howto/logging.rst:601 msgid "Programmers can configure logging in three ways:" -msgstr "" +msgstr "程序員有三種設定日誌(Logging)的方式:" #: ../../howto/logging.rst:603 msgid "" "Creating loggers, handlers, and formatters explicitly using Python code that " "calls the configuration methods listed above." msgstr "" +"以 Python 程式碼方式呼叫上述設定方法來明確的生成紀錄器 (loggers)、處理器 " +"(handlers),以及格式器 (formatters)。" #: ../../howto/logging.rst:605 msgid "" "Creating a logging config file and reading it using the :func:`fileConfig` " "function." -msgstr "" +msgstr "使用 :func:`fileConfig` 函式來生成一個日誌設定檔並讀取它。" #: ../../howto/logging.rst:607 msgid "" "Creating a dictionary of configuration information and passing it to " "the :func:`dictConfig` function." -msgstr "" +msgstr "建立一個包含設定訊息的字典,並將其傳送給 :func:`dictConfig` 函式。" #: ../../howto/logging.rst:610 msgid "" @@ -963,6 +1150,8 @@ msgid "" "config-api`. The following example configures a very simple logger, a " "console handler, and a simple formatter using Python code::" msgstr "" +"請參閱 :ref:`logging-config-api` 來了解關於最後兩個選項的參考文件。以下示範設" +"定一個非常簡單的紀錄器、控制台處理器和一個使用Python程式碼的簡單格式化器: ::" #: ../../howto/logging.rst:614 msgid "" @@ -997,7 +1186,7 @@ msgstr "" #: ../../howto/logging.rst:640 msgid "" "Running this module from the command line produces the following output:" -msgstr "" +msgstr "在命令行執行這個模組將會產生下列輸出:" #: ../../howto/logging.rst:642 msgid "" @@ -1015,6 +1204,8 @@ msgid "" "identical to those in the example listed above, with the only difference " "being the names of the objects::" msgstr "" +"以下Python模組建立了一個幾乎與上面列表中相同的記錄器(logger)、處理器" +"(handler),和格式化器(formatter),唯一不同之處在於對象名稱的改變: ::" #: ../../howto/logging.rst:655 msgid "" @@ -1036,7 +1227,7 @@ msgstr "" #: ../../howto/logging.rst:670 msgid "Here is the logging.conf file:" -msgstr "" +msgstr "這是 logging.conf 檔案:" #: ../../howto/logging.rst:672 msgid "" @@ -1072,7 +1263,7 @@ msgstr "" #: ../../howto/logging.rst:702 msgid "" "The output is nearly identical to that of the non-config-file-based example:" -msgstr "" +msgstr "輸出結果和非設定文件範例的幾乎完全相同:" #: ../../howto/logging.rst:704 msgid "" @@ -1090,6 +1281,8 @@ msgid "" "Python code approach, mainly separation of configuration and code and the " "ability of noncoders to easily modify the logging properties." msgstr "" +"可以看出使用設定檔的方法相較於使用 Python 程式碼具有一些優點。主要包括分離設" +"定和程式碼、以及使得非開發人員能夠簡單地修改日誌屬性。" #: ../../howto/logging.rst:717 msgid "" @@ -1101,6 +1294,11 @@ msgid "" "configuration. Please refer to the reference documentation for more " "information, and specify ``False`` for this parameter if you wish." msgstr "" +":func:`fileConfig` 函式帶有一個預設參數:``disable_existing_loggers``,其因向" +"後相容的考量而默認值為 ``True``。這可能不符合你的要求,除非它們或祖先" +"(ancestor)明確包含於設定當中,不然會因為它導致在呼叫 :func:`fileConfig` 前" +"已存在的非根記錄器(loggers) 被停用。如需更多資訊請查看參考文件並在本參數中指" +"定值 ``False``。" #: ../../howto/logging.rst:725 msgid "" @@ -1110,6 +1308,10 @@ msgid "" "the logger-disabling behaviour described above, which may not be what you " "want - in which case, provide the key explicitly with a value of ``False``." msgstr "" +"傳遞給 :func:`dictConfig` 的字典也可以使用 ``disable_existing_loggers`` 作為" +"鍵的布林值,如果該項在字典中沒有明確指定,則預設會解釋為 ``True``。這導致了上" +"述關閉 Logger 的行為,可能不是你想要的行為;若是如此,請提供顯式的鍵並以值 " +"\"False\" 提供。" #: ../../howto/logging.rst:735 msgid "" @@ -1121,6 +1323,11 @@ msgid "" "package ``mypackage`` and module ``mymodule``, where ``mypackage`` is " "available on the Python import path)." msgstr "" +"注意,設定檔中引用的類別名稱必須相對於日誌模組,或是可以透過正常匯入方式解析" +"的絕對值。因此你可以使用 :class:`~logging.handlers.WatchedFileHandler` (相對" +"於日誌模組),或者 ``mypackage.mymodule.MyHandler``\\ (表示在套件 " +"``mypackage`` 的模組 ``mymodule`` 中定義一個類別,並確認該套件已在 Python 匯" +"入路徑上)" #: ../../howto/logging.rst:743 msgid "" @@ -1136,12 +1343,19 @@ msgid "" "can construct the dictionary in Python code, receive it in pickled form over " "a socket, or use whatever approach makes sense for your application." msgstr "" +"在 Python 3.2 中,引入了一種使用字典來保存設定資訊的新方法。這提供了上述配置" +"文件方法所提供功能的超集,是推薦用於新應用程式和部署的配置方法。因為 Python " +"字典被用來保存配置資訊,你可以使用不同的方式來填充字典,所以你有更多的選項來" +"進行配置。例如,你可以使用 JSON 格式的配置文件填充配置字典,或者如果你能夠存" +"取到 YAML 處理功能,則可以使用 YAML 格式的文件來填充配置字典。或者當然你可以" +"在 Python 程式碼中建立字典,或透過 socket 以序列化形式接收它,或使用任何對於" +"應用程式合理的方法。" #: ../../howto/logging.rst:755 msgid "" "Here's an example of the same configuration as above, in YAML format for the " "new dictionary-based approach:" -msgstr "" +msgstr "以下是與上述相同的設定範例,採用基於新字典的 YAML 格式:" #: ../../howto/logging.rst:758 msgid "" @@ -1169,18 +1383,21 @@ msgstr "" msgid "" "For more information about logging using a dictionary, see :ref:`logging-" "config-api`." -msgstr "" +msgstr "欲了解如何使用字典進行紀錄,請參考 :ref:`logging-config-api`。" #: ../../howto/logging.rst:783 msgid "What happens if no configuration is provided" -msgstr "" +msgstr "如果未提供設定,會發生什麼" #: ../../howto/logging.rst:785 +#, fuzzy msgid "" "If no logging configuration is provided, it is possible to have a situation " "where a logging event needs to be output, but no handlers can be found to " "output the event." msgstr "" +"如果沒有提供日誌記錄配置,則可能會出現需要輸出日誌記錄事件,但找不到輸出該事" +"件的處理程序的情況。" #: ../../howto/logging.rst:789 msgid "" @@ -1193,31 +1410,42 @@ msgid "" "handler's level is set to ``WARNING``, so all events at this and greater " "severities will be output." msgstr "" +"本事件使用 'handler of last resort' 輸出,該處理程序存儲在 :data:" +"`lastResort` 中。這個內部處理程序不與任何日誌記錄器相關聯,作用類似於 :class:" +"`~logging.StreamHandler`,將事件描述信息寫入當前值 ``sys.stderr``\\ (因此會" +"尊重任何已生效的重定向)。對消息不進行任何格式化處理,僅打印出基本的事件描述" +"信息。處理程序的級別設置為 ``WARNING``,因此將輸出該級別及更高級別的所有事" +"件。" #: ../../howto/logging.rst:800 msgid "For versions of Python prior to 3.2, the behaviour is as follows:" -msgstr "" +msgstr "在 Python 3.2 版本之前的版本,其行為如下:" #: ../../howto/logging.rst:802 msgid "" "If :data:`raiseExceptions` is ``False`` (production mode), the event is " "silently dropped." msgstr "" +"如果 :data:`raiseExceptions` 為 ``False``\\ (正式產品模式),則該事件將會被" +"靜默刪除。" #: ../../howto/logging.rst:805 msgid "" "If :data:`raiseExceptions` is ``True`` (development mode), a message 'No " "handlers could be found for logger X.Y.Z' is printed once." msgstr "" +"如果 :data:`raiseExceptions` 為 ``True``\\ (開發模式),則會列印訊息 'No " +"handlers could be found for logger X.Y.Z'(無法找到日誌記錄器 X.Y.Z 的處理程" +"序)。" #: ../../howto/logging.rst:808 msgid "" "To obtain the pre-3.2 behaviour, :data:`lastResort` can be set to ``None``." -msgstr "" +msgstr "要獲得 3.2 之前的行為,可以將 :data:`lastResort` 設定為 ``None``。" #: ../../howto/logging.rst:814 msgid "Configuring Logging for a Library" -msgstr "" +msgstr "為函式庫設定日誌" #: ../../howto/logging.rst:816 msgid "" @@ -1229,6 +1457,10 @@ msgid "" "of severity ``WARNING`` and greater will be printed to ``sys.stderr``. This " "is regarded as the best default behaviour." msgstr "" +"開發使用 logging 的函式庫時,應該注意函式庫如何使用 logging ,例如日誌記錄器" +"的名稱。也需要考慮到 logging 設定的配置方式。如果應用程式未使用日誌記錄且函式" +"庫程式碼有做出日誌記錄呼叫(如前一節所述),則會將所有大於或等於 ``WARNING`` " +"嚴重性事件列印至 ``sys.stderr`` 中。這被認為是最佳預設行為。" #: ../../howto/logging.rst:824 msgid "" @@ -1241,6 +1473,11 @@ msgid "" "suitably configured then logging calls made in library code will send output " "to those handlers, as normal." msgstr "" +"如果因為某些原因,你 *不希望* 在缺乏任何記錄配置的情況下打印這些訊息,你可以" +"將一個什麼也不做的處理器附加到你函式庫的頂層記錄器。這樣可以避免打印訊息,因" +"為函式庫的事件都會找到對應的處理器:它只是不會產生任何輸出。如果函式庫使用者" +"為應用使用配置日誌,那麼該配置可能會添加一些處理器,如果級別被適當配置,那麼" +"在函式庫程式碼中進行的 logging 呼叫將像平常一樣將輸出發送到這些處理器中。" #: ../../howto/logging.rst:833 msgid "" @@ -1252,6 +1489,11 @@ msgid "" "all logging by a library *foo* is done using loggers with names matching " "'foo.x', 'foo.x.y', etc. then the code::" msgstr "" +"logging 套件中包含了一個什麼也不做的處理器 (do-nothing handler): :class:" +"`~logging.NullHandler`\\ (自 Python 3.1 起)。你可以將此處理器的實例新增至被" +"函式庫使用的 logging 命名空間的頂層記錄器中,( *如果* 你希望在缺少日誌配置的" +"情況下防止函式庫產生的日誌事件被輸出至 ``sys.stderr``\\ )。如果函式庫 *foo* " +"使用的所有記錄器都符合名為 'foo.x','foo.x.y' 等的規則,則程式碼: ::" #: ../../howto/logging.rst:841 msgid "" @@ -1267,6 +1509,8 @@ msgid "" "libraries, then the logger name specified can be 'orgname.foo' rather than " "just 'foo'." msgstr "" +"應該要有預期的結果。如果一個組織生產了多個函式庫,則指定的記錄器名稱會是 " +"'orgname.foo',而不只是 'foo'。" #: ../../howto/logging.rst:848 msgid "" @@ -1277,6 +1521,9 @@ msgid "" "application developer to configure the logging verbosity or handlers of your " "library as they wish." msgstr "" +"強烈建議你 *不要記錄到根記錄器*。而是使用一個具有獨特並易於識別的名稱的記錄" +"器,例如你函式庫的頂層套件或模組的 ``__name__``。如果記錄到根日誌,應用程序開" +"發者將很難或無法在你的函式庫設置他們想要的logging詳細程度和處理器。" #: ../../howto/logging.rst:855 msgid "" @@ -1289,10 +1536,14 @@ msgid "" "with their ability to carry out unit tests and deliver logs which suit their " "requirements." msgstr "" +"非常建議你 *不要在你的處理器中添加除* :class:`~logging.NullHandler` *之外的記" +"錄器到你的函式庫*。這是因為處理器的配置取決於使用你函式庫的應用程式開發人員," +"他們會知道目標受眾以及適合使用那些處理器: 如果在 '幕後' 添加處理器,你可能會" +"干擾他們進行單元測試的能力,並且妨礙他們生成符合自己要求的日誌。" #: ../../howto/logging.rst:866 msgid "Logging Levels" -msgstr "" +msgstr "日誌層級" #: ../../howto/logging.rst:868 msgid "" @@ -1302,10 +1553,13 @@ msgid "" "define a level with the same numeric value, it overwrites the predefined " "value; the predefined name is lost." msgstr "" +"日誌等級的數值定義如下表所示。如果你想要定義自己的等級,並且需要使它們相對於" +"預定義的等級具有特定的值,這些內容會對你非常有幫助。如果你定義一個與預設數值" +"相同的等級,它會覆寫原先對應的預設值;原本預設的名稱也會消失。" #: ../../howto/logging.rst:875 msgid "Numeric value" -msgstr "" +msgstr "數值" #: ../../howto/logging.rst:877 msgid "50" @@ -1344,6 +1598,10 @@ msgid "" "the method call's, no logging message is actually generated. This is the " "basic mechanism controlling the verbosity of logging output." msgstr "" +"級別 (Levels) 也可以與記錄器相關聯,被開發人員設置或透過加載保存的日誌配置。" +"當在記錄器上調用logging方法時,該記錄器將其自身級別和與方法調用相關聯的級別進" +"行比較。如果記錄器的級別高於方法調用的級別,則實際上不會生成任何記錄消息。這" +"是控制日誌輸出冗長程度的基本機制。" #: ../../howto/logging.rst:897 msgid "" @@ -1351,6 +1609,8 @@ msgid "" "class. When a logger decides to actually log an event, " "a :class:`~logging.LogRecord` instance is created from the logging message." msgstr "" +"記錄訊息被編碼成 :class:`~logging.LogRecord` 類別的實例。當記錄器決定要真正地" +"記錄事件時,會從日誌訊息建立 :class:`~logging.LogRecord` 的實例。" #: ../../howto/logging.rst:901 msgid "" @@ -1381,7 +1641,7 @@ msgstr "" #: ../../howto/logging.rst:924 msgid "Custom Levels" -msgstr "" +msgstr "自訂等級" #: ../../howto/logging.rst:926 msgid "" @@ -1398,23 +1658,24 @@ msgstr "" #: ../../howto/logging.rst:939 msgid "Useful Handlers" -msgstr "" +msgstr "有用的處理器" #: ../../howto/logging.rst:941 msgid "" "In addition to the base :class:`Handler` class, many useful subclasses are " "provided:" -msgstr "" +msgstr "除了基礎的 :class:`Handler` 類別,還提供了許多有用的子類別:" #: ../../howto/logging.rst:944 msgid "" ":class:`StreamHandler` instances send messages to streams (file-like " "objects)." msgstr "" +":class:`StreamHandler` 實例會將訊息傳送到資料流(與檔案相似的物件)中。" #: ../../howto/logging.rst:947 msgid ":class:`FileHandler` instances send messages to disk files." -msgstr "" +msgstr ":class:`FileHandler` 實例會將訊息傳送至磁碟檔案。" #: ../../howto/logging.rst:949 msgid "" From 0db7e7986a510a40c0663bfc4a6e239403b018e9 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 23 Jan 2026 08:39:20 +0000 Subject: [PATCH 2/3] style: fix line wrapping in howto/logging.po Run powrap to fix line wrapping issues in the PO file. https://claude.ai/code/session_01FubLSJSpQ2mNDuK2cjMebE --- howto/logging.po | 276 +++++++++++++++++++++++------------------------ 1 file changed, 136 insertions(+), 140 deletions(-) diff --git a/howto/logging.po b/howto/logging.po index 6bb32c2cca..dc534f230d 100644 --- a/howto/logging.po +++ b/howto/logging.po @@ -67,10 +67,10 @@ msgstr "什麼時候使用 logging" #: ../../howto/logging.rst:30 msgid "" "You can access logging functionality by creating a logger via ``logger = " -"getLogger(__name__)``, and then calling the " -"logger's :meth:`~Logger.debug`, :meth:`~Logger.info`, :meth:`~Logger.warning`, :meth:`~Logger.error` " -"and :meth:`~Logger.critical` methods. To determine when to use logging, and " -"to see which logger methods to use when, see the table below. It states, for " +"getLogger(__name__)``, and then calling the logger's :meth:`~Logger.debug`, :" +"meth:`~Logger.info`, :meth:`~Logger.warning`, :meth:`~Logger.error` and :" +"meth:`~Logger.critical` methods. To determine when to use logging, and to " +"see which logger methods to use when, see the table below. It states, for " "each of a set of common tasks, the best tool to use for that task." msgstr "" "日誌(Logging)提供方便使用的一組簡單紀錄函式。這些函式包括::func:`debug`、:" @@ -144,8 +144,8 @@ msgstr "報告錯誤但不引發異常(如長時間執行的伺服器進程中 #: ../../howto/logging.rst:63 msgid "" -"A logger's :meth:`~Logger.error`, :meth:`~Logger.exception` " -"or :meth:`~Logger.critical` method as appropriate for the specific error and " +"A logger's :meth:`~Logger.error`, :meth:`~Logger.exception` or :meth:" +"`~Logger.critical` method as appropriate for the specific error and " "application domain" msgstr "" "根據錯誤及應用領域的特定需要,使用 :func:`logging.error`、:func:`logging." @@ -266,8 +266,8 @@ msgstr "WARNING:root:Watch out!" msgid "" "printed out on the console. The ``INFO`` message doesn't appear because the " "default level is ``WARNING``. The printed message includes the indication of " -"the level and the description of the event provided in the logging call, " -"i.e. 'Watch out!'. The actual output can be formatted quite flexibly if you " +"the level and the description of the event provided in the logging call, i." +"e. 'Watch out!'. The actual output can be formatted quite flexibly if you " "need that; formatting options will also be explained later." msgstr "" "這段訊息顯示在控制台上。由於預設級別為 ``WARNING``,所以 ``INFO`` 訊息並未出" @@ -310,8 +310,8 @@ msgstr "" msgid "" "import logging\n" "logger = logging.getLogger(__name__)\n" -"logging.basicConfig(filename='example.log', encoding='utf-8', " -"level=logging.DEBUG)\n" +"logging.basicConfig(filename='example.log', encoding='utf-8', level=logging." +"DEBUG)\n" "logger.debug('This message should go to the log file')\n" "logger.info('So should this')\n" "logger.warning('And this, too')\n" @@ -319,8 +319,8 @@ msgid "" msgstr "" "import logging\n" "logger = logging.getLogger(__name__)\n" -"logging.basicConfig(filename='example.log', encoding='utf-8', " -"level=logging.DEBUG)\n" +"logging.basicConfig(filename='example.log', encoding='utf-8', level=logging." +"DEBUG)\n" "logger.debug('This message should go to the log file')\n" "logger.info('So should this')\n" "logger.warning('And this, too')\n" @@ -426,11 +426,11 @@ msgstr "" #: ../../howto/logging.rst:204 msgid "" -"logging.basicConfig(filename='example.log', filemode='w', " -"level=logging.DEBUG)" +"logging.basicConfig(filename='example.log', filemode='w', level=logging." +"DEBUG)" msgstr "" -"logging.basicConfig(filename='example.log', filemode='w', " -"level=logging.DEBUG)" +"logging.basicConfig(filename='example.log', filemode='w', level=logging." +"DEBUG)" #: ../../howto/logging.rst:206 msgid "" @@ -495,15 +495,15 @@ msgstr "如果你要變更顯示訊息使用的格式,需要指定你想使用 #: ../../howto/logging.rst:239 msgid "" "import logging\n" -"logging.basicConfig(format='%(levelname)s:%(message)s', " -"level=logging.DEBUG)\n" +"logging.basicConfig(format='%(levelname)s:%(message)s', level=logging." +"DEBUG)\n" "logging.debug('This message should appear on the console')\n" "logging.info('So should this')\n" "logging.warning('And this, too')" msgstr "" "import logging\n" -"logging.basicConfig(format='%(levelname)s:%(message)s', " -"level=logging.DEBUG)\n" +"logging.basicConfig(format='%(levelname)s:%(message)s', level=logging." +"DEBUG)\n" "logging.debug('This message should appear on the console')\n" "logging.info('So should this')\n" "logging.warning('And this, too')" @@ -564,9 +564,9 @@ msgstr "" #: ../../howto/logging.rst:277 msgid "" -"The default format for date/time display (shown above) is like ISO8601 " -"or :rfc:`3339`. If you need more control over the formatting of the date/" -"time, provide a *datefmt* argument to ``basicConfig``, as in this example::" +"The default format for date/time display (shown above) is like ISO8601 or :" +"rfc:`3339`. If you need more control over the formatting of the date/time, " +"provide a *datefmt* argument to ``basicConfig``, as in this example::" msgstr "" "預設的時間/日期格式遵照 ISO8601 或 :rfc:`3339`。如果你想要有更多的時間/日期自" "訂性,可以在 ``basicConfig`` 傳入 *datefmt* 的引數,如以下範例: ::" @@ -593,8 +593,8 @@ msgstr "" #: ../../howto/logging.rst:291 msgid "" -"The format of the *datefmt* argument is the same as supported " -"by :func:`time.strftime`." +"The format of the *datefmt* argument is the same as supported by :func:`time." +"strftime`." msgstr "*datefmt* 引數的格式與 :func:`time.strftime` 支援的格式相同。" #: ../../howto/logging.rst:296 @@ -715,11 +715,10 @@ msgstr "" #: ../../howto/logging.rst:348 msgid "" "The root of the hierarchy of loggers is called the root logger. That's the " -"logger used by the " -"functions :func:`debug`, :func:`info`, :func:`warning`, :func:`error` " -"and :func:`critical`, which just call the same-named method of the root " -"logger. The functions and the methods have the same signatures. The root " -"logger's name is printed as 'root' in the logged output." +"logger used by the functions :func:`debug`, :func:`info`, :func:`warning`, :" +"func:`error` and :func:`critical`, which just call the same-named method of " +"the root logger. The functions and the methods have the same signatures. The " +"root logger's name is printed as 'root' in the logged output." msgstr "" "記錄器等級中階層的根稱為根記錄器。這是由函式 :func:`debug`、:func:`info`、:" "func:`warning`、:func:`error` 和 :func:`critical` 使用的記錄器,這些函式僅調" @@ -746,12 +745,12 @@ msgstr "" msgid "" "By default, no destination is set for any logging messages. You can specify " "a destination (such as console or file) by using :func:`basicConfig` as in " -"the tutorial examples. If you call the " -"functions :func:`debug`, :func:`info`, :func:`warning`, :func:`error` " -"and :func:`critical`, they will check to see if no destination is set; and " -"if one is not set, they will set a destination of the console " -"(``sys.stderr``) and a default format for the displayed message before " -"delegating to the root logger to do the actual message output." +"the tutorial examples. If you call the functions :func:`debug`, :func:" +"`info`, :func:`warning`, :func:`error` and :func:`critical`, they will check " +"to see if no destination is set; and if one is not set, they will set a " +"destination of the console (``sys.stderr``) and a default format for the " +"displayed message before delegating to the root logger to do the actual " +"message output." msgstr "" "預設情況下,對於所有的日誌訊息都沒有設定目的地。你可以使用教程範例中的 :func:" "`basicConfig` 指定目的地(例如控制台或檔案)。如果你呼叫 :func:`debug`、:" @@ -859,15 +858,15 @@ msgstr "有了已配置的記錄器物件之後,下列這些方法可以產生 #: ../../howto/logging.rst:465 msgid "" -":meth:`Logger.debug`, :meth:`Logger.info`, :meth:`Logger.warning`, :meth:`Logger.error`, " -"and :meth:`Logger.critical` all create log records with a message and a " -"level that corresponds to their respective method names. The message is " -"actually a format string, which may contain the standard string substitution " -"syntax of ``%s``, ``%d``, ``%f``, and so on. The rest of their arguments is " -"a list of objects that correspond with the substitution fields in the " -"message. With regard to ``**kwargs``, the logging methods care only about a " -"keyword of ``exc_info`` and use it to determine whether to log exception " -"information." +":meth:`Logger.debug`, :meth:`Logger.info`, :meth:`Logger.warning`, :meth:" +"`Logger.error`, and :meth:`Logger.critical` all create log records with a " +"message and a level that corresponds to their respective method names. The " +"message is actually a format string, which may contain the standard string " +"substitution syntax of ``%s``, ``%d``, ``%f``, and so on. The rest of their " +"arguments is a list of objects that correspond with the substitution fields " +"in the message. With regard to ``**kwargs``, the logging methods care only " +"about a keyword of ``exc_info`` and use it to determine whether to log " +"exception information." msgstr "" ":meth:`Logger.debug`、:meth:`Logger.info`、:meth:`Logger.warning`、:meth:" "`Logger.error` 和 :meth:`Logger.critical` 建立一個包含訊息和相應名稱的日誌紀" @@ -878,10 +877,9 @@ msgstr "" #: ../../howto/logging.rst:475 msgid "" -":meth:`Logger.exception` creates a log message similar " -"to :meth:`Logger.error`. The difference is that :meth:`Logger.exception` " -"dumps a stack trace along with it. Call this method only from an exception " -"handler." +":meth:`Logger.exception` creates a log message similar to :meth:`Logger." +"error`. The difference is that :meth:`Logger.exception` dumps a stack trace " +"along with it. Call this method only from an exception handler." msgstr "" ":meth:`Logger.exception` 這個方法建立的日誌訊息與 :meth:`Logger.error` 相近。" "差別在於 :meth:`Logger.exception` 會附上一個程式執行時的堆疊(traceback)。請只" @@ -972,8 +970,8 @@ msgstr "" #: ../../howto/logging.rst:522 msgid "" "The standard library includes quite a few handler types (see :ref:`useful-" -"handlers`); the tutorials use mainly :class:`StreamHandler` " -"and :class:`FileHandler` in its examples." +"handlers`); the tutorials use mainly :class:`StreamHandler` and :class:" +"`FileHandler` in its examples." msgstr "" "標準函式庫中包含了相當多的處理器型別(請見 :ref:`useful-handlers`),本教學範" "例主要會使用 :class:`StreamHandler` 與 :class:`FileHandler`。" @@ -1019,10 +1017,10 @@ msgstr "" #: ../../howto/logging.rst:543 msgid "" -"Application code should not directly instantiate and use instances " -"of :class:`Handler`. Instead, the :class:`Handler` class is a base class " -"that defines the interface that all handlers should have and establishes " -"some default behavior that child classes can use (or override)." +"Application code should not directly instantiate and use instances of :class:" +"`Handler`. Instead, the :class:`Handler` class is a base class that defines " +"the interface that all handlers should have and establishes some default " +"behavior that child classes can use (or override)." msgstr "" "應用程式程式碼不應直接實例化和使用 :class:`Handler` 的實例。相反的,:class:" "`Handler` 類別是一個基礎類別,它定義了所有處理器應具備的介面(interface),並" @@ -1070,8 +1068,8 @@ msgstr "" #: ../../howto/logging.rst:571 msgid "" "If the ``style`` is ``'%'``, the message format string uses ``%()s`` styled string substitution; the possible keys are documented " -"in :ref:`logrecord-attributes`. If the style is ``'{'``, the message format " +"key>)s`` styled string substitution; the possible keys are documented in :" +"ref:`logrecord-attributes`. If the style is ``'{'``, the message format " "string is assumed to be compatible with :meth:`str.format` (using keyword " "arguments), while if the style is ``'$'`` then the message format string " "should conform to what is expected by :meth:`string.Template.substitute`." @@ -1140,8 +1138,8 @@ msgstr "使用 :func:`fileConfig` 函式來生成一個日誌設定檔並讀取 #: ../../howto/logging.rst:607 msgid "" -"Creating a dictionary of configuration information and passing it to " -"the :func:`dictConfig` function." +"Creating a dictionary of configuration information and passing it to the :" +"func:`dictConfig` function." msgstr "建立一個包含設定訊息的字典,並將其傳送給 :func:`dictConfig` 函式。" #: ../../howto/logging.rst:610 @@ -1166,8 +1164,8 @@ msgid "" "ch.setLevel(logging.DEBUG)\n" "\n" "# create formatter\n" -"formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %" -"(message)s')\n" +"formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - " +"%(message)s')\n" "\n" "# add formatter to ch\n" "ch.setFormatter(formatter)\n" @@ -1317,11 +1315,11 @@ msgstr "" msgid "" "Note that the class names referenced in config files need to be either " "relative to the logging module, or absolute values which can be resolved " -"using normal import mechanisms. Thus, you could use " -"either :class:`~logging.handlers.WatchedFileHandler` (relative to the " -"logging module) or ``mypackage.mymodule.MyHandler`` (for a class defined in " -"package ``mypackage`` and module ``mymodule``, where ``mypackage`` is " -"available on the Python import path)." +"using normal import mechanisms. Thus, you could use either :class:`~logging." +"handlers.WatchedFileHandler` (relative to the logging module) or ``mypackage." +"mymodule.MyHandler`` (for a class defined in package ``mypackage`` and " +"module ``mymodule``, where ``mypackage`` is available on the Python import " +"path)." msgstr "" "注意,設定檔中引用的類別名稱必須相對於日誌模組,或是可以透過正常匯入方式解析" "的絕對值。因此你可以使用 :class:`~logging.handlers.WatchedFileHandler` (相對" @@ -1401,10 +1399,10 @@ msgstr "" #: ../../howto/logging.rst:789 msgid "" -"The event is output using a 'handler of last resort', stored " -"in :data:`lastResort`. This internal handler is not associated with any " -"logger, and acts like a :class:`~logging.StreamHandler` which writes the " -"event description message to the current value of ``sys.stderr`` (therefore " +"The event is output using a 'handler of last resort', stored in :data:" +"`lastResort`. This internal handler is not associated with any logger, and " +"acts like a :class:`~logging.StreamHandler` which writes the event " +"description message to the current value of ``sys.stderr`` (therefore " "respecting any redirections which may be in effect). No formatting is done " "on the message - just the bare event description message is printed. The " "handler's level is set to ``WARNING``, so all events at this and greater " @@ -1481,13 +1479,13 @@ msgstr "" #: ../../howto/logging.rst:833 msgid "" -"A do-nothing handler is included in the logging " -"package: :class:`~logging.NullHandler` (since Python 3.1). An instance of " -"this handler could be added to the top-level logger of the logging namespace " -"used by the library (*if* you want to prevent your library's logged events " -"being output to ``sys.stderr`` in the absence of logging configuration). If " -"all logging by a library *foo* is done using loggers with names matching " -"'foo.x', 'foo.x.y', etc. then the code::" +"A do-nothing handler is included in the logging package: :class:`~logging." +"NullHandler` (since Python 3.1). An instance of this handler could be added " +"to the top-level logger of the logging namespace used by the library (*if* " +"you want to prevent your library's logged events being output to ``sys." +"stderr`` in the absence of logging configuration). If all logging by a " +"library *foo* is done using loggers with names matching 'foo.x', 'foo.x.y', " +"etc. then the code::" msgstr "" "logging 套件中包含了一個什麼也不做的處理器 (do-nothing handler): :class:" "`~logging.NullHandler`\\ (自 Python 3.1 起)。你可以將此處理器的實例新增至被" @@ -1527,14 +1525,13 @@ msgstr "" #: ../../howto/logging.rst:855 msgid "" -"It is strongly advised that you *do not add any handlers other " -"than* :class:`~logging.NullHandler` *to your library's loggers*. This is " -"because the configuration of handlers is the prerogative of the application " -"developer who uses your library. The application developer knows their " -"target audience and what handlers are most appropriate for their " -"application: if you add handlers 'under the hood', you might well interfere " -"with their ability to carry out unit tests and deliver logs which suit their " -"requirements." +"It is strongly advised that you *do not add any handlers other than* :class:" +"`~logging.NullHandler` *to your library's loggers*. This is because the " +"configuration of handlers is the prerogative of the application developer " +"who uses your library. The application developer knows their target audience " +"and what handlers are most appropriate for their application: if you add " +"handlers 'under the hood', you might well interfere with their ability to " +"carry out unit tests and deliver logs which suit their requirements." msgstr "" "非常建議你 *不要在你的處理器中添加除* :class:`~logging.NullHandler` *之外的記" "錄器到你的函式庫*。這是因為處理器的配置取決於使用你函式庫的應用程式開發人員," @@ -1606,37 +1603,37 @@ msgstr "" #: ../../howto/logging.rst:897 msgid "" "Logging messages are encoded as instances of the :class:`~logging.LogRecord` " -"class. When a logger decides to actually log an event, " -"a :class:`~logging.LogRecord` instance is created from the logging message." +"class. When a logger decides to actually log an event, a :class:`~logging." +"LogRecord` instance is created from the logging message." msgstr "" "記錄訊息被編碼成 :class:`~logging.LogRecord` 類別的實例。當記錄器決定要真正地" "記錄事件時,會從日誌訊息建立 :class:`~logging.LogRecord` 的實例。" #: ../../howto/logging.rst:901 msgid "" -"Logging messages are subjected to a dispatch mechanism through the use " -"of :dfn:`handlers`, which are instances of subclasses of " -"the :class:`Handler` class. Handlers are responsible for ensuring that a " -"logged message (in the form of a :class:`LogRecord`) ends up in a particular " -"location (or set of locations) which is useful for the target audience for " -"that message (such as end users, support desk staff, system administrators, " -"developers). Handlers are passed :class:`LogRecord` instances intended for " -"particular destinations. Each logger can have zero, one or more handlers " -"associated with it (via the :meth:`~Logger.addHandler` method " -"of :class:`Logger`). In addition to any handlers directly associated with a " -"logger, *all handlers associated with all ancestors of the logger* are " -"called to dispatch the message (unless the *propagate* flag for a logger is " -"set to a false value, at which point the passing to ancestor handlers stops)." +"Logging messages are subjected to a dispatch mechanism through the use of :" +"dfn:`handlers`, which are instances of subclasses of the :class:`Handler` " +"class. Handlers are responsible for ensuring that a logged message (in the " +"form of a :class:`LogRecord`) ends up in a particular location (or set of " +"locations) which is useful for the target audience for that message (such as " +"end users, support desk staff, system administrators, developers). Handlers " +"are passed :class:`LogRecord` instances intended for particular " +"destinations. Each logger can have zero, one or more handlers associated " +"with it (via the :meth:`~Logger.addHandler` method of :class:`Logger`). In " +"addition to any handlers directly associated with a logger, *all handlers " +"associated with all ancestors of the logger* are called to dispatch the " +"message (unless the *propagate* flag for a logger is set to a false value, " +"at which point the passing to ancestor handlers stops)." msgstr "" #: ../../howto/logging.rst:915 msgid "" "Just as for loggers, handlers can have levels associated with them. A " "handler's level acts as a filter in the same way as a logger's level does. " -"If a handler decides to actually dispatch an event, " -"the :meth:`~Handler.emit` method is used to send the message to its " -"destination. Most user-defined subclasses of :class:`Handler` will need to " -"override this :meth:`~Handler.emit`." +"If a handler decides to actually dispatch an event, the :meth:`~Handler." +"emit` method is used to send the message to its destination. Most user-" +"defined subclasses of :class:`Handler` will need to override this :meth:" +"`~Handler.emit`." msgstr "" #: ../../howto/logging.rst:924 @@ -1681,8 +1678,8 @@ msgstr ":class:`FileHandler` 實例會將訊息傳送至磁碟檔案。" msgid "" ":class:`~handlers.BaseRotatingHandler` is the base class for handlers that " "rotate log files at a certain point. It is not meant to be instantiated " -"directly. Instead, use :class:`~handlers.RotatingFileHandler` " -"or :class:`~handlers.TimedRotatingFileHandler`." +"directly. Instead, use :class:`~handlers.RotatingFileHandler` or :class:" +"`~handlers.TimedRotatingFileHandler`." msgstr "" #: ../../howto/logging.rst:954 @@ -1723,8 +1720,8 @@ msgstr "" #: ../../howto/logging.rst:972 msgid "" -":class:`~handlers.NTEventLogHandler` instances send messages to a Windows NT/" -"2000/XP event log." +":class:`~handlers.NTEventLogHandler` instances send messages to a Windows " +"NT/2000/XP event log." msgstr "" #: ../../howto/logging.rst:975 @@ -1780,27 +1777,27 @@ msgstr "" #: ../../howto/logging.rst:1006 msgid "" -"Logged messages are formatted for presentation through instances of " -"the :class:`Formatter` class. They are initialized with a format string " -"suitable for use with the % operator and a dictionary." +"Logged messages are formatted for presentation through instances of the :" +"class:`Formatter` class. They are initialized with a format string suitable " +"for use with the % operator and a dictionary." msgstr "" #: ../../howto/logging.rst:1010 msgid "" -"For formatting multiple messages in a batch, instances " -"of :class:`BufferingFormatter` can be used. In addition to the format string " -"(which is applied to each message in the batch), there is provision for " -"header and trailer format strings." +"For formatting multiple messages in a batch, instances of :class:" +"`BufferingFormatter` can be used. In addition to the format string (which is " +"applied to each message in the batch), there is provision for header and " +"trailer format strings." msgstr "" #: ../../howto/logging.rst:1015 msgid "" "When filtering based on logger level and/or handler level is not enough, " -"instances of :class:`Filter` can be added to both :class:`Logger` " -"and :class:`Handler` instances (through their :meth:`~Handler.addFilter` " -"method). Before deciding to process a message further, both loggers and " -"handlers consult all their filters for permission. If any filter returns a " -"false value, the message is not processed further." +"instances of :class:`Filter` can be added to both :class:`Logger` and :class:" +"`Handler` instances (through their :meth:`~Handler.addFilter` method). " +"Before deciding to process a message further, both loggers and handlers " +"consult all their filters for permission. If any filter returns a false " +"value, the message is not processed further." msgstr "" #: ../../howto/logging.rst:1022 @@ -1826,16 +1823,16 @@ msgstr "" msgid "" ":class:`SystemExit` and :class:`KeyboardInterrupt` exceptions are never " "swallowed. Other exceptions which occur during the :meth:`~Handler.emit` " -"method of a :class:`Handler` subclass are passed to " -"its :meth:`~Handler.handleError` method." +"method of a :class:`Handler` subclass are passed to its :meth:`~Handler." +"handleError` method." msgstr "" #: ../../howto/logging.rst:1042 msgid "" -"The default implementation of :meth:`~Handler.handleError` " -"in :class:`Handler` checks to see if a module-level " -"variable, :data:`raiseExceptions`, is set. If set, a traceback is printed " -"to :data:`sys.stderr`. If not set, the exception is swallowed." +"The default implementation of :meth:`~Handler.handleError` in :class:" +"`Handler` checks to see if a module-level variable, :data:`raiseExceptions`, " +"is set. If set, a traceback is printed to :data:`sys.stderr`. If not set, " +"the exception is swallowed." msgstr "" #: ../../howto/logging.rst:1048 @@ -1854,12 +1851,12 @@ msgstr "" msgid "" "In the preceding sections and examples, it has been assumed that the message " "passed when logging the event is a string. However, this is not the only " -"possibility. You can pass an arbitrary object as a message, and " -"its :meth:`~object.__str__` method will be called when the logging system " -"needs to convert it to a string representation. In fact, if you want to, you " -"can avoid computing a string representation altogether - for example, " -"the :class:`~handlers.SocketHandler` emits an event by pickling it and " -"sending it over the wire." +"possibility. You can pass an arbitrary object as a message, and its :meth:" +"`~object.__str__` method will be called when the logging system needs to " +"convert it to a string representation. In fact, if you want to, you can " +"avoid computing a string representation altogether - for example, the :class:" +"`~handlers.SocketHandler` emits an event by pickling it and sending it over " +"the wire." msgstr "" #: ../../howto/logging.rst:1071 @@ -1871,10 +1868,10 @@ msgid "" "Formatting of message arguments is deferred until it cannot be avoided. " "However, computing the arguments passed to the logging method can also be " "expensive, and you may want to avoid doing it if the logger will just throw " -"away your event. To decide what to do, you can call " -"the :meth:`~Logger.isEnabledFor` method which takes a level argument and " -"returns true if the event would be created by the Logger for that level of " -"call. You can write code like this::" +"away your event. To decide what to do, you can call the :meth:`~Logger." +"isEnabledFor` method which takes a level argument and returns true if the " +"event would be created by the Logger for that level of call. You can write " +"code like this::" msgstr "" #: ../../howto/logging.rst:1081 @@ -1924,10 +1921,9 @@ msgstr "" #: ../../howto/logging.rst:1105 msgid "" -"Set ``logging._srcfile`` to ``None``. This avoids " -"calling :func:`sys._getframe`, which may help to speed up your code in " -"environments like PyPy (which can't speed up code that " -"uses :func:`sys._getframe`)." +"Set ``logging._srcfile`` to ``None``. This avoids calling :func:`sys." +"_getframe`, which may help to speed up your code in environments like PyPy " +"(which can't speed up code that uses :func:`sys._getframe`)." msgstr "" #: ../../howto/logging.rst:1111 From 5477e5638adedc539d4a71cb08bbff1c850c9d76 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 23 Jan 2026 08:48:38 +0000 Subject: [PATCH 3/3] fix: correct inconsistent RST references in logging.po Fix inconsistent term references at line 195 where :meth:`~Logger.debug` and :meth:`~Logger.info` were incorrectly translated as :func:`debug` and :func:`info`. https://claude.ai/code/session_01FubLSJSpQ2mNDuK2cjMebE --- howto/logging.po | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/howto/logging.po b/howto/logging.po index dc534f230d..747a6ec22c 100644 --- a/howto/logging.po +++ b/howto/logging.po @@ -408,10 +408,9 @@ msgid "" "methods such as :meth:`~Logger.debug`, :meth:`~Logger.info`, etc. Otherwise, " "that logging event may not be handled in the desired manner." msgstr "" -":func:`basicConfig` 的呼叫應該放在任何關於 :func:`debug` 、 :func:`info` 等的" -"呼叫 *之前* ,否則這些功能就會以預設選項自動呼叫 :func:`basicConfig`。由於它" -"旨在作為一次性的簡單配置工具,只有第一個呼叫才能真正執行:後續的呼叫基本上是" -"無操作(no-ops)。" +":func:`basicConfig` 的呼叫應該放在任何對記錄器方法的呼叫 *之前*,例如 :meth:" +"`~Logger.debug`、:meth:`~Logger.info` 等。否則,該日誌事件可能無法以預期的方" +"式處理。" #: ../../howto/logging.rst:199 msgid ""