Homepage

Creating Application Logs

Last edit: Oct 26, 2022

This guide will help you create your own logs using the log Liquid tag. This tag allows you to print any information to application logs as type info, debug, error, or your own type, and list them in your console next to your sync.

You can use the log tag in any file that accepts Liquid, so you can use them in pages, layouts, partials, Authorization Policies, async callbacks, etc.

Requirements

So that you can follow the steps in this tutorial, you have to have the pos-cli installed, an environment configured, and the codebase set up. You should be familiar with Pages, and the technologies behind platformOS, especially Liquid.

  • Get Started: helps you get access to our platform, set up a site, install the pos-cli, set up the required directory structure, and deploy to your site.
  • Technologies

Steps

Creating your own application logs is a two-step process:

Step 1: Use log Liquid tag

Create a page using the log Liquid tag, and sync it.

app/views/pages/log-test.liquid

{% liquid
  log 'This is a message'
  log params, type: 'request-params'
  log 'This will be an error', type: 'error'
%}

Notes

  • You can print any object to the logs that can be printed.
  • You can use parameters (e.g. take parameters from the URL and include them in the message).
  • The type of the log entry can be any string you want to tag your entry.
  • If you chose error pos-cli will mark it red and try to notify your OS.

Step 2: Start logging

In your command line, enter the command to start live logging:


pos-cli logs staging

This pulls the logs from the server every couple of seconds and displays them in your command line.

Example

[2020-04-23 14:53:24.998Z] - info: This is a message
path: /test/logs/debug
[2020-04-23 14:53:25.094Z] - request-params: {"slug":"test","slug2":"logs","slug3":"debug","format":"html"}
path: /test/logs/debug
[2020-04-23 14:53:25.116Z] - error: This will be an error
path: /test/logs/debug

We are also logging a path which triggered a particular log entry. This way you can find the cause of the error easier.

Questions?

We are always happy to help with any questions you may have.

contact us