mod_logging

Logs messages to the database and adds log views to the admin.

Logging messages to the database

To persist a log message in the database, enable mod_logging in your Zotonic site. Then, in your code, send the #zlog{} notification:

-include_lib("zotonic_core/include/zotonic.hrl").

some_function() ->
    %% do some things

    z_notifier:notify(
        #zlog{
            user_id = z_acl:user(Context),
            props=#log_email{
                severity = ?LOG_LEVEL_ERROR,
                message_nr = MsgId,
                mailer_status = bounce,
                mailer_host = z_convert:ip_to_list(Peer),
                envelop_to = BounceEmail,
                envelop_from = "<>",
                to_id = z_acl:user(Context),
                props = []
        }},
        Context
    );

E-mail log

The e-mail log is a separate view, which lists which email messages have been sent to which recipients. Any mail that gets sent gets logged here.

This module stores selected log events in the site database and provides admin views and APIs to inspect those logs, including e-mail delivery log entries.

Accepted Events

This module handles the following notifier callbacks:

  • observe_acl_is_allowed: Allow access to log resources only for users with the required log-view permissions.

  • observe_admin_menu: Add log viewers and log configuration entries to the admin menu.

  • observe_search_query: Provide module-specific search query handlers with ACL-aware filtering.

  • observe_tick_1h: Delete expired log records during hourly maintenance.

See also

For regular application logging, use Logger instead.

Edit on GitHub

Models

log

Model for runtime logging state and access to server log entries for clients allowed to read logs.

log_email

Model for email log lookups used by logging/admin views.

log_ui

Model for admin UI log retrieval by index, gated by admin permissions.

Controllers

Dispatch rules

dispatch

Dispatch rules Name Path Resource Args admin_log [“admin”,”log”] controller_admin [{template,”admin_log.tpl”}

Filters

log_format_stack

Escapes and formats a Javascript string with a stack trace to readable HTML.

See also

Logging

Zotonic uses Logger for logging. Logger metadata is automatically set by Zotonic in the controller functions.

Referred by

All dispatch rules

All the dispatch rules from all modules. For a background on dispatch rules, see The URL dispatch system.

E-mail handling

Any Zotonic system is capable of sending and receiving e-mail messages over SMTP.