Download the PHP package arrowsphere/cloudwatch-logs without Composer
On this page you can find all versions of the php package arrowsphere/cloudwatch-logs. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download arrowsphere/cloudwatch-logs
More information about arrowsphere/cloudwatch-logs
Files in arrowsphere/cloudwatch-logs
Package cloudwatch-logs
Short Description Logs management in CloudWatch
License MIT
Informations about the package cloudwatch-logs
ArrowSphere CloudWatch Logs
This composer package allows to log data in CloudWatch, with auto-generated correlation id to follow the logs throughout all processes and their children.
⚙️ Installation
Install the latest version with
Request identifiers management
📖 Introduction
We manage 3 types of identifiers to help us identify our requests and follow their logs.
The request id, identified as ars-request-id
, is the unique identifier for the current request. It is auto-generated
and cannot be null.
The parent id, identified as ars-parent-id
, is the identifier of the parent request, that directly called this one. It
can be null if the current request is the originator of a process.
The correlation id, identified as ars-correlation-id
, is the identifier of the originator request of the process.
Whenever an event is logged, we should have those 3 headers indicated in the logging context.
🔧 How to use
The header ids
The three header ids are automatically logged by the logger system provided by this package, however if you want to pass them through to other API calls, you'll have to access them by yourself.
You can access the headers by using class ArsHeaderManager
.
The simplest way to use this class is to use static method ArsHeaderManager::initFromGlobals()
with no argument, it works as a singleton, and will populate the ids with whatever is already present in the $_SERVER
superglobal.
The $_SERVER
superglobal will then contain all three ids (parent id being an empty string if there's none).
Here's an example of code to make use of the variables:
The logger
This package provides a monolog handler for CloudWatch. To use it you'll have to instanciate it with the following parameters:
The handler is now ready to be used, you can add it to your monolog logger with method pushHandler
.
All logs you'll send to this logger will now be appended to CloudWatch, under the group name /{account_alias}/{stage}/{application}
.
The logs are formatted by ArsJsonFormatter
, which provides a unique format for ArrowSphere.
This format is described here: https://confluence.arrowcloud.org/display/XSP/ArrowSphere+logs
This table is a reminder of the fields that can be used in the logs:
Name | Mandatory | Type | Description |
---|---|---|---|
type | yes | string | The level of the log entry, typically one of the eight RFC 5424 levels (DEBUG, INFO, NOTICE, WARNING, ERROR, CRITICAL, ALERT, EMERGENCY). |
message | yes | string | The message of the log entry, should be a short string describing what the entry is about. Additional context information can and should be included in the context field. |
tags | yes | array of strings | Any tags you might want to add in your log. To use the tags, include a tags field in the log context. |
entries | yes | array | This field is present for backward-compatibility reason with xBE but will not be used by this package so it will always be an empty array. |
ars.correlation | yes | string | The identifier that will be used between ArrowSphere calls to create a link between the various micro-services. |
ars.request | yes | string | The identifier of the current request. |
ars.parent | yes | string | The identifier of the request that directly called the current one, if available (otherwise it's just an empty string). |
context | no | object | This field is the context used in the log entry, and should contain all variable information you might want to add to make your log entry more useful. For simplicity, the extra field from the log entry is also included in the context. |
Here's an example of log:
Please note that the logger uses ArsHeaderManager
and provides the three header ids in the ars
object as described above. This is handled by ArsHeaderProcessor
.
📃 License
This package is made available under the MIT License (MIT). Please see License File for more information.
All versions of cloudwatch-logs with dependencies
aws/aws-sdk-php Version ^3.304
monolog/monolog Version ^3.0
psr/log Version ^1.0 || ^2.0 || ^3.0
ramsey/uuid Version ^3.9 || ^4.2