diff --git a/howto/logging.po b/howto/logging.po index d22ef0a2b32..18f5260ffdb 100644 --- a/howto/logging.po +++ b/howto/logging.po @@ -3,6 +3,7 @@ # # Translators: # 文俊 高 , 2016 +# CTHua , 2023 msgid "" msgstr "" "Project-Id-Version: Python 3.14\n" @@ -20,7 +21,7 @@ msgstr "" #: ../../howto/logging.rst:5 msgid "Logging HOWTO" -msgstr "如何使用 Logging 模組" +msgstr "如何使用日誌記錄 (Logging)" #: ../../howto/logging.rst:0 msgid "Author" @@ -35,10 +36,12 @@ 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" -msgstr "基礎 Logging 指南" +msgstr "基礎日誌記錄教學" #: ../../howto/logging.rst:19 msgid "" @@ -50,10 +53,10 @@ msgid "" "which the developer ascribes to the event; the importance can also be called " "the *level* or *severity*." msgstr "" -"軟體執行時,追蹤有什麼事件發生的動作稱為 Logging。軟體開發者會使用 Logging 這" -"樣的機制是因為想知道在運行過程中是否有特定的事件發生。事件會被一段訊息所描" -"述。這段訊息可能包含一些因為此事件發生而改變的資料。開發者也可以指派事件的重" -"要程度,重要程度有時候也會被稱作 *程度* 或是 *嚴重性* 。" +"軟體執行時,追蹤有什麼事件發生的動作稱為 Logging。軟體開發者會在程式碼中加入日" +"誌記錄呼叫,以表示特定事件已經發生。事件會以一段描述訊息來說明,訊息中可以選擇" +"性地包含變數資料(即每次事件發生時都可能不同的資料)。開發者也會為事件指定重要" +"程度,重要程度也可以稱為\\ *等級* (level) 或\\ *嚴重性* (severity)。" #: ../../howto/logging.rst:28 msgid "When to use logging" @@ -68,19 +71,24 @@ 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 "" +"你可以透過 ``logger = logging.getLogger(__name__)`` 建立一個記錄器 (logger) 來" +"存取日誌記錄功能,然後呼叫記錄器的 :meth:`~Logger.debug`、" +":meth:`~Logger.info`、:meth:`~Logger.warning`、:meth:`~Logger.error` 和 " +":meth:`~Logger.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,50 @@ 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 "" +"記錄器的 :meth:`~Logger.info` 方法(若需要用於診斷的非常詳細輸出,則使用 " +":meth:`~Logger.debug` 方法)" #: ../../howto/logging.rst:49 msgid "Issue a warning regarding a particular runtime event" -msgstr "" +msgstr "針對特定的 runtime 事件發出警告" #: ../../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 "" +"如果客戶端應用程式無法處理該情況,但該事件仍應被注意,可以使用記錄器的 " +":meth:`~Logger.warning` 方法" #: ../../howto/logging.rst:60 msgid "Report an error regarding a particular runtime event" -msgstr "" +msgstr "回報與特定 runtime 事件相關的錯誤" #: ../../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 "" +"回報一個被抑制而未引發例外的錯誤(例如長時間執行的伺服器行程中的錯誤處理器)" #: ../../howto/logging.rst:63 msgid "" @@ -134,6 +149,8 @@ msgid "" "`~Logger.critical` method as appropriate for the specific error and " "application domain" msgstr "" +"依特定錯誤及應用領域的需要,使用記錄器的 :meth:`~Logger.error`、" +":meth:`~Logger.exception` 或 :meth:`~Logger.critical` 方法" #: ../../howto/logging.rst:70 msgid "" @@ -141,14 +158,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 +176,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 +184,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 +196,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 +207,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 +217,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 +225,8 @@ msgid "" "severity and higher will be tracked, unless the logging package is " "configured to do otherwise." msgstr "" +"預設等級為 ``WARNING``,這表示除非 logging 套件被設定為其他行為,否則只會追蹤此" +"嚴重性及以上的事件。" #: ../../howto/logging.rst:100 msgid "" @@ -211,6 +234,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 +257,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 +271,9 @@ msgid "" "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!'。如" +"果需要,實際輸出可以非常彈性地格式化;格式化選項也會在稍後說明。" #: ../../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,16 @@ 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 +359,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 +376,7 @@ 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 "" +"來取得要透過 *level* 引數傳給 :func:`basicConfig` 的值。你可能會想對使用者輸入" +"的值做錯誤檢查,例如以下範例: ::" #: ../../howto/logging.rst:187 msgid "" @@ -364,6 +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` 的呼叫應該放在任何對記錄器方法(例如 " +":meth:`~Logger.debug`、:meth:`~Logger.info` 等)的呼叫\\ *之前*。否則,該日誌事" +"件可能無法以預期的方式處理。" #: ../../howto/logging.rst:199 msgid "" @@ -372,6 +419,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 +436,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 +460,7 @@ msgstr "" #: ../../howto/logging.rst:219 msgid "will display:" -msgstr "" +msgstr "會顯示:" #: ../../howto/logging.rst:221 msgid "WARNING:root:Look before you leap!" @@ -422,16 +475,21 @@ msgid "" "options *are* supported, but exploring them is outside the scope of this " "tutorial: see :ref:`formatting-styles` for more information." msgstr "" +"如你所見,將變數資料合併到事件描述訊息中使用的是舊的 %-style 字串格式化方式。這" +"是為了向後相容: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 +509,7 @@ msgstr "" #: ../../howto/logging.rst:245 msgid "which would print:" -msgstr "" +msgstr "這將會印出:" #: ../../howto/logging.rst:247 msgid "" @@ -469,16 +527,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 +555,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 +567,9 @@ msgid "" "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 "" +"這個基礎教學就到這裡了。它應該足以讓你開始使用 logging。logging 套件還提供了更" +"多功能,但如果想要充分利用它,你需要再花些時間閱讀以下章節。如果你準備好了,就" +"拿杯你喜愛的飲料繼續閱讀吧。" #: ../../howto/logging.rst:304 msgid "" @@ -552,6 +621,10 @@ msgid "" "`Python discussion forum `_ and you " "should receive help before too long." msgstr "" +"如果你的日誌需求很簡單,可以參考上面的範例將 logging 加入你自己的腳本中。如果你" +"遇到問題或不理解某些內容,可以在 `Python 討論論壇 " +"`_ 的 Help 分類中發問,應該很快就會得到幫" +"助。" #: ../../howto/logging.rst:310 msgid "" @@ -559,42 +632,49 @@ 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 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 "" +"處理器 (handler) 將(由記錄器建立的)日誌紀錄 (log record) 傳送到適當的目的地。" #: ../../howto/logging.rst:326 msgid "" "Filters provide a finer grained facility for determining which log records " "to output." -msgstr "" +msgstr "過濾器 (filter) 提供更精細的機制來決定要輸出哪些日誌紀錄。" #: ../../howto/logging.rst:328 msgid "Formatters specify the layout of log records in the final output." -msgstr "" +msgstr "格式化器 (formatter) 指定日誌紀錄在最終輸出中的格式。" #: ../../howto/logging.rst:330 msgid "" "Log event information is passed between loggers, handlers, filters and " "formatters in a :class:`LogRecord` instance." msgstr "" +"日誌事件資訊在記錄器、處理器、過濾器和格式化器之間透過 :class:`LogRecord` 實例" +"傳遞。" #: ../../howto/logging.rst:333 msgid "" @@ -606,12 +686,19 @@ msgid "" "want, and indicate the area of an application in which a logged message " "originates." msgstr "" +"記錄是透過呼叫 :class:`Logger` 類別實例(以下稱為 :dfn:`loggers`\\ )上的方法來" +"進行。每個實例都有一個名稱,並在概念上以點(句號)作為分隔符號排列成命名空間階" +"層。例如,名為 'scan' 的記錄器是記錄器 '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 "" +"命名記錄器的一個良好慣例,是在每個使用 logging 的模組中使用模組層級的記錄器,並" +"如下命名: ::" #: ../../howto/logging.rst:343 msgid "logger = logging.getLogger(__name__)" @@ -622,6 +709,8 @@ 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 "" @@ -631,6 +720,10 @@ msgid "" "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 "" +"記錄器階層的根部稱為根記錄器 (root logger)。這是由函式 :func:`debug`、" +":func:`info`、:func:`warning`、:func:`error` 和 :func:`critical` 使用的記錄器," +"這些函式僅呼叫根記錄器的同名方法。這些函式和方法具有相同的簽名。根記錄器的名稱" +"在記錄輸出中顯示為 'root'。" #: ../../howto/logging.rst:354 msgid "" @@ -642,6 +735,11 @@ msgid "" "destination class if you have special requirements not met by any of the " "built-in handler classes." msgstr "" +"當然,也可以將訊息記錄到不同的目的地。該套件支援將日誌訊息寫入檔案、HTTP " +"GET/POST 位置、透過 SMTP 寄送的電子郵件、通用 socket、佇列,或像 syslog 或 " +"Windows NT 事件日誌等作業系統特定的日誌機制。這些目的地由\\ :dfn:`處理器` " +"(handler) 類別負責。如果你有內建處理器類別無法滿足的特殊需求,可以建立自己的日" +"誌目的地類別。" #: ../../howto/logging.rst:361 msgid "" @@ -654,10 +752,15 @@ msgid "" "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" @@ -669,20 +772,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 "下圖說明了日誌事件資訊在記錄器和處理器中的流程。" #: ../../howto/logging.rst:433 msgid "Loggers" -msgstr "" +msgstr "記錄器 (Loggers)" #: ../../howto/logging.rst:435 msgid "" @@ -693,16 +798,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 "" @@ -712,6 +821,9 @@ msgid "" "INFO, the logger will handle only INFO, WARNING, ERROR, and CRITICAL " "messages and will ignore DEBUG messages." msgstr "" +":meth:`Logger.setLevel` 指定記錄器會處理的最低嚴重性日誌訊息,其中 debug 是內建" +"最低的嚴重性等級,而 critical 是內建最高的嚴重性等級。例如,如果嚴重性等級是 " +"INFO,記錄器只會處理 INFO、WARNING、ERROR 和 CRITICAL 訊息,並忽略 DEBUG 訊息。" #: ../../howto/logging.rst:452 msgid "" @@ -719,6 +831,8 @@ msgid "" "handler objects from the logger object. Handlers are covered in more detail " "in :ref:`handler-basic`." msgstr "" +":meth:`Logger.addHandler` 和 :meth:`Logger.removeHandler` 可以在記錄器物件中新" +"增或移除處理器物件。有關處理器的詳細說明,請參閱 :ref:`handler-basic`。" #: ../../howto/logging.rst:456 msgid "" @@ -726,17 +840,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 "" @@ -750,6 +866,12 @@ msgid "" "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` 都會建立一筆日誌紀錄,其中包含" +"訊息以及與各自方法名稱對應的等級。訊息實際上是格式字串,可以包含 ``%s``、" +"``%d``、``%f`` 等標準字串替換語法。其餘的引數則是與訊息中替換欄位相對應的物件串" +"列。至於 ``**kwargs``,記錄方法只關心 ``exc_info`` 這個關鍵字,並以它來決定是否" +"記錄例外資訊。" #: ../../howto/logging.rst:475 msgid "" @@ -757,6 +879,9 @@ msgid "" "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` 會同時傾印出堆疊追蹤 (stack trace)。請只在例外處理器中" +"呼叫此方法。" #: ../../howto/logging.rst:479 msgid "" @@ -765,6 +890,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 "" @@ -777,6 +904,11 @@ msgid "" "loggers with names of ``foo.bar``, ``foo.bar.baz``, and ``foo.bam`` are all " "descendants of ``foo``." msgstr "" +":func:`getLogger` 會回傳指定名稱的記錄器實例的參照,若未提供名稱則回傳 " +"``root``。名稱是以點號分隔的階層結構。以相同名稱多次呼叫 :func:`getLogger` 會回" +"傳同一個記錄器物件的參照。在階層中位置較低的記錄器是位置較高之記錄器的子記錄器" +"。例如,對於名稱為 ``foo`` 的記錄器,名稱為 ``foo.bar``、``foo.bar.baz`` 和 " +"``foo.bam`` 的記錄器都是 ``foo`` 的後代。" #: ../../howto/logging.rst:491 msgid "" @@ -789,6 +921,11 @@ msgid "" "the logger is used to determine whether the event is passed to the logger's " "handlers." msgstr "" +"記錄器有\\ *有效等級* (effective level) 的概念。如果記錄器上沒有明確設定等級" +",則會改用其父記錄器的等級作為有效等級。如果父記錄器也沒有明確設定等級,就再檢" +"查\\ *它的*\\ 父記錄器,依此類推——會往上搜尋所有上層記錄器,直到找到明確設定的" +"等級為止。根記錄器一定有明確設定的等級(預設為 ``WARNING``)。在決定是否處理某" +"個事件時,會使用記錄器的有效等級來判斷該事件是否要傳遞給記錄器的處理器。" #: ../../howto/logging.rst:499 msgid "" @@ -799,10 +936,14 @@ msgid "" "needed. (You can, however, turn off propagation by setting the *propagate* " "attribute of a logger to ``False``.)" msgstr "" +"子記錄器會將訊息向上傳播給與其上層記錄器關聯的處理器。因此,不需要為應用程式使" +"用的所有記錄器定義和設定處理器,只需要為最上層的記錄器設定處理器,然後依需要建" +"立子記錄器即可。(不過,你可以將記錄器的 *propagate* 屬性設為 ``False`` 來關閉" +"傳播。)" #: ../../howto/logging.rst:510 msgid "Handlers" -msgstr "" +msgstr "處理器 (Handlers)" #: ../../howto/logging.rst:512 msgid "" @@ -816,6 +957,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` " +"方法替自己新增零個或多個處理器物件。舉例來說,一個應用程式可能想要將所有日誌訊" +"息發送到日誌檔、將所有 error 或更高等級的日誌訊息發送到 stdout,並將所有 " +"critical 訊息發送到某個電子郵件地址。這個情境需要三個獨立的處理器,每個處理器負" +"責將特定嚴重性的訊息發送到特定位置。" #: ../../howto/logging.rst:522 msgid "" @@ -823,6 +970,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 "" @@ -831,6 +980,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 "" @@ -841,18 +992,25 @@ msgid "" "The level set in each handler determines which messages that handler will " "send on." msgstr "" +":meth:`~Handler.setLevel` 方法與記錄器物件中的一樣,指定了會被分派到適當目的地" +"的最低嚴重性。為什麼會有兩個 :meth:`~Handler.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 "" @@ -861,10 +1019,13 @@ msgid "" "the interface that all handlers should have and establishes some default " "behavior that child classes can use (or override)." msgstr "" +"應用程式程式碼不應直接實例化和使用 :class:`Handler` 的實例。:class:`Handler` 類" +"別是一個基礎類別,它定義了所有處理器應具備的介面,並建立了一些子類別可以使用(" +"或覆寫)的預設行為。" #: ../../howto/logging.rst:550 msgid "Formatters" -msgstr "" +msgstr "格式化器 (Formatters)" #: ../../howto/logging.rst:552 msgid "" @@ -875,12 +1036,18 @@ msgid "" "takes three optional arguments -- a message format string, a date format " "string and a style indicator." msgstr "" +"格式化器物件設定日誌訊息的最終順序、結構和內容。和基礎的 " +":class:`logging.Handler` 類別不同,應用程式程式碼可以實例化格式化器類別,不過如" +"果應用程式需要特殊行為,你可能會想建立格式化器的子類別。建構函式有三個可選引數" +"——訊息格式字串、日期格式字串和樣式指示器。" #: ../../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" @@ -892,6 +1059,8 @@ msgid "" "``'{'``, or ``'$'``. If one of these is not specified, then ``'%'`` will be " "used." msgstr "" +"並在結尾附加毫秒。``style`` 是 ``'%'``、``'{'`` 或 ``'$'`` 其中之一。如果未指定" +",則使用 ``'%'``。" #: ../../howto/logging.rst:571 msgid "" @@ -902,6 +1071,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." @@ -913,10 +1087,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 "" @@ -928,32 +1104,38 @@ 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 顯示,可" +"在 Formatter 類別中設定 ``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 "開發者有三種設定日誌的方式:" #: ../../howto/logging.rst:603 msgid "" "Creating loggers, handlers, and formatters explicitly using Python code that " "calls the configuration methods listed above." -msgstr "" +msgstr "以 Python 程式碼呼叫上述設定方法來明確地建立記錄器、處理器和格式化器。" #: ../../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 "" @@ -961,6 +1143,9 @@ 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 "" @@ -995,7 +1180,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 "" @@ -1013,6 +1198,8 @@ msgid "" "identical to those in the example listed above, with the only difference " "being the names of the objects::" msgstr "" +"以下 Python 模組建立的記錄器、處理器和格式化器幾乎與上面範例中的相同,唯一的差" +"別是物件的名稱: ::" #: ../../howto/logging.rst:655 msgid "" @@ -1034,7 +1221,7 @@ msgstr "" #: ../../howto/logging.rst:670 msgid "Here is the logging.conf file:" -msgstr "" +msgstr "下面是 logging.conf 檔案:" #: ../../howto/logging.rst:672 msgid "" @@ -1070,7 +1257,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 "" @@ -1088,6 +1275,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 "" @@ -1099,6 +1288,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``。這可能不是你想要的,因為除非在設定中明確指名這" +"些記錄器(或其上層記錄器),否則它會導致在呼叫 :func:`fileConfig` 之前就已存在" +"的所有非根記錄器被停用。如需更多資訊請參閱參考文件,如有需要,可將此參數指定為" +" ``False``。" #: ../../howto/logging.rst:725 msgid "" @@ -1108,6 +1302,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``。這會導致上述" +"停用記錄器的行為,而這可能不是你想要的;若是如此,請明確提供此鍵並將值設為 " +"``False``。" #: ../../howto/logging.rst:735 msgid "" @@ -1119,6 +1317,11 @@ msgid "" "module ``mymodule``, where ``mypackage`` is available on the Python import " "path)." msgstr "" +"注意,設定檔中引用的類別名稱必須是相對於 logging 模組的名稱,或是可以透過一般引" +"入機制解析的絕對名稱。因此,你可以使用 " +":class:`~logging.handlers.WatchedFileHandler`\\ (相對於 logging 模組),或是 " +"``mypackage.mymodule.MyHandler``\\ (表示定義在套件 ``mypackage`` 的模組 " +"``mymodule`` 中的類別,且 ``mypackage`` 可在 Python 的引入路徑中找到)。" #: ../../howto/logging.rst:743 msgid "" @@ -1134,12 +1337,18 @@ 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 以 pickle 形式接收它,或使用任何適合你應用程式的方式。" #: ../../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 "" @@ -1168,10 +1377,11 @@ msgid "" "For more information about logging using a dictionary, see :ref:`logging-" "config-api`." msgstr "" +"欲了解更多使用字典進行日誌設定的資訊,請參考 :ref:`logging-config-api`。" #: ../../howto/logging.rst:783 msgid "What happens if no configuration is provided" -msgstr "" +msgstr "如果未提供設定,會發生什麼" #: ../../howto/logging.rst:785 msgid "" @@ -1179,6 +1389,8 @@ msgid "" "where a logging event needs to be output, but no handlers can be found to " "output the event." msgstr "" +"如果沒有提供日誌設定,則可能會出現需要輸出日誌事件,但找不到處理器來輸出該事件" +"的情況。" #: ../../howto/logging.rst:789 msgid "" @@ -1191,31 +1403,41 @@ 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'。" #: ../../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 "" @@ -1227,6 +1449,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,而函式庫程式碼有呼叫 logging,那麼(如上一節所述)嚴重性為 " +"``WARNING`` 及以上的事件會被印到 ``sys.stderr``。這被視為最佳的預設行為。" #: ../../howto/logging.rst:824 msgid "" @@ -1239,6 +1465,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 "" @@ -1250,6 +1481,11 @@ msgid "" "library *foo* is done using loggers with names matching 'foo.x', 'foo.x.y', " "etc. then the code::" msgstr "" +"logging 套件中包含了一個什麼也不做的處理器::class:`~logging.NullHandler`\\ (" +"自 Python 3.1 起)。可以將此處理器的實例新增到函式庫所使用的 logging 命名空間的" +"頂層記錄器中(\\ *如果*\\ 你希望在沒有日誌設定的情況下,防止函式庫的日誌事件被" +"輸出到 ``sys.stderr``)。如果函式庫 *foo* 的所有日誌記錄都是透過名稱符合 " +"'foo.x'、'foo.x.y' 等的記錄器來進行,那麼以下程式碼: ::" #: ../../howto/logging.rst:841 msgid "" @@ -1265,6 +1501,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 "" @@ -1275,6 +1513,9 @@ msgid "" "application developer to configure the logging verbosity or handlers of your " "library as they wish." msgstr "" +"強烈建議你在函式庫中\\ *不要記錄到根記錄器*。請改用一個具有獨特且易於識別名稱的" +"記錄器,例如你函式庫頂層套件或模組的 ``__name__``。記錄到根記錄器會讓應用程式開" +"發者很難或無法依自己的需求設定你函式庫的日誌詳細程度或處理器。" #: ../../howto/logging.rst:855 msgid "" @@ -1286,10 +1527,15 @@ msgid "" "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` *之" +"外的處理器*。這是因為處理器的設定是使用你函式庫的應用程式開發人員的特權。應用程" +"式開發人員了解他們的目標受眾,也知道哪些處理器最適合他們的應用程式:如果你在「" +"幕後」新增處理器,很可能會干擾他們進行單元測試,以及產出符合其需求之日誌的能力" +"。" #: ../../howto/logging.rst:866 msgid "Logging Levels" -msgstr "" +msgstr "日誌等級" #: ../../howto/logging.rst:868 msgid "" @@ -1299,10 +1545,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" @@ -1341,6 +1590,10 @@ msgid "" "the method call's, no logging message is actually generated. This is the " "basic mechanism controlling the verbosity of logging output." msgstr "" +"等級也可以與記錄器關聯,由開發人員設定或透過載入已儲存的日誌設定來設定。當在記" +"錄器上呼叫記錄方法時,記錄器會將自己的等級與該方法呼叫所對應的等級進行比較。如" +"果記錄器的等級高於方法呼叫的等級,就不會真的產生日誌訊息。這是控制日誌輸出詳細" +"程度的基本機制。" #: ../../howto/logging.rst:897 msgid "" @@ -1348,6 +1601,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 "" @@ -1378,7 +1633,7 @@ msgstr "" #: ../../howto/logging.rst:924 msgid "Custom Levels" -msgstr "" +msgstr "自訂等級" #: ../../howto/logging.rst:926 msgid "" @@ -1395,23 +1650,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 ""