{"title":"로깅","version":"6.1","locale":"ko","docname":"topics/logging","url":"/ko/6.1/topics/logging/","canonical":"https://djangodocs.dev/ko/6.1/topics/logging/","summary":"더 보기 로깅 구성 및 사용 방법 Django 로깅 참조 Python programmers will often use print() in their code as a quick and convenient debugging tool. Using the logging framework is…","html":"<span id=\"logging-explanation\"></span><h1>로깅<a class=\"heading-anchor\" href=\"#logging\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<aside class=\"admonition admonition-seealso\">\n<p class=\"admonition-title\">더 보기</p>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"/ko/6.1/howto/logging/#logging-how-to\"><span class=\"std std-ref\">로깅 구성 및 사용 방법</span></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/ko/6.1/ref/logging/#logging-ref\"><span class=\"std std-ref\">Django 로깅 참조</span></a></p></li>\n</ul>\n</aside>\n<p>Python programmers will often use <code class=\"docutils literal notranslate\"><span class=\"pre\">print()</span></code> in their code as a quick and\nconvenient debugging tool. Using the logging framework is only a little more\neffort than that, but it’s much more elegant and flexible. As well as being\nuseful for debugging, logging can also provide you with more - and better\nstructured - information about the state and health of your application.</p>\n<section id=\"overview\">\n<h2>개요<a class=\"heading-anchor\" href=\"#overview\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Django uses and extends Python’s builtin <a class=\"reference external\" href=\"https://docs.python.org/3/library/logging.html#module-logging\" title=\"(Python v3.14에서)\"><code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">logging</span></code></a> module to perform\nsystem logging. This module is discussed in detail in Python’s own\ndocumentation; this section provides a quick overview.</p>\n<section id=\"the-cast-of-players\">\n<h3>The cast of players<a class=\"heading-anchor\" href=\"#the-cast-of-players\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>A Python logging configuration consists of four parts:</p>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"#topic-logging-parts-loggers\"><span class=\"std std-ref\">로거</span></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#topic-logging-parts-handlers\"><span class=\"std std-ref\">핸들러</span></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#topic-logging-parts-filters\"><span class=\"std std-ref\">필터</span></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#topic-logging-parts-formatters\"><span class=\"std std-ref\">포매터</span></a></p></li>\n</ul>\n<section id=\"loggers\">\n<span id=\"topic-logging-parts-loggers\"></span><h4>로거<a class=\"heading-anchor\" href=\"#loggers\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>A <em>logger</em> is the entry point into the logging system. Each logger is a named\nbucket to which messages can be written for processing.</p>\n<p>A logger is configured to have a <em>log level</em>. This log level describes\nthe severity of the messages that the logger will handle. Python\ndefines the following log levels:</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">DEBUG</span></code>: Low level system information for debugging purposes</p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">INFO</span></code>: General system information</p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">WARNING</span></code>: Information describing a minor problem that has\noccurred.</p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">ERROR</span></code>: Information describing a major problem that has\noccurred.</p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">CRITICAL</span></code>: Information describing a critical problem that has\noccurred.</p></li>\n</ul>\n<p>Each message that is written to the logger is a <em>Log Record</em>. Each log\nrecord also has a <em>log level</em> indicating the severity of that specific\nmessage. A log record can also contain useful metadata that describes\nthe event that is being logged. This can include details such as a\nstack trace or an error code.</p>\n<p>When a message is given to the logger, the log level of the message is\ncompared to the log level of the logger. If the log level of the\nmessage meets or exceeds the log level of the logger itself, the\nmessage will undergo further processing. If it doesn’t, the message\nwill be ignored.</p>\n<p>Once a logger has determined that a message needs to be processed,\nit is passed to a <em>Handler</em>.</p>\n</section>\n<section id=\"handlers\">\n<span id=\"topic-logging-parts-handlers\"></span><h4>핸들러<a class=\"heading-anchor\" href=\"#handlers\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>The <em>handler</em> is the engine that determines what happens to each message\nin a logger. It describes a particular logging behavior, such as\nwriting a message to the screen, to a file, or to a network socket.</p>\n<p>Like loggers, handlers also have a log level. If the log level of a\nlog record doesn’t meet or exceed the level of the handler, the\nhandler will ignore the message.</p>\n<p>A logger can have multiple handlers, and each handler can have a\ndifferent log level. In this way, it is possible to provide different\nforms of notification depending on the importance of a message. For\nexample, you could install one handler that forwards <code class=\"docutils literal notranslate\"><span class=\"pre\">ERROR</span></code> and\n<code class=\"docutils literal notranslate\"><span class=\"pre\">CRITICAL</span></code> messages to a paging service, while a second handler\nlogs all messages (including <code class=\"docutils literal notranslate\"><span class=\"pre\">ERROR</span></code> and <code class=\"docutils literal notranslate\"><span class=\"pre\">CRITICAL</span></code> messages) to a\nfile for later analysis.</p>\n</section>\n<section id=\"filters\">\n<span id=\"topic-logging-parts-filters\"></span><h4>필터<a class=\"heading-anchor\" href=\"#filters\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>A <em>filter</em> is used to provide additional control over which log records\nare passed from logger to handler.</p>\n<p>By default, any log message that meets log level requirements will be\nhandled. However, by installing a filter, you can place additional\ncriteria on the logging process. For example, you could install a\nfilter that only allows <code class=\"docutils literal notranslate\"><span class=\"pre\">ERROR</span></code> messages from a particular source to\nbe emitted.</p>\n<p>Filters can also be used to modify the logging record prior to being\nemitted. For example, you could write a filter that downgrades\n<code class=\"docutils literal notranslate\"><span class=\"pre\">ERROR</span></code> log records to <code class=\"docutils literal notranslate\"><span class=\"pre\">WARNING</span></code> records if a particular set of\ncriteria are met.</p>\n<p>Filters can be installed on loggers or on handlers; multiple filters\ncan be used in a chain to perform multiple filtering actions.</p>\n</section>\n<section id=\"formatters\">\n<span id=\"topic-logging-parts-formatters\"></span><h4>포매터<a class=\"heading-anchor\" href=\"#formatters\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Ultimately, a log record needs to be rendered as text. <em>Formatters</em>\ndescribe the exact format of that text. A formatter usually consists\nof a Python formatting string containing\n<a class=\"reference external\" href=\"https://docs.python.org/3/library/logging.html#logrecord-attributes\" title=\"(Python v3.14에서)\"><span class=\"xref std std-ref\">LogRecord attributes</span></a>; however,\nyou can also write custom formatters to implement specific formatting behavior.</p>\n</section>\n</section>\n</section>\n<section id=\"security-implications\">\n<span id=\"logging-security-implications\"></span><h2>Security implications<a class=\"heading-anchor\" href=\"#security-implications\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>The logging system handles potentially sensitive information. For example, the\nlog record may contain information about a web request or a stack trace, while\nsome of the data you collect in your own loggers may also have security\nimplications. You need to be sure you know:</p>\n<ul class=\"simple\">\n<li><p>what information is collected</p></li>\n<li><p>where it will subsequently be stored</p></li>\n<li><p>how it will be transferred</p></li>\n<li><p>who might have access to it.</p></li>\n</ul>\n<p>To help control the collection of sensitive information, you can explicitly\ndesignate certain sensitive information to be filtered out of error reports –\nread more about how to <a class=\"reference internal\" href=\"/ko/6.1/howto/error-reporting/#filtering-error-reports\"><span class=\"std std-ref\">filter error reports</span></a>.</p>\n<section id=\"adminemailhandler\">\n<h3><code class=\"docutils literal notranslate\"><span class=\"pre\">AdminEmailHandler</span></code><a class=\"heading-anchor\" href=\"#adminemailhandler\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>The built-in <a class=\"reference internal\" href=\"/ko/6.1/ref/logging/#django.utils.log.AdminEmailHandler\" title=\"django.utils.log.AdminEmailHandler\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AdminEmailHandler</span></code></a> deserves a mention in\nthe context of security. If its <code class=\"docutils literal notranslate\"><span class=\"pre\">include_html</span></code> option is enabled, the email\nmessage it sends will contain a full traceback, with names and values of local\nvariables at each level of the stack, plus the values of your Django settings\n(in other words, the same level of detail that is exposed in a web page when\n<a class=\"reference internal\" href=\"/ko/6.1/ref/settings/#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEBUG</span></code></a> is <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>).</p>\n<p>It’s generally not considered a good idea to send such potentially sensitive\ninformation over email. Consider instead using one of the many third-party\nservices to which detailed logs can be sent to get the best of multiple worlds\n– the rich information of full tracebacks, clear management of who is notified\nand has access to the information, and so on.</p>\n</section>\n</section>\n<section id=\"configuring-logging\">\n<span id=\"id1\"></span><h2>로깅 설정하기<a class=\"heading-anchor\" href=\"#configuring-logging\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Python’s logging library provides several techniques to configure\nlogging, ranging from a programmatic interface to configuration files.\nBy default, Django uses the <a class=\"reference external\" href=\"https://docs.python.org/3/library/logging.config.html#logging-config-dictschema\" title=\"(Python v3.14에서)\"><span class=\"xref std std-ref\">dictConfig format</span></a>.</p>\n<p>In order to configure logging, you use <a class=\"reference internal\" href=\"/ko/6.1/ref/settings/#std-setting-LOGGING\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">LOGGING</span></code></a> to define a\ndictionary of logging settings. These settings describe the loggers,\nhandlers, filters and formatters that you want in your logging setup,\nand the log levels and other properties that you want those components\nto have.</p>\n<p>By default, the <a class=\"reference internal\" href=\"/ko/6.1/ref/settings/#std-setting-LOGGING\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">LOGGING</span></code></a> setting is merged with <a class=\"reference internal\" href=\"/ko/6.1/ref/logging/#default-logging-configuration\"><span class=\"std std-ref\">Django’s\ndefault logging configuration</span></a> using the\nfollowing scheme.</p>\n<p>If the <code class=\"docutils literal notranslate\"><span class=\"pre\">disable_existing_loggers</span></code> key in the <a class=\"reference internal\" href=\"/ko/6.1/ref/settings/#std-setting-LOGGING\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">LOGGING</span></code></a> dictConfig is\nset to <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code> (which is the <code class=\"docutils literal notranslate\"><span class=\"pre\">dictConfig</span></code> default if the key is missing)\nthen all loggers from the default configuration will be disabled. Disabled\nloggers are not the same as removed; the logger will still exist, but will\nsilently discard anything logged to it, not even propagating entries to a\nparent logger. Thus you should be very careful using\n<code class=\"docutils literal notranslate\"><span class=\"pre\">'disable_existing_loggers':</span> <span class=\"pre\">True</span></code>; it’s probably not what you want. Instead,\nyou can set <code class=\"docutils literal notranslate\"><span class=\"pre\">disable_existing_loggers</span></code> to <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code> and redefine some or all\nof the default loggers; or you can set <a class=\"reference internal\" href=\"/ko/6.1/ref/settings/#std-setting-LOGGING_CONFIG\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">LOGGING_CONFIG</span></code></a> to <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code>\nand <a class=\"reference internal\" href=\"#disabling-logging-configuration\"><span class=\"std std-ref\">handle logging config yourself</span></a>.</p>\n<p>Logging is configured as part of the general Django <code class=\"docutils literal notranslate\"><span class=\"pre\">setup()</span></code> function.\nTherefore, you can be certain that loggers are always ready for use in your\nproject code.</p>\n<section id=\"examples\">\n<h3>예제<a class=\"heading-anchor\" href=\"#examples\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>The full documentation for <a class=\"reference external\" href=\"https://docs.python.org/3/library/logging.config.html#logging-config-dictschema\" title=\"(Python v3.14에서)\"><span class=\"xref std std-ref\">dictConfig format</span></a>\nis the best source of information about logging configuration dictionaries.\nHowever, to give you a taste of what is possible, here are several examples.</p>\n<p>To begin, here’s a small configuration that will allow you to output all log\nmessages to the console:</p>\n<figure class=\"code-block code-block-captioned\" data-language=\"python\"><figcaption class=\"code-block-caption\"><code class=\"docutils literal notranslate\"><span class=\"pre\">settings.py</span></code></figcaption>\n<div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"kn\">import</span><span class=\"w\"> </span><span class=\"nn\">os</span>\n\n<span class=\"n\">LOGGING</span> <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;version&quot;</span><span class=\"p\">:</span> <span class=\"mi\">1</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;disable_existing_loggers&quot;</span><span class=\"p\">:</span> <span class=\"kc\">False</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;handlers&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;console&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;class&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;logging.StreamHandler&quot;</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n    <span class=\"s2\">&quot;root&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;handlers&quot;</span><span class=\"p\">:</span> <span class=\"p\">[</span><span class=\"s2\">&quot;console&quot;</span><span class=\"p\">],</span>\n        <span class=\"s2\">&quot;level&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;WARNING&quot;</span><span class=\"p\">,</span>\n    <span class=\"p\">},</span>\n<span class=\"p\">}</span>\n</code></pre></figure>\n<p>This configures the parent <code class=\"docutils literal notranslate\"><span class=\"pre\">root</span></code> logger to send messages with the\n<code class=\"docutils literal notranslate\"><span class=\"pre\">WARNING</span></code> level and higher to the console handler. By adjusting the level to\n<code class=\"docutils literal notranslate\"><span class=\"pre\">INFO</span></code> or <code class=\"docutils literal notranslate\"><span class=\"pre\">DEBUG</span></code> you can display more messages. This may be useful during\ndevelopment.</p>\n<p>Next we can add more fine-grained logging. Here’s an example of how to make the\nlogging system print more messages from just the <a class=\"reference internal\" href=\"/ko/6.1/ref/logging/#django-logger\"><span class=\"std std-ref\">django</span></a> named\nlogger:</p>\n<figure class=\"code-block code-block-captioned\" data-language=\"python\"><figcaption class=\"code-block-caption\"><code class=\"docutils literal notranslate\"><span class=\"pre\">settings.py</span></code></figcaption>\n<div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"kn\">import</span><span class=\"w\"> </span><span class=\"nn\">os</span>\n\n<span class=\"n\">LOGGING</span> <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;version&quot;</span><span class=\"p\">:</span> <span class=\"mi\">1</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;disable_existing_loggers&quot;</span><span class=\"p\">:</span> <span class=\"kc\">False</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;handlers&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;console&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;class&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;logging.StreamHandler&quot;</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n    <span class=\"s2\">&quot;root&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;handlers&quot;</span><span class=\"p\">:</span> <span class=\"p\">[</span><span class=\"s2\">&quot;console&quot;</span><span class=\"p\">],</span>\n        <span class=\"s2\">&quot;level&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;WARNING&quot;</span><span class=\"p\">,</span>\n    <span class=\"p\">},</span>\n    <span class=\"s2\">&quot;loggers&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;django&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;handlers&quot;</span><span class=\"p\">:</span> <span class=\"p\">[</span><span class=\"s2\">&quot;console&quot;</span><span class=\"p\">],</span>\n            <span class=\"s2\">&quot;level&quot;</span><span class=\"p\">:</span> <span class=\"n\">os</span><span class=\"o\">.</span><span class=\"n\">getenv</span><span class=\"p\">(</span><span class=\"s2\">&quot;DJANGO_LOG_LEVEL&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;INFO&quot;</span><span class=\"p\">),</span>\n            <span class=\"s2\">&quot;propagate&quot;</span><span class=\"p\">:</span> <span class=\"kc\">False</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n<span class=\"p\">}</span>\n</code></pre></figure>\n<p>By default, this config sends messages from the <code class=\"docutils literal notranslate\"><span class=\"pre\">django</span></code> logger of level\n<code class=\"docutils literal notranslate\"><span class=\"pre\">INFO</span></code> or higher to the console. This is the same level as Django’s default\nlogging config, except that the default config only displays log records when\n<code class=\"docutils literal notranslate\"><span class=\"pre\">DEBUG=True</span></code>. Django does not log many such <code class=\"docutils literal notranslate\"><span class=\"pre\">INFO</span></code> level messages. With\nthis config, however, you can also set the environment variable\n<code class=\"docutils literal notranslate\"><span class=\"pre\">DJANGO_LOG_LEVEL=DEBUG</span></code> to see all of Django’s debug logging which is very\nverbose as it includes all database queries.</p>\n<p>You don’t have to log to the console. Here’s a configuration which writes all\nlogging from the <a class=\"reference internal\" href=\"/ko/6.1/ref/logging/#django-logger\"><span class=\"std std-ref\">django</span></a> named logger to a local file:</p>\n<figure class=\"code-block code-block-captioned\" data-language=\"python\"><figcaption class=\"code-block-caption\"><code class=\"docutils literal notranslate\"><span class=\"pre\">settings.py</span></code></figcaption>\n<div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"n\">LOGGING</span> <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;version&quot;</span><span class=\"p\">:</span> <span class=\"mi\">1</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;disable_existing_loggers&quot;</span><span class=\"p\">:</span> <span class=\"kc\">False</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;handlers&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;file&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;level&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;DEBUG&quot;</span><span class=\"p\">,</span>\n            <span class=\"s2\">&quot;class&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;logging.FileHandler&quot;</span><span class=\"p\">,</span>\n            <span class=\"s2\">&quot;filename&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;/path/to/django/debug.log&quot;</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n    <span class=\"s2\">&quot;loggers&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;django&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;handlers&quot;</span><span class=\"p\">:</span> <span class=\"p\">[</span><span class=\"s2\">&quot;file&quot;</span><span class=\"p\">],</span>\n            <span class=\"s2\">&quot;level&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;DEBUG&quot;</span><span class=\"p\">,</span>\n            <span class=\"s2\">&quot;propagate&quot;</span><span class=\"p\">:</span> <span class=\"kc\">True</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n<span class=\"p\">}</span>\n</code></pre></figure>\n<p>If you use this example, be sure to change the <code class=\"docutils literal notranslate\"><span class=\"pre\">'filename'</span></code> path to a\nlocation that’s writable by the user that’s running the Django application.</p>\n<p>Finally, here’s an example of a fairly complex logging setup:</p>\n<figure class=\"code-block code-block-captioned\" data-language=\"python\"><figcaption class=\"code-block-caption\"><code class=\"docutils literal notranslate\"><span class=\"pre\">settings.py</span></code></figcaption>\n<div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"n\">LOGGING</span> <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;version&quot;</span><span class=\"p\">:</span> <span class=\"mi\">1</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;disable_existing_loggers&quot;</span><span class=\"p\">:</span> <span class=\"kc\">False</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;formatters&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;verbose&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;format&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;</span><span class=\"si\">{levelname}</span><span class=\"s2\"> </span><span class=\"si\">{asctime}</span><span class=\"s2\"> </span><span class=\"si\">{module}</span><span class=\"s2\"> </span><span class=\"si\">{process:d}</span><span class=\"s2\"> </span><span class=\"si\">{thread:d}</span><span class=\"s2\"> </span><span class=\"si\">{message}</span><span class=\"s2\">&quot;</span><span class=\"p\">,</span>\n            <span class=\"s2\">&quot;style&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;{&quot;</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n        <span class=\"s2\">&quot;simple&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;format&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;</span><span class=\"si\">{levelname}</span><span class=\"s2\"> </span><span class=\"si\">{message}</span><span class=\"s2\">&quot;</span><span class=\"p\">,</span>\n            <span class=\"s2\">&quot;style&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;{&quot;</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n    <span class=\"s2\">&quot;filters&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;special&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;()&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;project.logging.SpecialFilter&quot;</span><span class=\"p\">,</span>\n            <span class=\"s2\">&quot;foo&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;bar&quot;</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n        <span class=\"s2\">&quot;require_debug_true&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;()&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;django.utils.log.RequireDebugTrue&quot;</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n    <span class=\"s2\">&quot;handlers&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;console&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;level&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;INFO&quot;</span><span class=\"p\">,</span>\n            <span class=\"s2\">&quot;filters&quot;</span><span class=\"p\">:</span> <span class=\"p\">[</span><span class=\"s2\">&quot;require_debug_true&quot;</span><span class=\"p\">],</span>\n            <span class=\"s2\">&quot;class&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;logging.StreamHandler&quot;</span><span class=\"p\">,</span>\n            <span class=\"s2\">&quot;formatter&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;simple&quot;</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n        <span class=\"s2\">&quot;mail_admins&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;level&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;ERROR&quot;</span><span class=\"p\">,</span>\n            <span class=\"s2\">&quot;class&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;django.utils.log.AdminEmailHandler&quot;</span><span class=\"p\">,</span>\n            <span class=\"s2\">&quot;filters&quot;</span><span class=\"p\">:</span> <span class=\"p\">[</span><span class=\"s2\">&quot;special&quot;</span><span class=\"p\">],</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n    <span class=\"s2\">&quot;loggers&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;django&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;handlers&quot;</span><span class=\"p\">:</span> <span class=\"p\">[</span><span class=\"s2\">&quot;console&quot;</span><span class=\"p\">],</span>\n            <span class=\"s2\">&quot;propagate&quot;</span><span class=\"p\">:</span> <span class=\"kc\">True</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n        <span class=\"s2\">&quot;django.request&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;handlers&quot;</span><span class=\"p\">:</span> <span class=\"p\">[</span><span class=\"s2\">&quot;mail_admins&quot;</span><span class=\"p\">],</span>\n            <span class=\"s2\">&quot;level&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;ERROR&quot;</span><span class=\"p\">,</span>\n            <span class=\"s2\">&quot;propagate&quot;</span><span class=\"p\">:</span> <span class=\"kc\">False</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n        <span class=\"s2\">&quot;myproject.custom&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;handlers&quot;</span><span class=\"p\">:</span> <span class=\"p\">[</span><span class=\"s2\">&quot;console&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;mail_admins&quot;</span><span class=\"p\">],</span>\n            <span class=\"s2\">&quot;level&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;INFO&quot;</span><span class=\"p\">,</span>\n            <span class=\"s2\">&quot;filters&quot;</span><span class=\"p\">:</span> <span class=\"p\">[</span><span class=\"s2\">&quot;special&quot;</span><span class=\"p\">],</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n<span class=\"p\">}</span>\n</code></pre></figure>\n<p>This logging configuration does the following things:</p>\n<ul>\n<li><p>Identifies the configuration as being in ‘dictConfig version 1’\nformat. At present, this is the only dictConfig format version.</p></li>\n<li><p>Defines two formatters:</p>\n<ul>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">simple</span></code>, that outputs the log level name (e.g., <code class=\"docutils literal notranslate\"><span class=\"pre\">DEBUG</span></code>) and the log\nmessage.</p>\n<p>The <code class=\"docutils literal notranslate\"><span class=\"pre\">format</span></code> string is a normal Python formatting string\ndescribing the details that are to be output on each logging\nline. The full list of detail that can be output can be\nfound in <a class=\"reference external\" href=\"https://docs.python.org/3/library/logging.html#formatter-objects\" title=\"(Python v3.14에서)\"><span>Formatter Objects</span></a>.</p>\n</li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">verbose</span></code>, that outputs the log level name, the log\nmessage, plus the time, process, thread and module that\ngenerate the log message.</p></li>\n</ul>\n</li>\n<li><p>Defines two filters:</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">project.logging.SpecialFilter</span></code>, using the alias <code class=\"docutils literal notranslate\"><span class=\"pre\">special</span></code>. If this\nfilter required additional arguments, they can be provided as additional\nkeys in the filter configuration dictionary. In this case, the argument\n<code class=\"docutils literal notranslate\"><span class=\"pre\">foo</span></code> will be given a value of <code class=\"docutils literal notranslate\"><span class=\"pre\">bar</span></code> when instantiating\n<code class=\"docutils literal notranslate\"><span class=\"pre\">SpecialFilter</span></code>.</p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">django.utils.log.RequireDebugTrue</span></code>, which passes on records when\n<a class=\"reference internal\" href=\"/ko/6.1/ref/settings/#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEBUG</span></code></a> is <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>.</p></li>\n</ul>\n</li>\n<li><p>Defines two handlers:</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">console</span></code>, a <a class=\"reference external\" href=\"https://docs.python.org/3/library/logging.handlers.html#logging.StreamHandler\" title=\"(Python v3.14에서)\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">StreamHandler</span></code></a>, which prints any <code class=\"docutils literal notranslate\"><span class=\"pre\">INFO</span></code>\n(or higher) message to <code class=\"docutils literal notranslate\"><span class=\"pre\">sys.stderr</span></code>. This handler uses the <code class=\"docutils literal notranslate\"><span class=\"pre\">simple</span></code>\noutput format.</p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">mail_admins</span></code>, an <a class=\"reference internal\" href=\"/ko/6.1/ref/logging/#django.utils.log.AdminEmailHandler\" title=\"django.utils.log.AdminEmailHandler\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AdminEmailHandler</span></code></a>, which\nemails any <code class=\"docutils literal notranslate\"><span class=\"pre\">ERROR</span></code> (or higher) message to the site <a class=\"reference internal\" href=\"/ko/6.1/ref/settings/#std-setting-ADMINS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">ADMINS</span></code></a>.\nThis handler uses the <code class=\"docutils literal notranslate\"><span class=\"pre\">special</span></code> filter.</p></li>\n</ul>\n</li>\n<li><p>Configures three loggers:</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">django</span></code>, which passes all messages to the <code class=\"docutils literal notranslate\"><span class=\"pre\">console</span></code> handler.</p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">django.request</span></code>, which passes all <code class=\"docutils literal notranslate\"><span class=\"pre\">ERROR</span></code> messages to\nthe <code class=\"docutils literal notranslate\"><span class=\"pre\">mail_admins</span></code> handler. In addition, this logger is\nmarked to <em>not</em> propagate messages. This means that log\nmessages written to <code class=\"docutils literal notranslate\"><span class=\"pre\">django.request</span></code> will not be handled\nby the <code class=\"docutils literal notranslate\"><span class=\"pre\">django</span></code> logger.</p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">myproject.custom</span></code>, which passes all messages at <code class=\"docutils literal notranslate\"><span class=\"pre\">INFO</span></code>\nor higher that also pass the <code class=\"docutils literal notranslate\"><span class=\"pre\">special</span></code> filter to two\nhandlers – the <code class=\"docutils literal notranslate\"><span class=\"pre\">console</span></code>, and <code class=\"docutils literal notranslate\"><span class=\"pre\">mail_admins</span></code>. This\nmeans that all <code class=\"docutils literal notranslate\"><span class=\"pre\">INFO</span></code> level messages (or higher) will be\nprinted to the console; <code class=\"docutils literal notranslate\"><span class=\"pre\">ERROR</span></code> and <code class=\"docutils literal notranslate\"><span class=\"pre\">CRITICAL</span></code>\nmessages will also be output via email.</p></li>\n</ul>\n</li>\n</ul>\n</section>\n<section id=\"custom-logging-configuration\">\n<h3>Custom logging configuration<a class=\"heading-anchor\" href=\"#custom-logging-configuration\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>If you don’t want to use Python’s dictConfig format to configure your\nlogger, you can specify your own configuration scheme.</p>\n<p>The <a class=\"reference internal\" href=\"/ko/6.1/ref/settings/#std-setting-LOGGING_CONFIG\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">LOGGING_CONFIG</span></code></a> setting defines the callable that will\nbe used to configure Django’s loggers. By default, it points at\nPython’s <a class=\"reference external\" href=\"https://docs.python.org/3/library/logging.config.html#logging.config.dictConfig\" title=\"(Python v3.14에서)\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">logging.config.dictConfig()</span></code></a> function. However, if you want to\nuse a different configuration process, you can use any other callable\nthat takes a single argument. The contents of <a class=\"reference internal\" href=\"/ko/6.1/ref/settings/#std-setting-LOGGING\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">LOGGING</span></code></a> will\nbe provided as the value of that argument when logging is configured.</p>\n</section>\n<section id=\"disabling-logging-configuration\">\n<span id=\"id2\"></span><h3>Disabling logging configuration<a class=\"heading-anchor\" href=\"#disabling-logging-configuration\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>If you don’t want to configure logging at all (or you want to manually\nconfigure logging using your own approach), you can set\n<a class=\"reference internal\" href=\"/ko/6.1/ref/settings/#std-setting-LOGGING_CONFIG\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">LOGGING_CONFIG</span></code></a> to <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code>. This will disable the\nconfiguration process for <a class=\"reference internal\" href=\"/ko/6.1/ref/logging/#default-logging-configuration\"><span class=\"std std-ref\">Django’s default logging</span></a>.</p>\n<p>Setting <a class=\"reference internal\" href=\"/ko/6.1/ref/settings/#std-setting-LOGGING_CONFIG\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">LOGGING_CONFIG</span></code></a> to <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code> only means that the automatic\nconfiguration process is disabled, not logging itself. If you disable the\nconfiguration process, Django will still make logging calls, falling back to\nwhatever default logging behavior is defined.</p>\n<p>Here’s an example that disables Django’s logging configuration and then\nmanually configures logging:</p>\n<figure class=\"code-block code-block-captioned\" data-language=\"python\"><figcaption class=\"code-block-caption\"><code class=\"docutils literal notranslate\"><span class=\"pre\">settings.py</span></code></figcaption>\n<div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"n\">LOGGING_CONFIG</span> <span class=\"o\">=</span> <span class=\"kc\">None</span>\n\n<span class=\"kn\">import</span><span class=\"w\"> </span><span class=\"nn\">logging.config</span>\n\n<span class=\"n\">logging</span><span class=\"o\">.</span><span class=\"n\">config</span><span class=\"o\">.</span><span class=\"n\">dictConfig</span><span class=\"p\">(</span><span class=\"o\">...</span><span class=\"p\">)</span>\n</code></pre></figure>\n<p>Note that the default configuration process only calls\n<a class=\"reference internal\" href=\"/ko/6.1/ref/settings/#std-setting-LOGGING_CONFIG\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">LOGGING_CONFIG</span></code></a> once settings are fully-loaded. In contrast, manually\nconfiguring the logging in your settings file will load your logging config\nimmediately. As such, your logging config must appear <em>after</em> any settings on\nwhich it depends.</p>\n</section>\n</section>","rootId":"logging","toc":[{"title":"개요","anchor":"overview","children":[{"title":"The cast of players","anchor":"the-cast-of-players","children":[{"title":"로거","anchor":"loggers","children":[]},{"title":"핸들러","anchor":"handlers","children":[]},{"title":"필터","anchor":"filters","children":[]},{"title":"포매터","anchor":"formatters","children":[]}]}]},{"title":"Security implications","anchor":"security-implications","children":[{"title":"AdminEmailHandler","anchor":"adminemailhandler","children":[]}]},{"title":"로깅 설정하기","anchor":"configuring-logging","children":[{"title":"예제","anchor":"examples","children":[]},{"title":"Custom logging configuration","anchor":"custom-logging-configuration","children":[]},{"title":"Disabling logging configuration","anchor":"disabling-logging-configuration","children":[]}]}],"breadcrumbs":[{"docname":"topics/index","title":"Django 사용하기","url":"/ko/6.1/topics/"}],"prev":{"docname":"topics/i18n/timezones","title":"Time zones","url":"/ko/6.1/topics/i18n/timezones/"},"next":{"docname":"topics/pagination","title":"페이지네이션","url":"/ko/6.1/topics/pagination/"},"formats":{"html":"/ko/6.1/topics/logging/","markdown":"/ko/6.1/topics/logging.md","json":"/ko/6.1/topics/logging.json"},"source":"https://github.com/django/django/blob/stable/6.1.x/docs/topics/logging.txt","official":"https://docs.djangoproject.com/ko/6.1/topics/logging/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0","1.11"],"inLocales":["en","sv","zh-hans","ga","fr","ja","id","it","pt-br","ko","es","el","pl"]}