{"id":20525761,"url":"https://github.com/garbetjie/monolog-bigquery-handler","last_synced_at":"2026-04-20T17:05:13.742Z","repository":{"id":62509035,"uuid":"146087505","full_name":"garbetjie/monolog-bigquery-handler","owner":"garbetjie","description":"A simple Monolog handler for writing to BigQuery.","archived":false,"fork":false,"pushed_at":"2018-09-07T06:28:35.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-16T11:26:49.397Z","etag":null,"topics":["bigquery","logging","monolog","monolog-handler"],"latest_commit_sha":null,"homepage":null,"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/garbetjie.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-25T10:48:46.000Z","updated_at":"2018-09-07T06:28:18.000Z","dependencies_parsed_at":"2022-11-02T13:00:37.427Z","dependency_job_id":null,"html_url":"https://github.com/garbetjie/monolog-bigquery-handler","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garbetjie%2Fmonolog-bigquery-handler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garbetjie%2Fmonolog-bigquery-handler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garbetjie%2Fmonolog-bigquery-handler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garbetjie%2Fmonolog-bigquery-handler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/garbetjie","download_url":"https://codeload.github.com/garbetjie/monolog-bigquery-handler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242130124,"owners_count":20076554,"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":["bigquery","logging","monolog","monolog-handler"],"created_at":"2024-11-15T23:09:15.878Z","updated_at":"2026-04-20T17:05:13.710Z","avatar_url":"https://github.com/garbetjie.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BigQuery Monolog Handler\n\nA simple (and configurable) Monolog handler for writing log messages to BigQuery, making use of Google's\n`google/cloud-bigquery` PHP client.\n\n## Installation\n\n```\ncomposer require garbetjie/monolog-bigquery-handler\n```\n\nRequires PHP 7.0.\n\n## Getting started\n\nThe handler expects the BigQuery dataset and table to have been created already - the handler will not create either of\nthem.\n\nYou can run the following command (using the BigQuery command line tool) to create a minimal table that will be able to\naccept log records (replace `$dataset` and `$table` with the actual dataset and table names):\n\n```bash\nbq mk --schema=\"channel:string,message:string,level:integer,level_name:string,context:string,extra:string,datetime:timestamp\" --time_partitioning_field=\"datetime\" \"$dataset.$table\"\n```\n\n## Usage\n\nSimply create an instance of the BigQuery client, and pass it to the handler, along with the dataset and table names to\ninsert log records to.\n \n```php\n$bigQueryClient = new Google\\Cloud\\BigQuery\\BigQueryClient();\n$handler = new Garbetjie\\Monolog\\Handler\\BigQueryHandler($bigQueryClient, 'dataset_name', 'table_name', $level = Logger::DEBUG, $bubble = true);\n$logger = new Monolog\\Logger('channel', [$handler]);\n\n$logger-\u003edebug('debug message');\n```\n\nThe usage shown above will send each message individually. It is recommended to make use of a `BufferHandler`. This will\nensure that log messages are batched, and will reduce the duration spent sending log messages.\n\nWhen determining the size of the buffer to use, ensure that you're aware of the [quota limits for streaming inserts](https://cloud.google.com/bigquery/quotas#streaming_inserts)\nin BigQuery. If any of these limits are hit, the whole batch of messages will fail.\n\nAn example of using the `BufferHandler` is shown below:\n\n```php\n// Using a buffer handler to batch log messages.\n\n$bigQueryClient = new Google\\Cloud\\BigQuery\\BigQueryClient();\n$handler = new Garbetjie\\Monolog\\Handler\\BigQueryHandler($bigQueryClient, 'dataset_name', 'table_name', $level = Logger::DEBUG, $bubble = true);\n$handler = new Monolog\\Handler\\BufferHandler($handler, $bufferLimit = 10);\n$logger = new Monolog\\Logger('channel', [$handler]);\n\n$logger-\u003edebug('message 1');\n$logger-\u003edebug('message 2');\n$logger-\u003edebug('message 3');\n```\n\n### Custom fields\n\nAdditional custom fields can be sent along with the logged fields. These custom fields can be added in the following\nway:\n\n```php\n// Using custom fields\n\n$handler = new Garbetjie\\Monolog\\Handler\\BigQueryHandler($bigQueryClient, 'dataset_name', 'table_name', $level = Logger::DEBUG, $bubble = true);\n\n$handler-\u003esetCustomField('field_name', 'field_value');\n// Or $handler-\u003esetCustomField(['name' =\u003e 'value', 'other_name' =\u003e 'other_value'])\n\n$handler-\u003eremoveCustomField('field_name');\n// Or $handler-\u003eremoveCustomField(['field_name', 'other_field_name']);\n```\n\nCustom field values can be any scalar value that can be JSON encoded, or one of the following values:\n\n* __`callable`:__ Any `callable` can be passed, and it will be executed before the log record is sent to BigQuery.\n\n### Mapping fields\n\nBy default, the field names to insert to are the same as the [structure of a log record](https://github.com/Seldaek/monolog/blob/334b8d8783a1262c3b8311d6599889d82e9cc58c/doc/message-structure.md).\nHowever, if you have BigQuery column names that aren't the same as these, you can map the log record field names to your\nown column names:\n\n```php\n$bigQueryClient = new Google\\Cloud\\BigQuery\\BigQueryClient();\n$handler = new Garbetjie\\Monolog\\Handler\\BigQueryHandler($bigQueryClient, 'dataset_name', 'table_name', $level = Logger::DEBUG, $bubble = true);\n$handler-\u003esetFieldMapping(['datetime' =\u003e 'logged_at']);  // The `datetime` log record field will now be saved to the `logged_at` column.\n\n$logger-\u003edebug('message 1');\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgarbetjie%2Fmonolog-bigquery-handler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgarbetjie%2Fmonolog-bigquery-handler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgarbetjie%2Fmonolog-bigquery-handler/lists"}