Logs Query

Last updated: May 14th 2023

We can use below query to display logs at frontend via twig.

Query
{% set query = craft.loginAttempts.activity().all() %}

Variables

id

ID of log.

userId

User ID of the log for which login try was attempted.

loginName

Username or Email used to try login.

loginStatus

Status of login attempt. Can be either success or failed

ipAddress

IP Address of user who tried to attempt the login.

error

If login attempt failed, this variable will store error user got for that failed attempt.

dateCreated

Date of the log created.

dateUpdated

date of the log updated

uid

UID of given log.

Example:
{% set query = craft.loginAttempts.activity()
    .userId(currentUser.getId())
    .limit(100).all() %}

{% for log in query %}
    <div>
        {{ log.id }} <br>
        {{ log.userId }} <br>
        {{ log.loginName }} <br>
        {{ log.loginStatus }} <br>
        {{ log.ipAddress }} <br>
        {{ log.error }} <br>
        {{ log.dateCreated|datetime('m-d-Y h:i A') }} <br>
        {{ log.dateUpdated|datetime('m-d-Y h:i A') }} <br>
        {{ log.uid }} <br>
    </div>
{% endfor %}