Composerのインストール Almalinux8
# cd /var/www/XXXXX システムのディレクトリ
# curl -sS https://getcomposer.org/installer | php
# mv composer.phar /usr/local/bin/composer
# ll /usr/local/bin/composer
-rwxr-xr-x 1 root root 2862107 Jan 29 21:24 /usr/local/bin/composer
# composer --version
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]? yes
Composer version 2.6.6 2023-12-08 18:32:26
Monologをインストール
# cd /var/www/XXXXX/includes など
# composer require monolog/monolog
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]? yes
./composer.json has been created
Running composer update monolog/monolog
Loading composer repositories with package information
Updating dependencies
Lock file operations: 2 installs, 0 updates, 0 removals
- Locking monolog/monolog (3.5.0)
- Locking psr/log (3.0.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 2 installs, 0 updates, 0 removals
- Downloading psr/log (3.0.0)
- Downloading monolog/monolog (3.5.0)
- Installing psr/log (3.0.0): Extracting archive
- Installing monolog/monolog (3.5.0): Extracting archive
10 package suggestions were added by new dependencies, use `composer suggest` to see details.
Generating autoload files
1 package you are using is looking for funding.
Use the `composer fund` command to find out more!
No security vulnerability advisories found.
Using version ^3.5 for monolog/monolog
header.phpなどに記載
<?php
define('SYSTEM_NAME', 'AAA');
define('LOG_FILE', '/tmp/mysyslog');
define('ERROR_LOG_FILE', '/tmp/mysys_error_log');
require_once __DIR__ .'/vender/autoload.php';
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\NativeMailerHandler;
date_default_timezone_set("Asia/Tokyo");
$logger = new Logger('SYSTEM_NAME');
$logger->pushHandler(new StreamHandler(LOG_FILE, Logger::DEBUG));
$logger->pushHandler(new StreamHandler(ERROR_LOG_FILE, Logger::ERROR));
使い方
try{
処理
$logger->info('○○処理しました');
}catch (Exception $e)
$logger->error('○○エラー',['error'=>$e->getMessage(),'data'=>print_r($data,true)]);
}