All Projects → brefphp → logger

brefphp / logger

Licence: MIT license
All you need to log with Bref on AWS Lambda.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to logger

android-sdk
AppSpector is a debugging service for mobile apps
Stars: ✭ 39 (+30%)
Mutual labels:  logger
jcabi-log
Static Wrapper of SLF4J easing you from the necessity to create static LOGGER instances in each Java class
Stars: ✭ 53 (+76.67%)
Mutual labels:  logger
BaseDevelop
an android project for now fashion open source framework
Stars: ✭ 24 (-20%)
Mutual labels:  logger
webpack-log
A logger for the Webpack ecosystem
Stars: ✭ 18 (-40%)
Mutual labels:  logger
examples
Examples of PHP applications built with Bref
Stars: ✭ 78 (+160%)
Mutual labels:  bref
management tools
A collection of scripts and packages to simplify OS X management.
Stars: ✭ 93 (+210%)
Mutual labels:  logger
node-perj
A fast, flexible JSON logger.
Stars: ✭ 16 (-46.67%)
Mutual labels:  logger
puts debuggerer
Ruby library for improved puts debugging, automatically displaying bonus useful information such as source line number and source code.
Stars: ✭ 82 (+173.33%)
Mutual labels:  logger
ErrorHeroModule
💎 A Hero for your Zend Framework/Laminas, and Expressive/Mezzio application to log ( DB and Mail ) and handle php errors & exceptions during Mvc process/between request and response
Stars: ✭ 47 (+56.67%)
Mutual labels:  logger
fancy-logs
Print fancy logs to the terminal
Stars: ✭ 14 (-53.33%)
Mutual labels:  logger
react-native-log-ios
React Native iOS standalone logger
Stars: ✭ 37 (+23.33%)
Mutual labels:  logger
flor
FLOR: Fast Low-Overhead Recovery. FLOR lets you log ML training data post-hoc, with hindsight.
Stars: ✭ 123 (+310%)
Mutual labels:  logger
rest-api-node-typescript
This is a simple REST API with node and express with typescript
Stars: ✭ 154 (+413.33%)
Mutual labels:  logger
Loggaby
📝 A simple, lightweight and customizable logger.
Stars: ✭ 20 (-33.33%)
Mutual labels:  logger
handlers
Go's HTTP handlers I use in my projects
Stars: ✭ 53 (+76.67%)
Mutual labels:  logger
guzzle-logger
Automatically log all API calls
Stars: ✭ 42 (+40%)
Mutual labels:  logger
Multiplatform-Log
Kotlin Multi Platform Logger, for android an ios : Logcat & print
Stars: ✭ 49 (+63.33%)
Mutual labels:  logger
missionlog
🚀 lightweight logging • supports level based filtering and tagging • weighs in at around 500 bytes
Stars: ✭ 19 (-36.67%)
Mutual labels:  logger
Flogs
An Advanced Logging Framework develop in flutter that provides quick & simple logging solution.
Stars: ✭ 158 (+426.67%)
Mutual labels:  logger
forcelog
A structured, extensible logger for Salesforce Apex
Stars: ✭ 37 (+23.33%)
Mutual labels:  logger

All you need to log with Bref on AWS Lambda.

Build Status Latest Version

Bref/Logger is a lightweight PSR-3 logger for AWS Lambda. Messages are sent to stderr so that they end up in CloudWatch.

Why?

As explained in the Bref documentation, logging in AWS Lambda means logging to stderr. Logs written to stderr are automatically sent to CloudWatch, AWS' solution to collect and view logs.

While classic loggers like Monolog work fine, this logger comes as a simpler and lighter alternative optimized for AWS Lambda. It does not require any configuration and currently contains a single class.

Since it is PSR-3 compliant, Bref/Logger is also compatible with any framework or library consuming a PSR-3 logger.

Installation

composer require bref/logger

Usage

The logger does not require any configuration:

$logger = new \Bref\Logger\StderrLogger();

By default messages above the warning level will be logged, the rest will be discarded.

It is possible to log using any PSR-3 log level, the most common ones being:

$logger->debug('This is a debug message');
$logger->info('This is an info');
$logger->warning('This is a warning');
$logger->error('This is an error');
[WARNING] This is a warning
[ERROR] This is an error

Messages under warning are not logged.

Message placeholders

PSR-3 placeholders can be used to insert information from the $context array into the message without having to concatenate strings manually:

$logger->warning('Invalid login attempt for email {email}', [
    'email' => $email,
]);
[WARNING] Invalid login attempt for email [email protected]

Logging exceptions

Exceptions can be logged under the exception key:

try {
   // ...
} catch (\Exception $e) {
    $logger->error('Impossible to complete the action', [
        'exception' => $e,
    ]);
}
[ERROR] Impossible to complete the action
InvalidArgumentException: Impossible to complete the action in /var/task/index.php:12
Stack trace:
#0 /var/task/index.php(86): main()
...

Log level

It is possible to change the level above which messages are logged.

For example to log all messages:

$logger = new \Bref\Logger\StderrLogger(\Psr\Log\LogLevel::DEBUG);
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].