{% extends "loggerpanel/base.html" %}
{% load loggerpanel %}

{% block content %}

        <h1 class="mt-5">Loggers</h1>

        <section>
        <p class="lead">List of all loggers loaded from the Python's <code class="small">logging</code> module.</p>
        <p><span class="fw-bold">Log Level</span> is the specific level set for a logger.
          If no level is set, the <span class="fw-bold">Effective Logger Level</span>
          will be the nearest parent's log level in the logger hierarchy.</p>
        <p>For more information about <code class="small">logging.Logger.setLevel()</code>
          read the <a href="https://docs.python.org/3/library/logging.html#logging.Logger.setLevel">documentation</a>.</p>
        </section>
        {% if loggers %}
        <section>
          <table class="table">
            <thead>
              <tr>
                <th scope="col">Logger Name</th>
                <th scope="col">Logger Level</th>
                <th scope="col">Effective Logger Level</th>
                <th scope="col"></th>
              </tr>
            </thead>
            <tbody>
            {% for loggername, logger in loggers.items %}
              <tr>
                <th scope="row"><code class="">{{loggername}}</code></th>
                <td><code class="">{{logger.level | logger_level_name}}</code></td>
                <td>
                  <form action="{{base_url}}" method="POST">
                    <div class="btn-group btn-group-toggle" data-toggle="buttons">
                      <select name="logger_level" class="form-select" aria-label="Default select example">
                        {% for level_name, level_number in logger_levels.items %}
                        <option value="{{level_name}}" {% if level_number == logger.getEffectiveLevel %} selected {% endif %}>{{level_name}}
                        </option>
                        {% endfor %}
                      </select>
                      <button class="btn btn-primary" type="submit">Set</button>
                    </div>
                    <input type="hidden" name="logger_name" value="{{loggername}}"/>
                    {% csrf_token %}
                </form>
                </td>
                </td>
                  <td><a href="{{base_url}}{{loggername}}"><i class="bi bi-arrow-up-right-square"></i></a></td>
                </tr>

            {% endfor %}


            </tbody>
          </table>

        <section>
{% else %}
    <h2 class="mt-5">No logs to display :(</h2>
{% endif %}
{% endblock %}