fadiramzi99/hr-logger
Laravel HR Logger package for tracking HR-related actions and events in your app. Provides structured logging of employee activities, audit-friendly records, and configurable logging channels to help monitor changes, approvals, and operational history.
Installation
composer require fadiramzi99/hr-logger
Add the service provider to config/app.php:
'providers' => [
// ...
Fadiramzi99\HrLogger\HrLoggerServiceProvider::class,
],
Publish Config
php artisan vendor:publish --provider="Fadiramzi99\HrLogger\HrLoggerServiceProvider" --tag="config"
Configure logging in config/hr-logger.php (default: storage/logs/hr-logger.log).
First Use Case
Enable logging in AppServiceProvider:
public function boot()
{
\Fadiramzi99\HrLogger\Facades\HrLogger::enable();
}
Log a request manually:
use Fadiramzi99\HrLogger\Facades\HrLogger;
HrLogger::log('custom_message', ['key' => 'value']);
Automatic Request Logging
Extend App\Http\Middleware\LogRequests (if provided) or wrap routes:
Route::middleware(['log.requests'])->group(function () {
// Routes to log
});
Conditional Logging
if (config('app.debug')) {
HrLogger::log('Debug mode active');
}
Structured Logging
HrLogger::log('User action', [
'user_id' => auth()->id(),
'action' => 'profile_update',
'ip' => request()->ip(),
]);
public function handle(UserRegistered $event)
{
HrLogger::log('User registered', ['email' => $event->user->email]);
}
public function handle()
{
HrLogger::log('Job started', ['job' => self::class]);
// Job logic
HrLogger::log('Job completed');
}
public function handle($request, Closure $next)
{
$response = $next($request);
HrLogger::log('API response', [
'status' => $response->status(),
'route' => $request->route()->getName(),
]);
return $response;
}
Performance Overhead
HrLogger::disable();
Log File Rotation
logging config or use laravel-log-rotate.Sensitive Data
request()->input('password')). Use:
HrLogger::log('Login attempt', [
'email' => auth()->user()->email,
// Omit password from logs
]);
Middleware Conflicts
LogRequests middleware runs after auth/sanitization middleware to avoid logging raw input.storage/logs/hr-logger.log.HrLogger::setLevel(\Monolog\Logger::DEBUG);
php artisan hr-logger:clear
(Note: Command may not exist; manually delete storage/logs/hr-logger.log.)Custom Loggers
Bind a custom logger in AppServiceProvider:
$this->app->bind(\Fadiramzi99\HrLogger\Contracts\Logger::class, function () {
return new \Monolog\Logger('custom', [new \Monolog\Handler\StreamHandler(storage_path('logs/custom.log'))]);
});
Log Formatters Extend the logger to add metadata:
HrLogger::extend(function ($logger) {
$logger->pushProcessor(function ($record) {
$record['extra']['user_agent'] = request()->userAgent();
return $record;
});
});
Database Logging
Use Laravel’s Logging facade to store logs in a DB table:
use Illuminate\Support\Facades\Log;
Log::channel('database')->info('Database log entry');
(Note: Requires additional setup for database channel.)
How can I help you explore Laravel packages today?