{"id":22520489,"url":"https://github.com/mattyeend/laravel-logging","last_synced_at":"2025-08-03T20:30:41.972Z","repository":{"id":266877304,"uuid":"899627269","full_name":"MattYeend/Laravel-Logging","owner":"MattYeend","description":"Logging for Laravel","archived":false,"fork":false,"pushed_at":"2024-12-06T17:32:29.000Z","size":12,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-06T18:24:05.475Z","etag":null,"topics":["laravel","laravel-framework","laravel-package","logging","php","php-framework"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MattYeend.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"https://github.com/MattYeend","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"lfx_crowdfunding":null,"polar":null,"buy_me_a_coffee":null,"thanks_dev":null,"custom":null}},"created_at":"2024-12-06T16:57:44.000Z","updated_at":"2024-12-06T17:33:49.000Z","dependencies_parsed_at":"2024-12-06T18:34:09.348Z","dependency_job_id":null,"html_url":"https://github.com/MattYeend/Laravel-Logging","commit_stats":null,"previous_names":["mattyeend/laravel-logging"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MattYeend%2FLaravel-Logging","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MattYeend%2FLaravel-Logging/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MattYeend%2FLaravel-Logging/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MattYeend%2FLaravel-Logging/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MattYeend","download_url":"https://codeload.github.com/MattYeend/Laravel-Logging/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228562102,"owners_count":17937234,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","laravel-framework","laravel-package","logging","php","php-framework"],"created_at":"2024-12-07T05:07:32.948Z","updated_at":"2024-12-07T05:07:34.073Z","avatar_url":"https://github.com/MattYeend.png","language":"PHP","funding_links":["https://github.com/sponsors/https://github.com/MattYeend"],"categories":[],"sub_categories":[],"readme":"# Logger Package\n\nA Laravel package for logging application events into a database table. This package provides an extensible model, a database migration, and helper methods for recording user and system actions in a structured and searchable format.\n\n---\n\n## Features\n\n- **Action Logging**: Easily log predefined or custom actions with optional metadata.\n- **User Relationships**: Track the user performing the action (`logged_in_user_id`) and any user related to the action (`related_to_user_id`).\n- **Structured Data**: Store additional data as JSON for enhanced flexibility.\n- **Predefined Actions**: Common actions like login, logout, user creation, and more are included.\n\n---\n\n## Installation\n\n1. **Add the Package**  \n    Clone or place the package in the `packages/MattYeend/Logger` directory of your Laravel project.\n\n2. **Register the Package**  \n    Add the following entry in your Laravel application's `composer.json`:\n\n    ```\n    \"repositories\": [\n        {\n            \"type\": \"path\",\n            \"url\": \"./packages/MattYeend/Logger\"\n        }\n    ]\n    ```\n\n3. **Require teh package**\n    Run the following command: `composer require MattYeend/logger`\n\n4. **Run Migrations**\n    Publish and run the migrations to create the `logger` table:\n    `php artisan migrate`\n\n## Usage\n### Log an Action\nUse the `Logger` model to log actions. The predefined constants simplify common actions:\n```\nuse MattYeend\\Logger\\Models\\Logger;\n\n// Log a user login event\nLogger::log(Logger::ACTION_LOGIN, ['ip' =\u003e request()-\u003eip()], auth()-\u003eid());\n```\n\n### Log Custom Actions\nYou can log actions not predefined in the package:\n`Logger::log(99, ['custom_key' =\u003e 'custom_value'], auth()-\u003eid(), $relatedUserId);`\n\n### Model Relationships\nRetrieve the user who performed the action or the user related to it:\n```\n$log = Logger::find(1);\n\n// Logged-in user\n$loggedInUser = $log-\u003eloggedInUser;\n\n// Related user\n$relatedUser = $log-\u003erelatedToUser;\n```\n\n## Predefined Actions\n| Constant                    | Value | Description                  |\n|-----------------------------|-------|------------------------------|\n| `ACTION_LOGIN`              | 1     | User logged in               |\n| `ACTION_LOGOUT`             | 2     | User logged out              |\n| `ACTION_CREATE_USER`        | 3     | Created a new user           |\n| `ACTION_UPDATE_USER`        | 4     | Updated a user               |\n| `ACTION_DELETE_USER`        | 5     | Deleted a user               |\n| `ACTION_SHOW_USER`          | 6     | Viewed a user profile        |\n| `ACTION_WELCOME_EMAIL_SENT` | 7     | Sent a welcome email         |\n| `ACTION_CONFIRM_PASSWORD`   | 8     | Confirmed password           |\n| `ACTION_FORGOT_PASSWORD`    | 9     | Initiated password reset     |\n| `ACTION_REGISTER_USER`      | 10    | Registered a new user        |\n| `ACTION_RESET_PASSWORD`     | 11    | Reset password               |\n| `ACTION_VERIFY_USER`        | 12    | Verified user email          |\n| `ACTION_PASSWORD_CHANGED`   | 13    | Changed password             |\n| `ACTION_MFA_ENABLED`        | 14    | Enabled multi-factor auth    |\n| `ACTION_MFA_DISABLED`       | 15    | Disabled multi-factor auth   |\n| `ACTION_PROFILE_UPDATED`    | 16    | Updated user profile         |\n| `ACTION_EMAIL_UPDATED`      | 17    | Updated email address        |\n| `ACTION_ROLE_ASSIGNED`      | 18    | Assigned a role to a user    |\n| `ACTION_PERMISSION_GRANTED` | 19    | Granted permissions to user  |\n| `ACTION_PERMISSION_REVOKED` | 20    | Revoked user permissions     |\n\n## Customisation\n### Modify Migrations\nYou can customize the `logger` table by editing the migration file located at:\n`packages/MattYeend/Logger/src/Database/Migrations/2024_12_06_000000_create_logger_table.php.`\n\n### Extend the Logger Model\nAdd additional functionality by extending the `Logger` model in your application.\n\n### Troubleshooting\n1. **Migration Not Found**\n    Ensure the `LoggerServiceProvider` is loading migrations by verifying the path in: `src/LoggerServiceProvider.php`:\n    `$this-\u003eloadMigrationsFrom(__DIR__ . '/Database/Migrations');`\n\n2. **Data Validation Issues**\n    Ensure `data` passed to `Logger::log()` is either `null` or an array. Example:\n    `Logger::log(Logger::ACTION_LOGIN, ['key' =\u003e 'value'], auth()-\u003eid());`\n\n### License\nThis package is licensed under the MIT License.\n\n### Contributing\nFeel free to fork the repository and submit pull requests for improvements or new features!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattyeend%2Flaravel-logging","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmattyeend%2Flaravel-logging","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattyeend%2Flaravel-logging/lists"}