boldlygrow/audit-log
Composer 安装命令:
composer require boldlygrow/audit-log
包简介
Audit and Event Log Handler for Laravel
README 文档
README
[[TOC]]
Overview
The Audit Log package is an open source Composer package for use in Laravel applications that is used by other Boldly Grow packages to provide a consistent log syntax and optional database persistence for audit events. Although this is purpose built for our packages, you are welcome to adopt this for your own standardized logging.
This is maintained by the open source community and is not maintained by any company. Please use at your own risk and create merge requests for any bugs that you encounter.
Problem Statement
When using Laravel Logging with the Log::info('Message', ['key1' => 'value', 'key2' => 'value']) syntax, it is easy to have inconsistency with log formatting that results in a variety of log messages and varying context keys.
The BoldlyGrow\AuditLog\AuditLog::create() method provides a pre-defined set of context keys that allow us to improve indexing and searchability in external logging platforms, and ensures that all events provide as much context data as possible in a consistent format.
Sometimes you need to get a formatted array that can be added to a changelog or actioned upon programmatically instead of trying to tail a log file. An array is returned for each log entry that is created.
What You Get
- Standardized log syntax — a predefined set of context keys for consistent indexing and searchability in external logging platforms.
- A returned array — every call returns a formatted, filterable array you can use as a data transfer object, append to a changelog, or action programmatically.
- Optional database persistence — write events to a queryable
audit_logstable for perpetual, SQL-searchable audit storage in addition to (or instead of) the system log. See Database Persistence. - A configurable, extensible schema — actor attribute mapping, model-to-type auto-calculation, request-origin tracking, and custom columns, so the package adapts to your models and conventions without being forked.
For how these capabilities map to common compliance frameworks (SOC 1/2, ISO 27001, NIST 800-53/63/171, CISA, CIS) and the shared-responsibility boundaries, see COMPLIANCE.md.
Issue Tracking and Bug Reports
We do not maintain a roadmap of feature requests, however we invite you to contribute and we will gladly review your merge requests.
Please create an issue for bug reports.
Contributing
Please see CONTRIBUTING.md to learn more about how to contribute.
Maintainers
| Name | GitLab Handle | |
|---|---|---|
| Jeff Martin | @jeffersonmartin | jeff [at] boldlygrow [dot] us |
Contributor Credit
- Jeff Martin
Installation
Requirements
| Requirement | Version |
|---|---|
| PHP | ^8.0 |
| Laravel | ^8.0, ^9.0, ^10.0, ^11.0, ^12.0, ^13.0 |
Upgrade Guide
See the changelog for release notes. If you are upgrading from provisionesta/audit (1.x), read the 2.0 changelog for the package rename, class rename, and configuration changes.
Add Composer Package
composer require boldlygrow/audit-log:^2.0
The old provisionesta/audit package name is retained as a replace alias, so existing dependency graphs continue to resolve during the transition.
If you are contributing to this package, see CONTRIBUTING.md for instructions on configuring a local composer package with symlinks.
Publish the configuration file
This is optional and only needed if you want to customize response schemas (dump_config) or any other setting.
php artisan vendor:publish --tag=audit-log
If you plan to use database persistence, run the interactive installer instead — it publishes the config, generates an application model, and publishes the migration in one step.
php artisan audit-log:install
Usage Examples
Basic Usage
use BoldlyGrow\AuditLog\AuditLog; AuditLog::create( event_ms: $event_ms, event_type: 'okta.api.post.success.ok', level: 'info', message: 'Success', metadata: [ 'okta_request_id' => 'REDACTED', 'rate_limit_remaining' => $request->headers['x-rate-limit-remaining'], 'uri' => 'users', 'url' => 'https://dev-12345678.okta.com/api/v1/users?activate=true' ], method: __METHOD__ );
Comprehensive Usage
You can copy and paste this example anywhere in your code that you would create a log entry. Any arguments that are not relevant can be removed and will be considered null.
use BoldlyGrow\AuditLog\AuditLog; AuditLog::create( actor_email: auth()->user()->email, actor_id: auth()->user()->id, actor_name: auth()->user()->name, actor_provider_id: auth()->user()->provider_id, actor_session_id: session()->getId(), actor_source: 'web', actor_type: config('auth.providers.users.model'), actor_username: auth()->user()->username, attribute_key: 'xxx', attribute_value_old: 'xxx', attribute_value_new: 'xxx', count_records: count($array), database: false, dump_config: null, dump_date: 'c', dump_keys: [], dump_strings: [], duration_ms: $duration_ms, duration_ms_per_record: (int) ($duration_ms / count($records)), errors: [], event_ms: $event_ms, event_ms_per_record: (int) ($event_ms / count($records)), event_type: '{provider}.{entity}.{action}.xxx', level: 'info', log: true, message: '{What happened}', metadata: [], method: __METHOD__, occurred_at: $entity->created_at, parent_id: $parent->id, parent_model: ProviderApplication::class, // parent_type => "provider_application" parent_provider_id: $parent->provider_id, parent_reference_key: 'name', parent_reference_value: $entity->organization->name, record_id: $entity->id, record_model: ProviderEntity::class, // record_type => "provider_entity" record_provider_id: $entity->provider_id, record_reference_key: 'name', record_reference_value: $entity->name, related_id: $manager->id, related_model: ProviderUser::class, subject_id: $service->id, subject_model: ProviderService::class, tenant_id: $entity->provider_organization_id, tenant_model: ProviderOrganization::class, );
Example Output
[YYYY-MM-DD HH:II:SS] local.DEBUG: ApiClient Success {"event_type":"okta.api.post.success.ok","method":"BoldlyGrow\\Okta\\ApiClient::post","event_ms":627,"metadata":{"okta_request_id":"REDACTED","rate_limit_remaining":"16","uri":"users","url":"https://dev-12345678.okta.com/api/v1/users?activate=true"}"}
The log message is prefixed with the class name only (
ApiClient). The fully-qualifiedmethodremains in the log context.
{
"event_type": "okta.api.post.success.ok",
"method": "BoldlyGrow\\Okta\\ApiClient::post",
"event_ms": 627,
"metadata": {
"okta_request_id": "REDACTED",
"rate_limit_remaining": "16",
"uri": "users",
"url": "https://dev-12345678.okta.com/api/v1/users?activate=true"
}
}
Log Parameter Definitions
| Parameter Name | Example Usage | Description |
|---|---|---|
event_type (Required)string |
provider.entity.action.result.reason |
The octet notation event type that follows our codestyle conventions. |
level (Required)string |
debuginfonoticewarningerrorcriticalalertemergency |
The log level for the log entry |
message (Required)string |
Validation Failed | A short message to include in the logs. This will be auto-prefixed with the fully-qualified method name (the "noun") so you can keep the message focused on the "verb" language. |
method (Required)string |
__METHOD__ |
The method where this audit log is created in or is on behalf of. |
actor_emailstring |
auth()->user()->email |
The email address of the actor |
actor_idstring |
auth()->user()->id |
The database ID of the actor |
actor_namestring |
auth()->user()->name |
The first and last name of the actor |
actor_provider_idstring |
auth()->user()->provider_id |
The 3rd party vendor API ID of the actor (ex. Okta User ID) |
actor_session_idstring |
session()->getId() |
The session ID of the actor |
actor_sourcestring |
systemapiwebcli |
The origin of the request. Auto-detected as system, api, or web when omitted; see Actor Source. Validated against config('audit-log.actor.source.allowed'). |
actor_typestring |
config('auth.providers.users.model') |
The fully-qualified class name of the authenticated user model. |
actor_usernamestring |
auth()->user()->username |
The username of the actor |
attribute_keystring |
(State Changes) The database column name that has changed. | |
attribute_value_oldstring |
(State Changes) The value in the database before the update. | |
attribute_value_newstring |
(State Changes) The API value that is now updated in the database. | |
count_recordsint |
count($array) |
(Multiple records) Count of records processed. |
databasebool |
truefalse (default) |
Whether to persist this event to the database. See Database Persistence. |
dump_configstring |
default |
(Response Schema) The array key in config/audit-log.php that contains the date, keys, strings schema configuration. The other dump_* parameters are ignored if dump_config is set. |
dump_datestring |
cY-m-dY-m-d H:i:s |
(Response Schema) The PHP datetime format string for timestamps returned in the response array. |
dump_keysarray |
See docs | (Response Schema) An filtered list of array of keys from the AuditLog::create() method that returned in the response array. |
dump_stringsarray |
See docs | (Response Schema) An array of key value pairs of static strings that should be included in the in the response array (instead of having to add them yourself with collection transformation later). |
duration_msCarbon |
$duration_ms |
Carbon instance (timestamp) used for long running batch jobs to provide a point-in-time duration since job started. |
duration_ms_per_recordint |
(int) ($duration_ms / count($records)) |
Number of milliseconds divided by count of records. This is not auto-calculated to allow flexibility for custom Carbon timestamps |
errorsarray |
Flat array of error message(s) that will be encoded as JSON | |
event_msCarbon |
$event_ms |
Carbon instance (timestamp) that was initialized at the start of the action and provides a point-in-time duration for this specific action within a longer running job. |
event_ms_per_recordint |
(int) ($event_ms / count($records)) |
Number of milliseconds divided by count of records. This is not auto-calculated to allow flexibility for custom Carbon timestamps |
job_batchstring |
(Background Job Logs) The human identifier string or system ID of the batch of jobs. Format is at your discretion. | |
job_idstring |
(Background Job Logs) The human identifier string or system ID of the specific job that triggered this log entry. Format is at your discretion. | |
job_platformstring |
githubgitlablambdaredis{your string} |
(Background Job Logs) The human identifier string of the platform that the background jobs are running in. Format is at your discretion. |
job_pipeline_idstring |
(Background Job Logs) The system ID of the CI/CD pipeline (if applicable). | |
job_timestampstring |
now()->getTimestamp() |
(Background Job Logs) The timestamp that the job or pipeline was started. This is useful for identifying which scheduled job timestamp triggered this event. |
job_transaction_idstring |
now()->getTimestamp() |
(Background Job Logs) An alternative to job_id that can be used for additional indexable identifiers used by your application or business logic. |
logbool |
true (default)false |
Whether to create a system log entry for this event. See docs. |
metadataarray |
An array of custom metadata that should be included in the log | |
occurred_atstring |
2023-02-01T03:45:27.612584Z |
A datetime that will be formatted with Carbon for when the event occurred at based on a created_at or updated_at API timestamp |
parent_idstring |
{uuid} |
(Many-to-Many Relationship Events) The database ID of the database model with a many-to-many relationship. |
parent_typestring |
App\Models\Path\To\ModelName |
(Many-to-Many Relationship Events) The fully-qualified namespace of the database model with a many-to-many relationship. |
parent_modelstring |
ProviderApplication::class |
(Many-to-Many Relationship Events) The model class name. Auto-calculates parent_type; see Model References. |
parent_provider_idstring |
a1b2c3d4e5f6 |
(Many-to-Many Relationship Events) The API ID of the database model with a many-to-many relationship that is usually stored in the database in the `provider_id` column. |
parent_reference_keystring |
name |
(Many-to-Many Relationship Events) The database column name for value that is human readable in logs |
parent_reference_valuestring |
(Many-to-Many Relationship Events) The value of the human readable database column | |
record_idstring |
{uuid} |
The database ID of the affected database model |
record_typestring |
App\Models\Path\To\ModelName |
The fully-qualified namespace of the database model |
record_modelstring |
ProviderEntity::class |
The model class name of the affected record. Auto-calculates record_type; see Model References. |
record_provider_idstring |
a1b2c3d4e5f6 |
The API ID of the affected database model that is usually stored in the database in the `provider_id` column. |
record_reference_keystring |
name |
The database column name for value that is human readable in logs |
record_reference_valuestring |
The value of the human readable database column | |
related_idstring |
{uuid} |
The database ID of a related human or service account. |
related_modelstring |
ProviderUser::class |
The model class name of the related account. Auto-calculates related_type. |
subject_idstring |
{uuid} |
The database ID of the impacted human or service account subject. |
subject_modelstring |
ProviderService::class |
The model class name of the subject. Kept generic so any application module's model may be used. Auto-calculates subject_type. |
tenant_idstring |
{uuid} |
The database ID of the top-level organization/tenant for the provider |
tenant_typestring |
App\Models\VendorName\Organization |
The fully-qualified namespace of the database model of the top-level entity (organization, tenant, etc) for the provider. |
tenant_modelstring |
ProviderOrganization::class |
The model class name of the top-level entity. Auto-calculates tenant_type. |
transactionbool (deprecated) |
truefalse (default) |
Deprecated alias for database. Either flag persists the event. Prefer database. |
Advanced Usage
Actor Metadata
The following fields related to the actor (authenticated user) are captured with each log entry.
This uses Auth::user() that uses the model configured in the providers array in config/auth.php. The Laravel default is App\Models\User::class, however your application may use a different model.
Mapping Custom User Attributes
If your user model uses different column names (for example work_email or display_name), map each actor field to the attribute(s) it should read in config('audit-log.actor.attributes'). A mapping may be a single attribute name or an ordered list of candidates, in which case the first non-null value wins (this is how name falls back to full_name by default).
// config/audit-log.php 'actor' => [ 'attributes' => [ 'id' => 'id', 'email' => 'work_email', 'name' => ['display_name', 'name', 'full_name'], 'provider_id' => 'okta_id', 'username' => 'handle', ], ],
| Attribute | Authenticated (Auth::check()) |
Unauthenticated |
|---|---|---|
actor_email |
Auth::user()->email |
null |
actor_id |
Auth::user()->id |
null |
actor_ip_addr |
proxy header or request()->ip() |
proxy header or request()->ip() |
actor_name |
Auth::user()->name ?? Auth::user()->full_name |
null |
actor_provider_id |
Auth::user()->provider_id |
null |
actor_session_id |
session()->getId() |
session()->getId() |
actor_source |
system / api / web (auto-detected) |
system / api / web |
actor_type |
config('auth.providers.users.model') |
null |
actor_username |
Auth::user()->username |
null |
Actor IP Address Behind a Proxy or CDN
If your application is behind a proxy or CDN, add the trusted header(s) that carry the originating IP to config('audit-log.actor.ip_headers'). The first non-empty header wins, falling back to request()->ip().
// config/audit-log.php 'actor' => [ 'ip_headers' => [ 'CF-Connecting-IP', 'X-Forwarded-For', ], ],
Actor Source
The actor_source field records the origin of the request. It is auto-detected as system (console commands and queued jobs), api (API routes or requests that expect JSON), or web. The cli value is available for applications that detect device-based tokens, and must be passed explicitly.
The allowed vocabulary lives in one place. Add your own values (for example service) there, and any value passed to AuditLog::create(actor_source: '...') is validated against the list.
// config/audit-log.php 'actor' => [ 'source' => [ 'enabled' => env('AUDIT_ACTOR_SOURCE_ENABLED', true), 'allowed' => ['system', 'cli', 'api', 'web'], ], ],
The table above shows the defaults that are auto-populated for each actor field. You can override any of them by passing the corresponding argument to AuditLog::create().
use BoldlyGrow\AuditLog\AuditLog; AuditLog::create( // ... actor_email: '{string}', actor_id: '{string}', actor_ip_addr: '{string}', actor_name: '{string}', actor_provider_id: '{string}', actor_session_id: '{string}', actor_source: '{string}', actor_type: '{string}', actor_username: '{string}', // ... );
Disabling Actor Metadata
Actor metadata is enabled by default. You can disable actor metdata if you do not want to capture actor metadata automatically or your application does not support request and session data (ex. Laravel Zero CLI app).
You can use an environment variables or your .env file to disable it.
AUDIT_ACTOR_ENABLED=false
If your application cannot support actor metadata, you can permanently disable it in config/audit-log.php.
'actor' => [ - 'enabled' => env('AUDIT_ACTOR_ENABLED', true) + 'enabled' => false ],
Background Job Log Entry
You can add the job_* parameters if you are running background jobs and want to add metadata to your logs and persisted database records. All of these values (except job_timestamp) are freeform strings that you can standardize however you'd like.
use BoldlyGrow\AuditLog\AuditLog; AuditLog::create( // ... job_batch: '{string}', job_id: '{string}', job_platform: '{string}', job_pipeline_id: '{string}', job_timestamp: now()->getTimestamp(), job_transaction_id: '{string}', // ... );
Model References and Automatic Types
Each relationship (parent, record, related, subject, tenant) accepts a fully-qualified model class name via a *_model parameter. The paired *_type value is auto-calculated as a snake_case string using the namespace configured in config('audit-log.model.namespace') (default App\Models\).
use BoldlyGrow\AuditLog\AuditLog; AuditLog::create( // ... record_id: $user->id, record_model: \App\Models\Okta\User::class, // record_type => "okta_user" related_id: $manager->id, related_model: \App\Models\Okta\User::class, subject_id: $service->id, subject_model: \App\Models\Service::class, // any module's model may be used // ... );
The legacy string parameters (record_type: 'App\\Models\\Okta\\User') still work for backwards compatibility. When both are provided, the *_model value takes precedence.
Database Persistence
In addition to writing to the system log, entries can be persisted to a database table for perpetual audit storage and querying.
-
Run the installer to publish the config, an application model overlay, and the migration:
php artisan audit-log:installThe overlay (
App\Models\AuditLogby default) extends the package base modelBoldlyGrow\AuditLog\Models\AuditLog. Add relationships and casts to the overlay, and reference it from your UI and API code — it is safe from package upgrades. The installer also reminds you to pointconfig('audit-log.database.model')at the overlay. -
Enable persistence and run the migration:
AUDIT_DATABASE_ENABLED=truephp artisan migrate -
Pass
database: trueon the events you want to persist:use BoldlyGrow\AuditLog\AuditLog; AuditLog::create( // ... database: true, // ... );
The table name is configurable via config('audit-log.database.table') (or the AUDIT_DATABASE_TABLE env variable). If persistence is enabled but the configured model is missing or invalid, a warning is logged and the event is still logged normally — a misconfiguration never prevents your code from completing.
Adding Custom Fields
You will often need to store application-specific fields (for example a tenant, organization, or workspace ID) on your audit log records. There are two approaches.
Recommended: Metadata Flatten (no package changes)
-
Add the column(s) to the table with your own migration:
Schema::table('audit_logs', function (Blueprint $table) { $table->string('federation_organization_id')->nullable()->index(); });
-
Whitelist the key in
config('audit-log.database.custom_fields'):'database' => [ 'custom_fields' => [ 'federation_organization_id', ], ],
-
Add a relationship to your published
App\Models\AuditLogoverlay if desired. -
Pass the value inside
metadata:AuditLog::create( // ... database: true, metadata: [ 'federation_organization_id' => $organization->id, ], // ... );
Whitelisted keys are flattened out of metadata into their matching columns. They also remain in the metadata JSON for the system log.
Advanced: First-Class Parameter
If you want a custom field as a first-class parameter of AuditLog::create() (rather than passed via metadata), the value must be added in each of these places within the package:
- The
create()method signature and docblock - The
$log_context_keysgrouping - The
validate()rules - The
$log_dataarray (for persistence) - The base model
casts()(if a non-string cast is needed) - The migration
Skipping Log Creation
You can specify true/false booleans for the log and database parameters. By default, log is true and database is false. (transaction is retained as a deprecated alias for database.)
The parsed and formatted schema is always returned as an array.
log |
database |
Behavior |
|---|---|---|
true |
false |
(Default) Log entry is created. |
true |
true |
Log entry is created. Database row is persisted. |
false |
true |
No log is created. Database row is persisted. |
false |
false |
No log or database row is created. Used for schema parsing. |
Response Schema
One of the benefits to this package is the formatted array with predictable keys.
In addition to (or instead of) writing a log or persisting to the database, every call returns a formatted array with all of the keys and their provided or default values. This is useful if you simply need an array that you will use for your own changelog or some other purpose. You can also disable log creation and use this like a data transfer object (DTO).
Simply define a variable to get the returned array.
use BoldlyGrow\AuditLog\AuditLog; // Create a log entry with no returned array AuditLog::create( // ... log: true // ... ); // Define a variable with the returned array $schema = AuditLog::create( // ... log: true // ... ); // Append the return array to an existing array of records that are not created in system logs foreach($records as $record) { // ... $changelog[] = AuditLog::create( // ... log: false // ... ); }
Example Response Array with No Configuration
use BoldlyGrow\AuditLog\AuditLog; $event_ms = now(); $result = AuditLog::create( event_ms: $event_ms, event_type: "okta.api.post.success.ok", level: "info", message: "Success", metadata: [ "okta_request_id" => "REDACTED", "rate_limit_remaining" => "199", "uri" => "users", "url" => "https://dev-12345678.okta.com/api/v1/users?activate=true" ], method: "BoldlyGrow\Okta\ApiClient::get" ); dd($result); // [ // "datetime" => "2024-03-02T18:51:10+00:00", // "event_type" => "okta.api.post.success.ok", // "level" => "info", // "message" => "Success", // "method" => "BoldlyGrow\Okta\ApiClient::get", // "actor_email" => null, // "actor_id" => null, // "actor_ip_addr" => null, // "actor_name" => null, // "actor_provider_id" => null, // "actor_session_id" => "…", // "actor_source" => "system", // "actor_type" => null, // "actor_username" => null, // "attribute_key" => null, // "attribute_value_old" => null, // "attribute_value_new" => null, // "count_records" => null, // "duration_ms" => null, // "duration_ms_per_record" => null, // "errors" => [], // "event_ms" => 4, // "event_ms_per_record" => null, // "job_batch" => null, // "job_id" => null, // "job_platform" => null, // "job_pipeline_id" => null, // "job_timestamp" => null, // "job_transaction_id" => null, // "metadata" => [ // "okta_request_id" => "REDACTED", // "rate_limit_remaining" => "199", // "uri" => "users", // "url" => "https://dev-12345678.okta.com/api/v1/users?activate=true", // ], // "occurred_at" => null, // "parent_id" => null, // "parent_type" => null, // "parent_provider_id" => null, // "parent_reference_key" => null, // "parent_reference_value" => null, // "record_id" => null, // "record_type" => null, // "record_provider_id" => null, // "record_reference_key" => null, // "record_reference_value" => null, // "related_id" => null, // "related_type" => null, // "subject_id" => null, // "subject_type" => null, // "tenant_id" => null, // "tenant_type" => null, // ]
The
*_modelparameters do not appear as separate keys in the returned array — they are folded into their paired*_typevalue. When a database row is persisted, both the*_model(fully-qualified class) and*_type(snake_case) columns are stored.
Specifying Keys in Response Array
There are a large number of parameter keys in the schema. To avoid having to use Laravel Collections transform methods with the result array, you can simply pass an array of keys to the dump_keys array that you want to be included.
use BoldlyGrow\AuditLog\AuditLog; $result = AuditLog::create( // ... dump_keys: [ 'event_type', 'message', 'attribute_key', 'attribute_value_old', 'attribute_value_new', 'record_id', 'record_type', 'record_provider_id', 'record_reference_key', 'record_reference_value' ], ); dd($result); // [ // "datetime" => "2024-03-02T18:53:35+00:00", // "event_type" => "okta.api.post.success.ok", // "message" => "Success", // "attribute_key" => null, // "attribute_value_old" => null, // "attribute_value_new" => null, // "record_id" => null, // "record_type" => null, // "record_provider_id" => null, // "record_reference_key" => null, // "record_reference_value" => null, // ]
Specifying Custom Static Strings in Response Array
If you need to add custom static strings to your array, they can be specified in the dump_strings array. Strings are returned at the end of the array.
use BoldlyGrow\AuditLog\AuditLog; $result = AuditLog::create( // ... dump_keys: [ 'event_type', 'message', 'attribute_key', 'attribute_value_old', 'attribute_value_new', 'record_id', 'record_type', 'record_provider_id', 'record_reference_key', 'record_reference_value' ], dump_strings: [ 'custom_key' => 'my_value', 'another_key' => 'my_value', ], // ... ); dd($result); // [ // "datetime" => "2024-03-02T18:54:55+00:00", // "event_type" => "okta.api.post.success.ok", // "message" => "Success", // "attribute_key" => null, // "attribute_value_old" => null, // "attribute_value_new" => null, // "record_id" => null, // "record_type" => null, // "record_provider_id" => null, // "record_reference_key" => null, // "record_reference_value" => null, // "custom_key" => "my_value", // "another_key" => "my_value", // ]
Custom Datetime Format in Response Array
The datetime is always returned in the first key (table column) of the array. You can customize the format using a string of supported PHP datetime format characters. By default, we use c for the ISO 8601 format (YYYY-MM-DDTHH:II:SS+00:00). You may want to simplify this with Y-m-d or Y-m-d H:i.
use BoldlyGrow\AuditLog\AuditLog; $result = AuditLog::create( // ... dump_date: 'c', dump_keys: [ 'event_type', 'message', 'attribute_key', 'attribute_value_old', 'attribute_value_new', 'record_id', 'record_type', 'record_provider_id', 'record_reference_key', 'record_reference_value' ], dump_strings: [ 'custom_key' => 'my_value', 'another_key' => 'my_value', ], // ... ); dd($result); // [ // "datetime" => "2024-03-02", // "event_type" => "okta.api.post.success.ok", // // .... // ]
Standardized Configurations for Response Array
Reminder: You need to publish the configuration file for it to appear in
config/audit-log.phpor it will use the default one in thevendor/boldlygrow/audit-logdirectory that cannot be modified.
It can be difficult to manage your simplified schemas throughout your code base.
You can define standardized simplified schemas in the config/audit-log.php file for each of your use cases. The default key is a placeholder that can be customized and you can add additional arrays for each type of resource if needed (ex. okta_user).
After a schema is defined, simply set the dump_config key to the same key that was defined in config/audit-log.php.
use BoldlyGrow\AuditLog\AuditLog; $result = AuditLog::create( // ... dump_config: 'okta_user' // ... );
// config/audit-log.php return [ 'dump' => [ 'default' => [ 'date' => 'c', 'strings' => [ 'custom_key' => 'my_value' ], 'keys' => [ 'event_type', 'message', 'record_id', 'record_type', 'record_provider_id', 'record_reference_key', 'record_reference_value' ], ], 'okta_user' => [ 'date' => 'c', 'strings' => [ 'custom_key' => 'my_value' ], 'keys' => [ 'event_type', 'message', 'attribute_key', 'attribute_value_old', 'attribute_value_new', 'record_id', 'record_type', 'record_provider_id', 'record_reference_key', 'record_reference_value' ] ] ] ];
Real World Example for Response Arrays
use BoldlyGrow\AuditLog\AuditLog; $result = AuditLog::create( attribute_key: $attribute, attribute_value_old: $manifest_record[$attribute], attribute_value_new: $api_record[$attribute], duration_ms: $this->duration_ms, event_type: $this->event_type . '.datadumper.manifest.attribute.changed.' . $attribute, level: 'info', log: true, message: Str::title($attribute) . ' Attribute Value Changed', method: __METHOD__, record_provider_id: $manifest_record['provider_id'], record_reference_key: $this->reference_key, record_reference_value: $manifest_record[$this->reference_key] ?? null, database: true ); dd($result); // [ // 'datetime' => 'YYYY-MM-DDTHH:II:SS+00:00', // 'event_type' => 'okta.user.sync.datadumper.manifest.attribute.changed.manager', // 'message' => 'Manager Attribute Value Changed', // 'attribute_key' => 'manager', // 'attribute_value_old' => 'klibby', // 'attribute_value_new' => 'dmurphy', // 'record_id' => null, // 'record_type' => 'okta_user', // 'record_provider_id' => '00u1b2c3d4e5f6g7h8i9', // 'record_reference_key' => 'handle', // 'record_reference_value' => 'jpardella' // 'custom_key' => 'my_value', // ]
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-07-10