Download the PHP package joomla/log without Composer

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

The Log Package Build Status

Latest Stable Version Total Downloads Latest Unstable Version License

Deprecated

The joomla/log package has been deprecated. No further updates are planned.

Introduction

The Joomla Framework includes a Log package that allows for configurable, hook-driven logging to a variety of formats.

The classes included in the Log package are Joomla\Log\Log, Joomla\Log\LogEntry, Joomla\Log\AbstractLogger as well as the classes Joomla\Log\Logger\Callback, Joomla\Log\Logger\Database, Joomla\Log\Logger\Echoo, Joomla\Log\Logger\FormattedText, Joomla\Log\Logger\Syslog and Joomla\Log\Logger\W3c which support formatting and storage. Of all these classes, you will generally only use Joomla\Log\Log in your projects.

Logging is a two-step process.

First you must add the add loggers to listen for log messages. Any number of loggers can be configured to listen for log messages based on a priority and a category. For example, you can configure all log messages to be logged to the database, but also set just errors to be logged to a file. To do this, you use the Joomla\Log\Log::addLogger method.

After at least one logger is configured, you can then add messages using the Joomla\Log\Log::addLogEntry method where you can specify a message, and optionally a priority (integer), category (string) and date.

Logging priority

Before we look at any logging examples, we need to understand what the priority is. The priority is an integer mask and is set using one or more predefined constants in the Joomla\Log\Log class. These are:

For information on what situation to use each constant in see the PSR-3 (Section 3) details here - https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md#3-psrlogloggerinterface where a detailed explanation can be found.

A final constant, Joomla\Log\Log::ALL is also available which corresponds to hex FFFF (16 bits). The other constants reserve the first eight bits for system use. This allows the developer the last eight bits, hex 100 to 8000, for custom use if desired. As the values are for masking, they can be mixed using any of the bitwise operators for and, or, not and xor.

By default, loggers are added to listen for Joomla\Log\Log::ALL priorities and log entries are added using the Joomla\Log\Log::INFO mask.

Logging to files (formattedtext)

A very typical example of logging is the ability to log to a file, and this is the default handler for logging. To do this add the logger and then you can add log messages.

As no logger has been specified in the Joomla\Log\Log::addLogger call, the "formattedtext" logger will be used. This will log the message to a file called "error.php" in the log folder specified by the "log_path" configuration variable (in the Joomla CMS, the default is /logs/). It will look something like this:

#
#Date: 2011-06-17 02:56:21 UTC
#Software: Joomla Framework 01-Jun-2011 06:00 GMT

#Fields: datetime   priority    category    message
2011-06-17T03:06:44+00:00   INFO    -   Logged

The file is tab-delimited and the default columns are the timestamp, the text representation of the priority, the category and finally the message. The category is empty (a dash) because we didn't supply it.

To log a different priority, you can use code like:

The log file will now look similar to the following:

2011-06-17T03:06:44+00:00 INFO - Logged
2011-06-17T03:52:08+00:00 WARNING - Logged 2
2011-06-17T03:57:03+00:00 WARNING test Logged 3

Additional options with formattedtext

When adding the "formattedtext" logger, the following options are available to supply in the array you pass to Joomla\Log\Log::addLogger.

Option Description
text_file Allows you to specify the name of the file to which messages are logged.
text_file_path Allows you to specify the folder path to the file to which messages are logged.
text_file_no_php If set, the PHP die statement will not be added to the file line of the file.
text_entry_format Allows you to change the format of the entire line of the log message in the file.

Changing the name of the log file

Given the options outlined in the previous section, you can change the name of the file to which you are logging when you add the logger, like this:

Logging different priorities to different files

You can log different types of messages to different files by adding multiple loggers that bind different log priorities to different files. For example, the following code will log all messages except errors to one file, and error messages to a separate file.

Logging specific categories to a file

If you are wanting to collect errors for your specific project, class or extension, you can also bind logging to different categories. For example, the following code could be used in a Joomla extension to just collect errors relating to it.

To log messages to that logger, you would use something similar to the following code:

It is important to note that other loggers, added beyond your control, may also pick up this message.

Splitting up logs by date

Log files can, potentially, get very long over time. A convenient solution to this is to roll logs into different files based on a period of time - an hour, a day, a month or even a year. To do this, you just need to add the date to the file name of the log file. The following example shows you how to do this on a daily basis.

Changing the format of the log message

When you adding a log message, it is written to the file in a default format in the form:

{DATETIME} {PRIORITY} {CATEGORY} {MESSAGE}

Each field is written in upper case, wrapped in curly braces and separated by tabs. There are a number of other fields that are automatically defined in the "formattedtext" logger that you can take advantage of automatically. These are:

Field Description
{CLIENTIP} The IP address of the user.
{DATE} The "Y-m-d" date component of the message datestamp.
{TIME} The "H:i:s" time component of the message datestamp.

To modify for the log format to add any or all of these fields, you can add the logger as shown in the following code.

As you can see, you can include or leave out any fields as you require to suit the needs of your project.

You can also add more fields but to do this you need to create and add a Joomla\Log\LogEntry object directly. The following example shows you how to do this.

It is strongly recommended that, when using a custom format, you bind the log entries to a specific and unique category, otherwise log files with different format (fields) could become mixed.

Logging to the database

The "database" logger allows you to log message to a database table. The create syntax for the default table is as follows:

To log messages using the "database" logger, you the following code as a guide.

Notice that the example binds the logger to all message priorities, but only those with a category of "dblog".

If you are wanting to store additional information in the message, you can do so using a JSON encoded string. For example:

This makes it possible to retrieve detailed information for display.

Installation via Composer

Add "joomla/log": "~1.0" to the require block in your composer.json and then run composer install.

Alternatively, you can simply run the following from the command line:


All versions of log with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.10|>=7.0
joomla/date Version ~1.0
joomla/filesystem Version ~1.0
psr/log 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 joomla/log contains the following files

Loading the files please wait ....