Recommend this page to a friend! |
Download |
Info | Example | Files | Install with Composer | Download | Reputation | Support forum | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not enough user ratings | Total: 158 | All time: 8,997 This week: 39 |
Version | License | PHP version | Categories | |||
ite-logger 1.2.3 | BSD License | 5.6 | PHP 5, Logging, Stream wrappers, Traits, P... |
Description | Author | |||
This package can log messages to different storage containers compliant with PSR-3. Innovation Award
|
Create a logger to an application
I need a logger class to insert in file or database.
<?php |
Set of classes the can be used for logging messages.
It provides simple file logging and abstract classes for sending emails with logs and writing them to database. It also has simple classes using internal php function mail() for sending logs and \PDO for writing into database tables. This packages includes LoggerAggregator class and trait that allow using of multiple nested loggers for all or different levels.
All the loggers implements PSR-3 logger standards. See http://www.php-fig.org/psr/psr-3/ for more information.
First run 'composer install' to install psr/log package. You can see the following examples in the 'example' folder
<?php
require_once '../vendor/autoload.php';
// Create the file logger with concrete log fils for 'alert' and 'error' levels:
$logger = new \Ite\Logger\FileLogger([
'error' => '../data/logs/errors.log',
'alert' => '../data/logs/errors.log'
]);
// the rest of levels will use the default log file
// log 10 info messages with fake context:
for ($i=0; $i<10; $i++) {
$logger->info("Test info {$i}",['a' => 'test context', 'qwe' => 'alabala', 'q' => [1, 2, 4]]);
}
// log 10 error messages with exception:
for ($i=0; $i<10; $i++) {
$logger->error("Test error {$i}", ['exception' => new Exception("Tesitng exceptions")]);
}
// log 10 alert messages with exception and fake context:
for ($i=0; $i<10; $i++) {
$logger->alert("Test alert {$i}", ['exception' => new Exception("Tesitng exceptions"), 'a' => 'test context', 'qwe' => 'alabala', 'q' => [1, 2, 4]]);
}
<?php
require_once '../vendor/autoload.php';
use Ite\Logger\PhpMailLogger;
// Change the email addres to yours:
$logger = new PhpMailLogger('me@xample.com');
// Log simple info message with fake content:
$logger->info("Test info",['a' => 'test context', 'nested_context' => [1, 2, 4]]);
<?php
require_once '../vendor/autoload.php';
$dbConfig = [
'host' => 'localhost',
'name' => '{{DATABASE_NAME}}', // set your own here
'username' => '{{USERNAME}}', // set your own here
'password' => '{{PASSWORD}}', // set your own here
'options' => [
\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES UTF8"
]
];
/*
*
* You need to execute this query to use this logger:
CREATE TABLE logs(
id INT(11) NOT NULL AUTO_INCREMENT,
message VARCHAR(255) NOT NULL,
level VARCHAR(10) NOT NULL,
date DATETIME NOT NULL,
context TEXT,
PRIMARY KEY(ID)
);
*/
$logger = new Ite\Logger\PdoMysqlLogger($dbConfig);
$logger->info("Testing database", ['key1' => 'value1']);
$logger->alert("Testing database", ['alert' => 'alerting']);
<?php
require_once '../vendor/autoload.php';
use Ite\Logger\FileLogger;
use Ite\Logger\LoggerAggregator;
use Ite\Logger\PhpMailLogger;
// create some simple loggers:
$logger = new FileLogger(['error' => '../data/logs/errors.log', 'alert' => '../data/logs/errors.log']);
$logger2 = new FileLogger();
$logger3 = new FileLogger();
$logger3->setDefaultLog('../data/logs/all.log');
// Change the email addres to yours:
$emailLogger = new PhpMailLogger('me@xample.com');
// create Logger Aggregator with a nested logger for 'error' and 'alert' level:
$loggerAggregator = new LoggerAggregator(['error' => $logger, 'alert' => $logger]);
// attach logger for 'info', 'debug' and 'error' levels:
$loggerAggregator->attachLogger($logger2, ['info', 'debug', 'error']);
// attach logger for all log levels:
$loggerAggregator->attachLogger($logger3);
// remove a logger for 'debug' level:
$loggerAggregator->detachLogger($logger2, 'debug');
// add email logger for critical messages:
$loggerAggregator->attachLogger($emailLogger, 'critical');
// fire some loggings:
for ($i=0; $i<10; $i++) {
$loggerAggregator->info("Test info {$i}",['a' => 'test context', 'qwe' => 'alabala']);
}
for ($i=0; $i<10; $i++) {
$loggerAggregator->error("Test error {$i}", ['exception' => new Exception("Tesitng exceptions")]);
}
for ($i=0; $i<10; $i++) {
$loggerAggregator->alert("Test alert {$i}", ['exception' => new Exception("Tesitng exceptions"),'a' => 'test context', 'qwe' => 'alabala']);
}
for ($i=0; $i<10; $i++) {
$loggerAggregator->debug("Test debug {$i}");
}
// Fire criticial log message (this should send email):
$loggerAggregator->critical("Critical message");
<?php
require_once '../vendor/autoload.php';
use Ite\Logger\Stream\Strategy\AbstractDatabaseLoggerStrategy;
use Ite\Logger\Stream\Strategy\AbstractEmailLoggerStrategy;
use Ite\Logger\Stream\StreamLoggerTrait;
use Ite\Logger\Stream\FileLogger;
use Ite\Logger\Stream\PhpMailLogger;
use Ite\Logger\Stream\PdoMysqlLogger;
use Psr\Log\LoggerInterface;
# Test database logger:
//stream_register_wrapper('log', PdoMysqlLogger::class);
//$stream = fopen('log://db/info', 'w');
# Test email logger:
//stream_register_wrapper('log', PhpMailLogger::class);
//$stream = fopen('log://email/info?to=k.savchev@gmail.com', 'w');
# Test file logger:
stream_register_wrapper('log', FileLogger::class);
$stream = fopen('log://file/info?log=../data/logs/errors.log', 'w', STREAM_REPORT_ERRORS);
// Write log:
fwrite($stream, serialize(["Testing stream...", [1, 2, 3]]));
Files (147) |
File | Role | Description | ||
---|---|---|---|---|
data (1 directory) | ||||
docs (2 files, 9 directories) | ||||
examples (5 files) | ||||
src (10 files, 2 directories) | ||||
composer.json | Data | Auxiliary data | ||
composer.lock | Data | Auxiliary data | ||
license | Lic. | License text | ||
README.md | Data | Auxiliary data |
Files (147) | / | data | / | logs |
File | Role | Description |
---|---|---|
all.log | Data | Auxiliary data |
errors.log | Data | Auxiliary data |
logger.log | Data | Auxiliary data |
Files (147) | / | docs |
Files (147) | / | docs | / | classes |
Files (147) | / | docs | / | css |
File | Role | Description | ||
---|---|---|---|---|
phpdocumentor-clean-icons (2 files, 1 directory) | ||||
bootstrap-combined.no-icons.min.css | Data | Auxiliary data | ||
font-awesome.min.css | Data | Auxiliary data | ||
jquery.iviewer.css | Data | Auxiliary data | ||
prism.css | Data | Auxiliary data | ||
template.css | Data | Auxiliary data |
Files (147) | / | docs | / | css | / | phpdocumentor-clean-icons |
File | Role | Description | ||
---|---|---|---|---|
fonts (2 files) | ||||
lte-ie7.js | Data | Auxiliary data | ||
style.css | Data | Auxiliary data |
Files (147) | / | docs | / | css | / | phpdocumentor-clean-icons | / | fonts |
File | Role | Description |
---|---|---|
phpdocumentor-clean-icons.dev.svg | Data | Auxiliary data |
phpdocumentor-clean-icons.svg | Data | Auxiliary data |
Files (147) | / | docs | / | files |
Files (147) | / | docs | / | files | / | Exception |
File | Role | Description |
---|---|---|
InvalidArgumentException.php.txt | Doc. | Documentation |
RuntimeException.php.txt | Doc. | Documentation |
Files (147) | / | docs | / | files | / | Stream |
File | Role | Description | ||
---|---|---|---|---|
Strategy (5 files) | ||||
FileLogger.php.txt | Doc. | Documentation | ||
PdoMysqlLogger.php.txt | Doc. | Documentation | ||
PhpMailLogger.php.txt | Doc. | Documentation | ||
StreamLoggerTrait.php.txt | Doc. | Documentation |
Files (147) | / | docs | / | files | / | Stream | / | Strategy |
File | Role | Description |
---|---|---|
AbstractDatabaseLoggerStrategy.php.txt | Doc. | Documentation |
AbstractEmailLoggerStrategy.php.txt | Doc. | Documentation |
FileLoggerStrategy.php.txt | Doc. | Documentation |
PdoMysqlLoggerStrategy.php.txt | Doc. | Documentation |
StreamLoggerStrategyInterface.php.txt | Doc. | Documentation |
Files (147) | / | docs | / | graphs |
File | Role | Description |
---|---|---|
class.html | Doc. | Documentation |
classes.svg | Data | Auxiliary data |
Files (147) | / | docs | / | images |
File | Role | Description | ||
---|---|---|---|---|
iviewer (8 files) | ||||
apple-touch-icon-114x114.png | Icon | Icon image | ||
apple-touch-icon-72x72.png | Icon | Icon image | ||
apple-touch-icon.png | Icon | Icon image | ||
custom-icons.svg | Data | Auxiliary data | ||
favicon.ico | Data | Auxiliary data | ||
hierarchy-item.png | Icon | Icon image | ||
icon-class-13x13.png | Icon | Icon image | ||
icon-class.svg | Data | Auxiliary data | ||
icon-interface-13x13.png | Icon | Icon image | ||
icon-interface.svg | Data | Auxiliary data | ||
icon-trait-13x13.png | Icon | Icon image | ||
icon-trait.svg | Data | Auxiliary data |
Files (147) | / | docs | / | images | / | iviewer |
File | Role | Description |
---|---|---|
grab.cur | Data | Auxiliary data |
hand.cur | Data | Auxiliary data |
iviewer.rotate_left.png | Icon | Icon image |
iviewer.rotate_right.png | Icon | Icon image |
iviewer.zoom_fit.png | Icon | Icon image |
iviewer.zoom_in.png | Icon | Icon image |
iviewer.zoom_out.png | Icon | Icon image |
iviewer.zoom_zero.png | Icon | Icon image |
Files (147) | / | docs | / | js |
File | Role | Description | ||
---|---|---|---|---|
ui (1 directory) | ||||
bootstrap.min.js | Data | Auxiliary data | ||
html5.js | Data | Auxiliary data | ||
jquery-1.11.0.min.js | Data | Auxiliary data | ||
jquery.dotdotdot-1.5.9.js | Data | Auxiliary data | ||
jquery.dotdotdot-1.5.9.min.js | Data | Auxiliary data | ||
jquery.iviewer.js | Data | Auxiliary data | ||
jquery.iviewer.min.js | Data | Auxiliary data | ||
jquery.mousewheel.js | Data | Auxiliary data | ||
jquery.smooth-scroll.js | Data | Auxiliary data | ||
prism.min.js | Data | Auxiliary data |
Files (147) | / | docs | / | namespaces |
File | Role | Description |
---|---|---|
default.html | Doc. | Documentation |
Ite.html | Doc. | Documentation |
Ite.Logger.Exception.html | Doc. | Documentation |
Ite.Logger.html | Doc. | Documentation |
Ite.Logger.Stream.html | Doc. | Documentation |
Ite.Logger.Stream.Strategy.html | Doc. | Documentation |
Files (147) | / | docs | / | reports |
File | Role | Description |
---|---|---|
deprecated.html | Doc. | Documentation |
errors.html | Doc. | Documentation |
markers.html | Doc. | Documentation |
Files (147) | / | examples |
File | Role | Description |
---|---|---|
database_example.php | Example | Example script |
file_logger.php | Example | Example script |
logger_aggregator.php | Example | Example script |
mail_example.php | Example | Example script |
stream_logger.php | Class | Class source |
Files (147) | / | src |
File | Role | Description | ||
---|---|---|---|---|
Exception (2 files) | ||||
Stream (4 files, 1 directory) | ||||
AbstractDatabaseLogger.php | Class | Class source | ||
AbstractEmailLogger.php | Class | Class source | ||
FileLogger.php | Class | Class source | ||
LoggerAggregator.php | Class | Class source | ||
LoggerAggregatorInterfrace.php | Class | Class source | ||
LoggerAggregatorTrait.php | Class | Class source | ||
MessagePrepareTrait.php | Class | Class source | ||
NoopLogger.php | Class | Class source | ||
PdoMysqlLogger.php | Class | Class source | ||
PhpMailLogger.php | Class | Class source |
Files (147) | / | src | / | Exception |
File | Role | Description |
---|---|---|
InvalidArgumentException.php | Class | Class source |
RuntimeException.php | Class | Class source |
Files (147) | / | src | / | Stream |
File | Role | Description | ||
---|---|---|---|---|
Strategy (5 files) | ||||
FileLogger.php | Class | Class source | ||
PdoMysqlLogger.php | Class | Class source | ||
PhpMailLogger.php | Class | Class source | ||
StreamLoggerTrait.php | Class | Class source |
Files (147) | / | src | / | Stream | / | Strategy |
File | Role | Description |
---|---|---|
AbstractDatabaseLoggerStrategy.php | Class | Class source |
AbstractEmailLoggerStrategy.php | Class | Class source |
FileLoggerStrategy.php | Class | Class source |
PdoMysqlLoggerStrategy.php | Class | Class source |
StreamLoggerStrategyInterface.php | Class | Class source |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
Install with Composer |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.