Download the PHP package pauloamgomes/logger without Composer
On this page you can find all versions of the php package pauloamgomes/logger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pauloamgomes/logger
More information about pauloamgomes/logger
Files in pauloamgomes/logger
Package logger
Short Description Logger addon for Cockpit Headless CMS
License MIT
Homepage https://github.com/pauloamgomes/cockpit-cms-logger
Informations about the package logger
Cockpit CMS Logger Addon
This addon extends Cockpit CMS (Next) core by providing logging functionality based on the awesome Monolog Library.
Installation
Installation can be performed with ot without php composer.
Without php composer
- Download zip and extract to 'your-cockpit-docroot/addons/Logger' (e.g. cockpitcms/addons/Logger)
-
Install Monolog dependency using composer
- Access module settings
https://your-cockpit-site/settings/logger
and confirm that page loads.
Using php composer
- Install addon using composer
Configuration
The Logger operations are available to the super admin user, and they can be used by other users if they belong to a group with proper permissions. The following permissions are defined:
- manage.admin → Can access Logger settings
Above ACLs can be added to the global configuration file as below:
Main Settings
The settings page provide all the main configurations:
-
Enable - Check that option to enable the logging
-
Context attributes - included in the logging entry as an extra array
- Username - Includes the username of the active user
- Hostname - Includes the hostname of the request
- Request URI - Includes the request URI
- Referrer - Includes the Referrer URI
- HTTP Method - Includes the HTTP method of the request
-
Log Level - Set the log level
Cockpit Logger uses the same log levels defined in Monolog:
- DEBUG
- INFO
- NOTICE
- WARNING
- ERROR
- CRITICAL
- ALERT
- EMERGENCY
When its set to DEBUG, additional details about the request will be included in the log entry:
- Duration time
- Memory used
- Number of loaded php files
Monolog settings
The Monolog sections are resumed to the Formatter and Handler.
Formatters
A formatter defines the structure of the log entries, Cockpit Logger supports three Monolog formatters
Formatter | Purpose |
---|---|
LineFormatter | Formats a log record into a one-line string. |
JsonFormatter | Formats a log record into json |
HtmlFormatter | Used to format log records into a human readable html table, mainly suitable for emails. |
Its also possible to define the format of the date in the log entries, the value must be a valid PHP date format like Y-m-d H:i:s
Handlers
A handler defines how the logs will be saved. Cockpit Logger provides two Handlers:
Handler | Purpose |
---|---|
StreamHandler | Saves log entries in the filesystem using the configured location and filename |
SyslogHandler | Writes the log entries using the operating system syslog functionality. Requires an ident and syslog facility. |
SyslogUdpHandler | Pushes the log entries to a remove rsyslog server. |
The StreamHandler requires two additional settings:
- Log Location - Use either a relative location to the storage like "#storage:logs" or an absolute path like "/logs". In both cases ensure that web server can write on the target location
- Log Filename - The filename (e.g. cockpit.log)
The SyslogHandler requires also to additional settings:
- Ident - A string to identify the program name (e.g. cockpit)
- Facility - The Syslog Facility to use
Settings via config.yaml
Besides the configuration page the settings can also be defined in the cockpit config/config.yaml file, e.g.:
When using the config.yaml, the settings will take precedence over the configuration page.
Event Settings
Most relevant Cockpit events (e.g. User login, Collection removal) are logged automatically:
- collections.save.after
- collections.remove.after
- collections.removecollection
- collections.createcollection
- collections.updatecollection
- regions.save.after
- regions.remove
- singleton.save.after
- singleton.saveData.after
- singleton.remove
- forms.save.after
- cockpit.assets.save
- cockpit.media.upload
- cockpit.media.removefiles
- cockpit.media.rename
- cockpit.assets.remove
- cockpit.authentication.success
- cockpit.authentication.failed
- cockpit.account.logout
- cockpit.clearcache
- cockpit.api.erroronrequest
- cockpit.request.error
- imagestyles.save.after
- imagestyles.createstyle
- imagestyles.remove
If required to disable, they can be disabled in the config.yaml, e.g:
Examples
-
Saving a collection entry using LineFormatter and NOTICE level:
-
Saving a collection entry using LineFormatter and DEBUG level:
-
Saving a collection entry using the JsonFormatter and DEBUG Level:
- Saving a collection entry using the HtmlFormatter and NOTICE Level:
Logging on other addons using the Logger functions:
The Cockpit Logger can be used on any other code by just invoking the module, e.g.:
Viewing the most recent logs in Cockpit
Logs can be accessed on the server and processed using any tool, additionaly its also possible to access from the UI
to the most recent log entries - https://your-cockpit-site/recent-logs
.
The UI supports automatic fetch and dynamic filters:
Security considerations
When using the StreamLogger and the log location is set to the #storage:logs
ensure that file is not public accessible.
Copyright and license
Copyright 2018 pauloamgomes under the MIT license.