Download the PHP package zalora/punyan without Composer

On this page you can find all versions of the php package zalora/punyan. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package punyan

Punyan Build Status Test Coverage Code Climate

Punyan is the PHP implementation of the Bunyan Logger originally written for node.js

Requirements

Installation

$ composer require zalora/punyan

tl;dr logger to go

Bunyan is actually one of the few npm modules which installed without a single warning or error!

The Config file

The example config is written in JSON-format, every other format works, too as long as it represents the same structure. The logger itself expects an array with the same structure.

Top level options

Filters

To add a filter you have to add a structure like this to the filters array:

{ "<filter_name>": { "option1": "value1", "option2": "value2" } }

Callback

Callback filters have to return (true|false) and are passed in the LogEvent object to have some data for evaluation.

The only option is:

If you don't return anything, false is assumed. It's of course also your responsibility to make sure the class is loaded or an autoloader is present to do that.

Example:

{ "callback": { "function": "MyClass::myStaticMethod" }

DiscoBouncer

The name says it all: It will filter everything. This filter doesn't have options and is currently used for unit tests. If you find a real world use case, let me know. I'm curious.

Example:

{ "discoBouncer": {} }

NoFilter

Opposite of the DiscoBouncer, lets everything pass.

Example:

{ "noFilter": {} }

Namespace (Ns)

This filter is applied on your class name (including the namespace), so you can e.g. use it to assign your modules a separate logfile. Regular Expressions are validated during init of the logger.

Options:

If you use regexp as searchMethod, namespace contains your regular expression

Examples:

This will accept only logs from classes which contain the token 'Service':

{ "ns": { "namespace": "Service", "searchMethod": "contains" } }

My regex foo is incredibly low, sorry for this example. I hope this matches every class which ends with Hello:

{ "ns": { "namespace": "/Hello$/", "searchMethod": "regexp" } }

Priority

Priority filters filter by priority (Surprise...), e.g. if the filter level is set to 'info' then everything from info on passes. I guess there's not that much to explain.

Here's the full options list:

Example:

{ "priority": { "priority": "warn", "operator": ">=" } }

Regexp

Match a field (log message by default) against your regular expression pattern. These are the options of the filter:

Example:

{ "regexp": { "pattern": "/^https/", "field": "request.url", "returnValueOnMissingField": false } }

Match all URLs which start with https, in case there are no URLs logged, discard the log entry.

Writers

Currently there's only one writer (StreamWriter), in a later version I'll add a few more to support FirePHP and Slack. The three options every writer has are:

Mute

This will (Cpt. Obvious) mute the writer and suppress any potential output

Origin

Origin adds an array with information about where the log call was triggered, it contains the following fields:

This is e.g. required for the Namespace filter. If you set origin to false and add a Ns-Filter, the filter will always return false.

Bubble

Once a writer logged the message, the log event is not sent to other writers. Example:

The services.log keeps all log events which come from classes which contain the word Service in their class name. Without bubbling the log message would be in both files, as the stream writer for common.log doesn't have any filters. So bubbling can be used to prevent duplicate log messages. Keep in mind that the order in which you define your writers is important when you use bubbling!

Disclaimer: I stole the word "bubbling" from Monolog

StreamWriter

The StreamWriter supports all writeable streams (http://php.net/manual/en/wrappers.php), e.g.

Options:

The stream will be opened during the init process, so in case of files you know very early if it's writeable or not

Processors

I stole the name again from Monolog, because I couldn't come up with a better one... They're also doing the same: Add additional to every log event.

Of course you can do that manually, but it's a lot of work and it clutters the code, because it will be executed even if the log message itself is filtered out. So you move this code into a Processor and attach it to a writer. From that moment on it will gather all the required information automatically.

Processors have one common field:

The additional data is stored under the key 'proc', which is defined in Zalora\Punyan\IProcessor.

Example:

{ "Web": { "onDemand": true } or { "Web": { } }

Web Processor

The following data is added to the proc array of every log event:

Known Problems

FAQs

Why reinvent the wheel?

Actually I couldn't find a logger I liked, which does NOT implement the PSR-3 interface. At first I thought implementing a Formatter for Monolog should do the trick, but the log levels wouldn't match properly and using a mapping seemed too hackish.

As we want to use the tooling the bunyan project provides, we have to stay format-compatible. And here we have yet another logger for PHP.

What's planned?

Configuration storage

In order to change log levels you have to change a file or even worse change code. I want to provide a small CLI program which changes the configuration without a need for writeable files or redeploy. This can be achieved by storing the configuration in a key value store

New Filters

New Writers


All versions of punyan with dependencies

PHP Build Version
Package Version
Requires php Version >= 7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package zalora/punyan contains the following files

Loading the files please wait ....