Download the PHP package swf/slf4php without Composer

On this page you can find all versions of the php package swf/slf4php. 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 slf4php

CI master: Codeship Status for ironhawk/swf-slf4php

What is this project?

slf4php is similar to the slf4j (The Simple Logging Facade for Java) project.

slf4php is not a logging implementation! This is more like an abstraction layer on the top of existing logging frameworks like Monolog - just like slf4j

If you are not adding (configuring) any logging implementation no problem! slf4php will default itself to the "no operation" mechanism. In terms of using the facade in your code nothing will change. And you can configure the logging any time later!

Supported logging implementations

This first 1.0 version supports Monolog logging implementation out of the box by providing MonologProxyAppender class.

Probably there will be more in upcoming versions.

The concept - in a nut shell

We have the following key entities:

And: the configuration

We want to be able to easily configure all the above! To achieve this the best way is having a simple (as possible) configuration file.

Take a quick look on the following JSON config and you will immediatelly understand the concept:

With the above simple config we have:

VISIT OUR WIKI! For more info about configuring the logging please visit the Wiki page!

Basic usage

Assuming you have the above config saved in file named log.config.json you can configure the LoggerFactory like this:

Once you have configured the LoggerFactory you can start get Logger instances from the factory like this:

As you might have already figured this out when you get a Logger from the factory you will get back the Logger which is matching the configuration!

In this case:

you will get back a DEBUG level Logger instance with the logFile and the console Appenders behind this.

While in this case:

it will be the default logger which is matching so you will get back a WARNING level Logger instance with the logFile Appender behind this.

Dumping out variables in log messages

One of the ideas I like most in the slf4j Java framework is this part.

Imagine we have complex objects. In DEBUG level we often want to dump those objects into log streams. But as soon as we change the log level to something more restrictive if we still keep dumping those objects into Strings (the log message) and then just throw them away because of the log level... Well this is a waste of CPU power and additional job to the Garbage Collector... So we shouldn't do that!

Here is a bad example:

Why is it a bad idea to do this this way? Because the String parameter is constructed anyways - using up memory and CPU power. And if the logLevel is not DEBUG then it was for nothing...

slf4j has an elegant solution for this - it is using "varargs" in Java. This means that a method can get any number of additional parameters. And actually PHP also supports this so we can use it here as well!

Keeping the example above here is the recommended way to do this:

You can define placeholders in you log message with adding {} into the log message. And then you simply pass over the variables to the log method invocation.

You can use as many placeholders as you would like to. The number of variables you pass to the method should match with the number of placeholders you used in the message! (If you pass less or more variables it is not a tragedy of course but your log message can look "strange" then)

IMPORTANT! You shouldn't do ANY transformations on the objects you pass over! You should pass over the variable as it is and leave it up to slf4php to do the string transformation - if needed!

DO NOT DO THIS:

If you pass over not only simple types (like boolean, int, string, etc) but objects and/or arrays slf4php will transform them into strings (when needed only) this way:

Here is another example

Recommended usage in your class definitions

When you invoke LoggerFactory::getLogger(<fully qualified class name>) what is happening under the hood is that the LoggerFactory is going through the configured Loggers and trying to find the best matching one. If you invoke this method 100 times it will be done 100 times! So you should not do that...

In Java the typical usage is this code (probably you can read it)

Unfortunately we can not do this in PHP because

The best alternative (I could find so far) is the following:
In your class definitions

  1. You declare a protected static variable - to hold the reference to the Logger instance
  2. You create a protected static method named e.g. logger() which gets and stores the Logger instance from the LoggerFactory - if it is not done before. But be ware! You need to reference the protected static variable with the static:: keyword and not the self:: keyword! You might need the "late static binding" feature of PHP...
  3. When you want to log out something you get the Logger instance by invoking the static method (you defined in step 2.) And when you are extending this class then
  4. Make sure that in the subclass you re-define the protected static variable - using the same name. As you did in step 1.

The following code sample shows you this

Definition of ClassA:

And in definition of subclasses of ClassA:

Explanation:
This will work as expected! ClassASubclass inherits the protected static method named logger(). But since we are overriding the protected static $_LOG field AND the inherited logger() method is using "late static binding" the $_LOG variable will be initialized the first time the logger() method is used in ClassASubclass.

Visit our Wiki page

For more info / advanced topics please visit the Wiki page!


All versions of slf4php with dependencies

PHP Build Version
Package Version
Requires php Version >= 5.3.0
psr/log Version 1.0.*
monolog/monolog Version 1.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 swf/slf4php contains the following files

Loading the files please wait ....