Skip to content

Logs and Security Events

Arthu Santiago edited this page Nov 30, 2026 · 1 revision

Logs and Security Events

KeyAnyWhere keeps three kinds of records: technical logs (errors, warnings), security events (failed logins, blocked content) and the audit trail of who changed what. This page explains where each one is, how to read it and how to keep the log files from growing forever.

Technical logs

The log files are in /var/www/keyanywhere/logs/, one per level: debug.log, info.log, notice.log, warning.log, error.log, critical.log, alert.log and emergency.log. Each line is a JSON object with the time, level, message, context and a requisicao (request) block: request id, method, route (or, when no route matched, only the path: never the query string, which could carry a token), IP and user id. Errors with HTTP status 4xx are logged as warning.

Follow the errors as they happen:

tail -f /var/www/keyanywhere/logs/error.log

Security events

Security events go to logs/seguranca.log and to the database, which feeds the Eventos de segurança (Security events) screen. The message is a fixed description; variable data (such as the typed e-mail) goes in the context, never in the message.

Event Level When
login_credencial_invalida notice Login with a wrong e-mail or password.
login_2fa_invalido notice Login with a wrong 2FA code.
acesso_somente_root warning A non-administrator tried to open an administrator screen.
xss_detectado alert A form field carried malicious HTML or JavaScript; it was blocked.

Every logged-in user sees every event on the screen and in the home page block (last 7 days); only the administrator sees the origin IP. In the online demo, open the menu and choose Eventos de segurança.

Read the security log, one event per line, with jq:

sudo apt install -y jq
jq -c '{timestamp, nivel, mensagem, ip: .requisicao.ip}' /var/www/keyanywhere/logs/seguranca.log | tail -n 20

Audit trail

The audit trail is not a log file: it is an insert-only table (auditorias) that records who created, edited or deleted each entry, category and user, and when. It keeps the names of the changed fields, never their values, because the values are secrets. It is on the Auditoria (Audit) screen, open to every logged-in user; see Administration.

Rotate the log files

CakePHP appends to the files and never deletes them. This step sets up logrotate to rotate them weekly and keep 12 weeks, compressed.

sudo tee /etc/logrotate.d/keyanywhere > /dev/null <<'EOF'
/var/www/keyanywhere/logs/*.log {
    weekly
    rotate 12
    compress
    delaycompress
    missingok
    notifempty
    copytruncate
    su www-data www-data
}
EOF

Check the configuration without rotating anything:

sudo logrotate --debug /etc/logrotate.d/keyanywhere

Clone this wiki locally