Skip to content

Logs

Logs are generated by various components of the stack:

  • The runtime (PHP, nodejs, etc.).
  • The application.
  • CronJobs.
  • CDN.
  • Deployments.

These logs are aggregated in AWS CloudWatch - see Usage access instructions.

Usage / Examples

Get prod logs generated between two times on a specific date.

$ skpr logs prod --start '2017-10-11 9:00' --end '2017-10-11 10:30'

Get staging logs for the last hour.

$ skpr logs staging --start 1h

Stream dev logs in real time.

$ skpr logs dev --follow

Get prod logs generated between two times today.

$ skpr logs prod --start '11:55' --end '12:05'

Get dev cloudfront logs generated between two relative times.

$ skpr logs dev --start 2h --end 30m --source cloudfront

Date / Time Formats

The following date/time formats are supported for the --start and --end flags.

  • Relative:
    • now
    • 30s "s" suffix denotes seconds.
    • 15m "m" suffix denotes minutes.
    • 2h "h" suffix denotes hours.
  • Absolute:
    • 19:05: time with no date, defaults to current date (use 24 hour syntax)
    • 2017-6-15: date with no time - assumes midnight of specified date
    • 2017-6-15 19:05: date and time specified.
    • 2019-04-26T07:46:40.795968088Z: RFC3339 with nanoseconds

CloudWatch Insights

TODO. Coming soon.

Configuration

Applications need to output their logs to stdout - this ensures the container orchestrator can aggregate logs and ship them to the storage backend. The Twelve-Factor App manifesto describes this succinctly:

A twelve-factor app never concerns itself with routing or storage of its output stream. It should not attempt to write to or manage logfiles. Instead, each running process writes its event stream, unbuffered, to stdout.

Drupal 10 or higher

  1. Enable and configure the Monolog module
  2. Enable the Monolog module, then configure it to log to a new Stdout stream.
  3. To install monolog module via composer, run: composer require drupal/monolog:^3.0

In your projects services.yml file add the following config:

parameters:
  monolog.channel_handlers:
  # Log to the stderr by default.
  default: ['stderr']
services:
  monolog.handler.stderr:
    class: Monolog\Handler\StreamHandler
    arguments: ['php://stderr']

Other

Other applications which log to stdout will log to AWS CloudWatch as well. Examples of this might include Solr, ElasticSearch, MailHog or one of the various smaller service applications which might be utilised.

Note

If you're using Drupal 7, be sure to enable log_stdout and disable any other logging modules such as dblog or syslog.

More Information

$ skpr logs --help
usage: skpr logs [<flags>] <environment> [<component>]

Query logs for an Environments component of the stack

Flags:
  --help         Show context-sensitive help (also try --help-long and --help-man).
  --start="15m"  
  --end="0"      

Args:
  <environment>  Name of the Environment to query for logs
  [<component>]  Name of the component of the stack to query

What's next?

After looking through the logs, consider one of the following: