- A log token
- An encoded payload (see below)
- A web page or HTML email to embed it in
To ensure what you’re logging doesn’t get mangled in a URL, you need to base64 encode it. In a browser, you can convert your data from the JS console as a one-liner. Taking the “Hello, Logentries!” string:
var encoded = encodeURIComponent(btoa("Hello, Logentries")); // => 'SGVsbG8sIExvZ2VudHJpZXM%3D'
will give you a properly encoded & formatted payload. If you’re building the URLs on the server-side, chances are your language / framework can easily generate a payload. Here’s an example using Ruby:
encoded = Base64.urlsafe_encode64("Hello, Logentries!")
You can make a call by building a URL like this:
where TOKEN is the log token and DATA is the base64 encoded string. DATA must be assigned to the ‘?e=’ query parameter (you’ll get a HTTP ‘bad request’ response if you leave it out). You change the URL to use unencrypted http as opposed to https, but we don’t recommend it unless you have to.
To log the string “Hello, Logentries”, the URL would look something like:
You’ll probably want to embed this url in an HTML <img/> tag like this*:
<html lang="en"> <head> <title>Pixel tracker example</title> </head> <body> <img src="https://js.logentries.com/v1/logs/13a65x78-4fae-42bb-8ce0-a01dd11di50q?e=SGVsbG8sIExvZ2VudHJpZXM%3D/> </body> </html>
*we made up that token- you’ll have to change it for one of your own!
Ideally the log data payload should be encoded in the URL-safe RFC 4648-compliant dialect, but it can tolerate most incorrectly formatted data. Many browsers limit the length of a URL to approximately 2000 characters. To ensure your log data doesn’t get lost or truncated, you should make sure it fits within this limit.