PHP code example of joomla / log
1. Go to this page and download the library: Download joomla/log library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
joomla / log example snippets
// Initialise a basic logger with no options (once only).
Joomla\Log\Log::addLogger(array());
// Add a message.
Joomla\Log\Log::add('Logged');
Joomla\Log\Log::add('Logged 3', Joomla\Log\Log::WARNING, 'Test');
// Log to a specific text file.
Joomla\Log\Log::addLogger(
array(
'text_file' => 'mylogs.php'
)
);
// Log all message except errors to mylogs.php.
Joomla\Log\Log::addLogger(
array(
'text_file' => 'mylogs.php'
),
Joomla\Log\Log::ALL ^ Joomla\Log\Log::ERROR
);
// Log errors to myerrors.php.
Joomla\Log\Log::addLogger(
array(
'text_file' => 'myerrors.php'
),
Joomla\Log\Log::ERROR
);
// Log my extension errors only.
Joomla\Log\Log::addLogger(
array(
'text_file' => 'com_hello.errors.php'
),
Joomla\Log\Log::ERROR,
'com_hello'
);
Joomla\Log\Log::add('Forgot to say goodbye', Joomla\Log\Log::ERROR, 'com_hello');
// Get the date.
$date = date('Y-m-d');
// Add the logger.
Joomla\Log\Log::addLogger(
array(
'text_file' => 'com_hello.'.$date.'.php'
)
);
// Add the logger.
Joomla\Log\Log::addLogger(
array(
'text_file' => 'com_hello.php',
'text_entry_format' => '{DATE} {TIME} {CLIENTIP} {CATEGORY} {MESSAGE}'
)
);
// Add the logger.
Joomla\Log\Log::addLogger(
array(
'text_file' => 'com_shop.sales.php',
'text_entry_format' => '{DATETIME} {PRICE} {QUANTITY} {MESSAGE}'
),
Joomla\Log\Log::INFO,
'Shop'
);
$logEntry = new Joomla\Log\LogEntry('T- Shirt', Joomla\Log\Log::INFO, 'Shop');
$logEntry->price = '7.99';
$logEntry->quantity = 10;
Joomla\Log\Log::add($logEntry);
// Add the logger.
Joomla\Log\Log::addLogger(
array(
'logger' => 'database'
),
Joomla\Log\Log::ALL,
'dblog'
);
// Add the message.
Joomla\Log\Log::add('Database log', Joomla\Log\Log::INFO, 'dblog');
// Assemble the log message. Assume a $user object.
$log = array(
'userId' => $user->get('id'),
'userName' => $user->get('name'),
'stockId' => 'SKU123',
'price' => '7.49',
'quantity' => 10
);
// Add the message.
Joomla\Log\Log::add(json_encode($log), Joomla\Log\Log::INFO, 'dblog');
die('Forbidden.');