Download the PHP package parseword/logger without Composer
On this page you can find all versions of the php package parseword/logger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download parseword/logger
More information about parseword/logger
Files in parseword/logger
Package logger
Short Description A PHP class implementing a text file logging facility
License Apache-2.0
Homepage https://github.com/parseword/logger/
Informations about the package logger
Logger
Logger is a PHP text file logging facility, implemented as a singleton. It's nothing special, but I'm breaking a larger code base down into independent components and I needed this to be in its own repository.
Usage
Implementing Logger
in 4 easy steps:
-
Either
composer require parseword/logger
or copy theLogger.php
file into your project. -
Make sure
Logger.php
is discoverable by your autoloader, orrequire_once
it manually. -
Throughout your application code, call
Logger::debug()
,Logger::info()
,Logger::warning()
andLogger::error()
to send log messages of differing severity levels. - In your application's config file or a common include file, you (or the user) call Logger::setFilename() to set the log file, and Logger::setSeverityFilter() to specify which log messages are written to disk.
Example
In the following example, a file named /tmp/my.log
is created. The severity
filter is set so that only messages with severity of WARNING or higher will be
written. Messages with lower severity will be disregarded.
The contents of /tmp/my.log
will look like this:
Inspect or run the included test.php
file for more examples.
Method overview
These methods are used to configure the Logger:
-
setCollapseEntries()
- Whether or not to replace newlines in log entries with spaces, constraining each entry to a single line. Defaults to true. -
setDateFormat()
- Set the date format to use when stamping log messages. -
setFilename()
- Set the filesystem path and filename for the log file. -
setLabel()
- Set an optional text string to include in log messages. If each instance of your application has a unique ID, setting it here can help with tracing and troubleshooting. setSeverityFilter()
- Set which types of log messages are written to the file.
These methods control the logger's functionality:
-
debug()
- Send a log message of severity DEBUG. -
error()
- Send a log message of severity ERROR. -
warning()
- Send a log message of severity WARNING. -
info()
- Send a log message of severity INFO. truncate()
- Truncate the log file, wiping out any previous entries.
Requirements
The Logger class requires PHP7 to support scalar type declarations.
Errata
None at this time.