2017 © Pedro Peláez
 

library logging

Wrapper of monolog/monolog. Should be easier to use/configure than monolog

image

oasis/logging

Wrapper of monolog/monolog. Should be easier to use/configure than monolog

  • Friday, July 28, 2017
  • by no7mks
  • Repository
  • 2 Watchers
  • 0 Stars
  • 5,360 Installations
  • PHP
  • 7 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 21 Versions
  • 8 % Grown

The README.md

MLogger - logging for Oasis projects

oasis/logging provides classes and functions used to write logs., (*1)

The component can be referred to as MLog or MLogger in short., (*2)

There are a list of log handlers provided by default:, (*3)

  • Console Handler
  • Local File Handler
  • Local Error Handler
  • AWS SNS Handler

MLog adhere strictly to the PSR-3 standard and uses monolog/monolog as its underlying implementation., (*4)

Installation

Install the latest version with command below:, (*5)

$ composer require oasis/logging

Basic Usage

It is easy to use MLogger withour any configuration:, (*6)

<?php

// quick logging methods as global functions
mdebug("This is a debug message");
minfo("This is a info-level log message");
mnotice("Notice is also available");
mwarning("WARNING: something is possibly wrong!");
merror("ERROR: something is definitely wrong!");
mcritical("This is CRITICAL!");
malert("ALERT! ALERT!");
memergency("URGENT!");

// sprintf compatible logging
$name = 'test';
mdebug("The object %s is being processed", $name);

Using the Logger directly

A Monolog\Logger can be used directly. This provides the freedom to integrate MLog with other PSR-3 compatible components who need logging tools., (*7)

<?php

use Monolog\Logger as MonoLogger;
use Oasis\Mlib\Logging\MLogging;

/** @var MonoLogger $logger */
$logger = MLogging::getLogger();

// the $logger object can then be injected into any place in need of a MonoLogger

Add Handler

Thanks to the mature community of monolog/monolog, MLog can take use of all the existing Handlers for monolog., (*8)

In addition, you can also write your own handler that implements the Monolog\Handler\HandlerInterface interface., (*9)

Adding a handler to MLog is as simple as:, (*10)

<?php

use Oasis\Mlib\Logging\ConsoleHandler;
use Oasis\Mlib\Logging\LocalFileHandler;
use Oasis\Mlib\Logging\MLogging;

MLogging::addHandler(new ConsoleHandler());

// or

(new LocalFileHandler())->install();

Use auto-rotated-timestamp for file handler

The Oasis\Mlib\Logging\LocalFileHandler can be easily configured to rotate its filename based on time changes. This is a very useful feature if your script is a longlive script which runs more than just a few seconds. Provided the correct name pattern, the local filename will rotate each time the preset interval has passed. Here is an example:, (*11)

<?php
use Oasis\Mlib\Logging\LocalFileHandler;

$lfh = new LocalFileHandler('/my-log-path', '%date%/%hour%-%minute%-%script%.log');

// This tells the filename to rotate every 30 minutes
$lfh->setRefreshRate(1800);

The supported name patterns are:, (*12)

|pattern | meaning| |:--- |: ---| %date% | substituted by date of now, in the format: yyyymmdd %hour% | substituted by hour of now, in the format: HH (00-23) %minute% | substituted by minute of now, in the format: ii (00-59) %second% | substituted by second of now, in the format: ss (00-59) %script% | substituted by name of current script, filename only without directory names %pid% | substituted by current process ID, (*13)

Using AWS SNS to auto handle alert

The Oasis\Mlib\Logging\AwsSnsHandler provides a handler which is only processed when log above certain level (default to ALERT) is triggered., (*14)

It is an especially useful tool under production environment. It buffers all the logs and discard them if the script exits without error. If anything like a fatal error has put the script to exit abnormally, the handler will publish all the buffer as well as an ALERT log to the specified AWS SNS topic., (*15)

The AwsSnsHandler is an optional feature and it depends on the oasis/aws-wrappers component:, (*16)

$ composer require oasis/aws-wrappers

To use the AwsSnsHandler, try the code below:, (*17)

<?php

use Oasis\Mlib\Logging\AwsSnsHandler;
use Oasis\Mlib\AwsWrappers\SnsPublisher;

/** @var string $the_topic_arn      the topic's AWS Resource Name */
/** @var array $some_aws_config     config data to initialize an Sns Publisher */
$publisher = new SnsPublisher($some_aws_config, $the_topic_arn);

$snsHandler = new AwsSnsHandler($publisher, 'This is the subject');
$snsHandler->enableAutoPublishingOnFatalError();
$snsHandler->install();

