Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Hr Logger Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require fadiramzi99/hr-logger
    

    Add the service provider to config/app.php:

    'providers' => [
        // ...
        Fadiramzi99\HrLogger\HrLoggerServiceProvider::class,
    ],
    
  2. 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).

  3. 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']);
    

Implementation Patterns

Core Workflows

  1. Automatic Request Logging Extend App\Http\Middleware\LogRequests (if provided) or wrap routes:

    Route::middleware(['log.requests'])->group(function () {
        // Routes to log
    });
    
  2. Conditional Logging

    if (config('app.debug')) {
        HrLogger::log('Debug mode active');
    }
    
  3. Structured Logging

    HrLogger::log('User action', [
        'user_id' => auth()->id(),
        'action' => 'profile_update',
        'ip' => request()->ip(),
    ]);
    

Integration Tips

  • Laravel Events: Log events in listeners:
    public function handle(UserRegistered $event)
    {
        HrLogger::log('User registered', ['email' => $event->user->email]);
    }
    
  • Queue Jobs: Log job execution:
    public function handle()
    {
        HrLogger::log('Job started', ['job' => self::class]);
        // Job logic
        HrLogger::log('Job completed');
    }
    
  • API Responses: Log responses in middleware:
    public function handle($request, Closure $next)
    {
        $response = $next($request);
        HrLogger::log('API response', [
            'status' => $response->status(),
            'route' => $request->route()->getName(),
        ]);
        return $response;
    }
    

Gotchas and Tips

Pitfalls

  1. Performance Overhead

    • Disable in production if unused:
      HrLogger::disable();
      
    • Avoid logging in loops or high-frequency routes.
  2. Log File Rotation

    • No built-in rotation; configure via Laravel’s logging config or use laravel-log-rotate.
  3. Sensitive Data

    • Never log passwords, tokens, or PII (e.g., request()->input('password')). Use:
      HrLogger::log('Login attempt', [
          'email' => auth()->user()->email,
          // Omit password from logs
      ]);
      
  4. Middleware Conflicts

    • Ensure LogRequests middleware runs after auth/sanitization middleware to avoid logging raw input.

Debugging

  • Check Logs: Verify logs are written to storage/logs/hr-logger.log.
  • Enable Verbose Logging:
    HrLogger::setLevel(\Monolog\Logger::DEBUG);
    
  • Clear Logs:
    php artisan hr-logger:clear
    
    (Note: Command may not exist; manually delete storage/logs/hr-logger.log.)

Extension Points

  1. 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'))]);
    });
    
  2. Log Formatters Extend the logger to add metadata:

    HrLogger::extend(function ($logger) {
        $logger->pushProcessor(function ($record) {
            $record['extra']['user_agent'] = request()->userAgent();
            return $record;
        });
    });
    
  3. 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.)

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui