Application Logs

Logs for applications running on Stackato are aggregated into streams, so that data from multiple instances can be viewed together and filtered. Application log streams can be accessed via:

Information on system logs for Stackato itself and log aggregation settings can be found in the Log Aggregation documentation.

Log streams are tailed output from actual log files in each application container, generally found in the /app/logs/ directory. These files can be accessed with the stackato files command or from the Application details page of the Management Console.

Note

These files are not automatically rotated. For long-running applications or verbose logs, you should rotate them to avoid filling up the application container's filesystem.

stackato logs

To view and application log stream, use the stackato logs command:

$ stackato logs myapp

To limit the number of lines displayed, use the --num option:

$ stackato logs myapp --num 50

To view log stream as it is updated, use the --follow option:

$ stackato logs myapp --follow

Log streams can be filtered on a number of parameters:

  • --text does a glob pattern match on the log message
  • --instance shows only logs from the specified application instances (starting at instance 0).
  • --filename filters based on the log filename (e.g. 'stderr.log')
  • --source shows only logs from the specified source ('app' or 'staging'). Without a source specified, the log stream includes staging and application logs as well as cloud events relevant to app.

The --json flag can be used to return each log line as a JSON object.

Note

stackato logs buffers only 400 lines of the log stream history (i.e. lines generated prior to it being run). If you need earlier log lines, use the stackato files command to fetch the relevant log file from the logs/ directory or create a log drain preemptively (where possible).

stackato drain

The stackato drain command is used to create a log drain, which can forward application logs to external log aggregation services, log analysis tools, or Redis databases. For example:

$ stackato drain add myapp appdrain udp://logs.loggly.com:12345

This creates a UDP drain called "appdrain" for the application "myapp" which forwards all log messages and events for that application to Loggly on port 12345.

To delete the drain:

$ stackato drain delete appdrain

Use the --json option send the log lines in JSON format:

$ stackato drain add myapp jsondrain --json udp://logs.loggly.com:12346

Note

If the service at the recieving end of the drain goes offline or becomes disconnected, Stackato will retry the connection indefinitely (at increasing intervals).

Rotating Application Log Files

Stackato does not automatically rotate application log files in /app/logs/. However, you can add log rotation for these files yourself using cron and logrotate:

  1. Add a cron key in stackato.yml to run logrotate. Set STACKATO_CRON_INSTANCES to "all" to specify that the job should be run in all application instances. For example:

    env:
      STACKATO_CRON_INSTANCES: all
    cron:
      - 0 1 * * * /usr/sbin/logrotate /app/app/app-logrotate.conf
  2. Add an app-logrotate.conf file to the base directory of your application to specify which log files to rotate, and and which logrotate options to use. For example:

    /app/logs/\*.log {
      daily
      compress
      copytruncate
      dateext
      missingok
      notifempty
      rotate 3
      maxage 7
      size 3M
    }

Programming languages, frameworks, and utilities handle logging operations in different ways. Check for incompatibilities with logrotate before implementing log rotation scheme such as the one above.

Table Of Contents

Previous topic

Generic & Standalone Frameworks

Next topic

New Relic Monitoring