The Versions

28/07 2017

dev-master

9999999-dev

Wrapper of monolog/monolog. Should be easier to use/configure than monolog

  Sources   Download

MIT

The Requires

 

The Development Requires

by Minhao Zhang

28/07 2017

v1.4.1

1.4.1.0

Wrapper of monolog/monolog. Should be easier to use/configure than monolog

  Sources   Download

MIT

The Requires

 

The Development Requires

by Minhao Zhang

17/07 2017

v1.4.0

1.4.0.0

Wrapper of monolog/monolog. Should be easier to use/configure than monolog

  Sources   Download

MIT

The Requires

 

The Development Requires

by Minhao Zhang

26/06 2017

v1.3.0

1.3.0.0

Wrapper of monolog/monolog. Should be easier to use/configure than monolog

  Sources   Download

MIT

The Requires

 

The Development Requires

by Minhao Zhang

10/01 2017

v1.2.0

1.2.0.0

Wrapper of monolog/monolog. Should be easier to use/configure than monolog

  Sources   Download

MIT

The Requires

 

The Development Requires

by Minhao Zhang

12/07 2016

v1.1.9

1.1.9.0

Wrapper of monolog/monolog. Should be easier to use/configure than monolog

  Sources   Download

MIT

The Requires

 

The Development Requires

by Minhao Zhang

12/07 2016

dev-feature/markup-test

dev-feature/markup-test

Wrapper of monolog/monolog. Should be easier to use/configure than monolog

  Sources   Download

MIT

The Requires

 

The Development Requires

by Minhao Zhang

05/05 2016

v1.1.8

1.1.8.0

Wrapper of monolog/monolog. Should be easier to use/configure than monolog

  Sources   Download

MIT

The Requires

 

The Development Requires

by Minhao Zhang

11/03 2016

v1.1.7

1.1.7.0

Wrapper of monolog/monolog. Should be easier to use/configure than monolog

  Sources   Download

MIT

The Requires

 

The Development Requires

by Minhao Zhang

10/03 2016

v1.1.6

1.1.6.0

Wrapper of monolog/monolog. Should be easier to use/configure than monolog

  Sources   Download

MIT

The Requires

 

The Development Requires

by Minhao Zhang

08/03 2016

v1.1.5

1.1.5.0

Wrapper of monolog/monolog. Should be easier to use/configure than monolog

  Sources   Download

MIT

The Requires

 

The Development Requires

by Minhao Zhang

27/01 2016

v1.1.4

1.1.4.0

Wrapper of monolog/monolog. Should be easier to use/configure than monolog

  Sources   Download

MIT

The Requires

 

The Development Requires

by Minhao Zhang

21/01 2016

v1.1.3

1.1.3.0

Wrapper of monolog/monolog. Should be easier to use/configure than monolog

  Sources   Download

MIT

The Requires

 

The Development Requires

by Minhao Zhang

21/01 2016

v1.1.2

1.1.2.0

Wrapper of monolog/monolog. Should be easier to use/configure than monolog

  Sources   Download

MIT

The Requires

 

The Development Requires

by Minhao Zhang

30/12 2015

v1.1.1

1.1.1.0

Wrapper of monolog/monolog. Should be easier to use/configure than monolog

  Sources   Download

MIT

The Requires

 

The Development Requires

by Minhao Zhang

30/12 2015

v1.1.0

1.1.0.0

Wrapper of monolog/monolog. Should be easier to use/configure than monolog

  Sources   Download

MIT

The Requires

 

The Development Requires

by Minhao Zhang

29/12 2015

v1.0.4

1.0.4.0

Wrapper of monolog/monolog. Should be easier to use/configure than monolog

  Sources   Download

MIT

The Requires

 

The Development Requires

by Minhao Zhang

29/12 2015

v1.0.3

1.0.3.0

Wrapper of monolog/monolog. Should be easier to use/configure than monolog

  Sources   Download

MIT

The Requires

 

The Development Requires

by Minhao Zhang

04/12 2015

1.0.2

1.0.2.0

Wrapper of monolog/monolog. Should be easier to use/configure than monolog

  Sources   Download

MIT

The Requires

 

The Development Requires

by Minhao Zhang

04/12 2015

v1.0.1

1.0.1.0

Wrapper of monolog/monolog. Should be easier to use/configure than monolog

  Sources   Download

MIT

The Requires

 

The Development Requires

by Minhao Zhang

04/12 2015

v1.0

1.0.0.0

Wrapper of monolog/monolog. Should be easier to use/configure than monolog

  Sources   Download

MIT

The Requires

 

The Development Requires

by Minhao Zhang