{"id":13669221,"url":"https://github.com/katzgrau/KLogger","last_synced_at":"2025-04-27T01:32:52.644Z","repository":{"id":45074096,"uuid":"734976","full_name":"katzgrau/KLogger","owner":"katzgrau","description":"A Simple Logging Class For PHP","archived":false,"fork":false,"pushed_at":"2022-07-29T20:43:03.000Z","size":73,"stargazers_count":973,"open_issues_count":19,"forks_count":284,"subscribers_count":75,"default_branch":"master","last_synced_at":"2025-04-18T16:59:57.826Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://codefury.net/projects/klogger/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/katzgrau.png","metadata":{"files":{"readme":"README.markdown","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-06-23T01:53:37.000Z","updated_at":"2025-03-17T03:00:13.000Z","dependencies_parsed_at":"2022-09-03T22:52:05.343Z","dependency_job_id":null,"html_url":"https://github.com/katzgrau/KLogger","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/katzgrau%2FKLogger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/katzgrau%2FKLogger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/katzgrau%2FKLogger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/katzgrau%2FKLogger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/katzgrau","download_url":"https://codeload.github.com/katzgrau/KLogger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250460818,"owners_count":21434299,"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":[],"created_at":"2024-08-02T08:01:06.695Z","updated_at":"2025-04-27T01:32:48.323Z","avatar_url":"https://github.com/katzgrau.png","language":"PHP","funding_links":[],"categories":["PHP","日志","目录","日志 Logging","Logging","日志( Logging )"],"sub_categories":["日志记录 Logging"],"readme":"# KLogger: Simple Logging for PHP\n\nA project written by [Kenny Katzgrau](http://twitter.com/katzgrau) and [Dan Horrigan](http://twitter.com/dhrrgn).\n\n## About\n\nKLogger is an easy-to-use [PSR-3](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md)\ncompliant logging class for PHP. It isn't naive about\nfile permissions (which is expected). It was meant to be a class that you could\nquickly include into a project and have working right away.\n\nIf you need a logger that supports PHP \u003c 5.3, see [past releases](https://github.com/katzgrau/KLogger/releases) for KLogger versions \u003c 1.0.0.\n\n## Installation\n\n### Composer\n\nFrom the Command Line:\n\n```\ncomposer require katzgrau/klogger:dev-master\n```\n\nIn your `composer.json`:\n\n``` json\n{\n    \"require\": {\n        \"katzgrau/klogger\": \"dev-master\"\n    }\n}\n```\n\n## Basic Usage\n\n``` php\n\u003c?php\n\nrequire 'vendor/autoload.php';\n\n$users = [\n    [\n        'name' =\u003e 'Kenny Katzgrau',\n        'username' =\u003e 'katzgrau',\n    ],\n    [\n        'name' =\u003e 'Dan Horrigan',\n        'username' =\u003e 'dhrrgn',\n    ],\n];\n\n$logger = new Katzgrau\\KLogger\\Logger(__DIR__.'/logs');\n$logger-\u003einfo('Returned a million search results');\n$logger-\u003eerror('Oh dear.');\n$logger-\u003edebug('Got these users from the Database.', $users);\n```\n\n### Output\n\n```\n[2014-03-20 3:35:43.762437] [INFO] Returned a million search results\n[2014-03-20 3:35:43.762578] [ERROR] Oh dear.\n[2014-03-20 3:35:43.762795] [DEBUG] Got these users from the Database.\n    0: array(\n        'name' =\u003e 'Kenny Katzgrau',\n        'username' =\u003e 'katzgrau',\n    )\n    1: array(\n        'name' =\u003e 'Dan Horrigan',\n        'username' =\u003e 'dhrrgn',\n    )\n```\n\n## PSR-3 Compliant\n\nKLogger is [PSR-3](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md)\ncompliant. This means it implements the `Psr\\Log\\LoggerInterface`.\n\n[See Here for the interface definition.](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md#3-psrlogloggerinterface)\n\n## Setting the Log Level Threshold\n\nYou can use the `Psr\\Log\\LogLevel` constants to set Log Level Threshold, so that\nany messages below that level, will not be logged.\n\n### Default Level\n\nThe default level is `DEBUG`, which means everything will be logged.\n\n### Available Levels\n\n``` php\n\u003c?php\nuse Psr\\Log\\LogLevel;\n\n// These are in order of highest priority to lowest.\nLogLevel::EMERGENCY;\nLogLevel::ALERT;\nLogLevel::CRITICAL;\nLogLevel::ERROR;\nLogLevel::WARNING;\nLogLevel::NOTICE;\nLogLevel::INFO;\nLogLevel::DEBUG;\n```\n\n### Example\n\n``` php\n\u003c?php\n// The \n$logger = new Katzgrau\\KLogger\\Logger('/var/log/', Psr\\Log\\LogLevel::WARNING);\n$logger-\u003eerror('Uh Oh!'); // Will be logged\n$logger-\u003einfo('Something Happened Here'); // Will be NOT logged\n```\n\n### Additional Options\n\nKLogger supports additional options via third parameter in the constructor:\n\n``` php\n\u003c?php\n// Example\n$logger = new Katzgrau\\KLogger\\Logger('/var/log/', Psr\\Log\\LogLevel::WARNING, array (\n    'extension' =\u003e 'log', // changes the log file extension\n));\n```\n\nHere's the full list:\n\n| Option | Default | Description |\n| ------ | ------- | ----------- |\n| dateFormat | 'Y-m-d G:i:s.u' | The format of the date in the start of the log lone (php formatted) |\n| extension | 'txt' | The log file extension |\n| filename | [prefix][date].[extension] | Set the filename for the log file. **This overrides the prefix and extention options.** |\n| flushFrequency | `false` (disabled) | How many lines to flush the output buffer after |\n| prefix  | 'log_' | The log file prefix |\n| logFormat | `false` | Format of log entries |\n| appendContext | `true` | When `false`, don't append context to log entries |\n\n### Log Formatting\n\nThe `logFormat` option lets you define what each line should look like and can contain parameters representing the date, message, etc.\n\nWhen a string is provided, it will be parsed for variables wrapped in braces (`{` and `}`) and replace them with the appropriate value:\n\n| Parameter | Description |\n| --------- | ----------- |\n| date | Current date (uses `dateFormat` option) |\n| level | The PSR log level |\n| level-padding | The whitespace needed to make this log level line up visually with other log levels in the log file |\n| priority | Integer value for log level (see `$logLevels`) |\n| message | The message being logged |\n| context | JSON-encoded context |\n\n#### Tab-separated\n\nSame as default format but separates parts with tabs rather than spaces:\n\n    $logFormat = \"[{date}]\\t[{level}]\\t{message}\";\n\n#### Custom variables and static text\n\nInject custom content into log messages:\n\n    $logFormat = \"[{date}] [$var] StaticText {message}\";\n\n#### JSON\n\nTo output pure JSON, set `appendContext` to `false` and provide something like the below as the value of the `logFormat` option:\n\n```\n$logFormat = json_encode([\n    'datetime' =\u003e '{date}',\n    'logLevel' =\u003e '{level}',\n    'message'  =\u003e '{message}',\n    'context'  =\u003e '{context}',\n]);\n```\n\nThe output will look like:\n\n    {\"datetime\":\"2015-04-16 10:28:41.186728\",\"logLevel\":\"INFO\",\"message\":\"Message content\",\"context\":\"{\"1\":\"foo\",\"2\":\"bar\"}\"}\n    \n#### Pretty Formatting with Level Padding\n\nFor the obsessive compulsive\n\n    $logFormat = \"[{date}] [{level}]{level-padding} {message}\";\n\n... or ...\n\n    $logFormat = \"[{date}] [{level}{level-padding}] {message}\";\n\n## Why use KLogger?\n\nWhy not? Just drop it in and go. If it saves you time and does what you need,\ngo for it! Take a line from the book of our C-code fathers: \"`build` upon the\nwork of others\".\n\n## Who uses KLogger?\n\nKlogger has been used in projects at:\n\n    * The University of Iowa\n    * The University of Laverne\n    * The New Jersey Institute of Technology\n    * Middlesex Hospital in NJ\n\nAdditionally, it's been used in numerous projects, both commercial and personal.\n\n## Special Thanks\n\nSpecial thanks to all contributors:\n\n* [Dan Horrigan](http://twitter.com/dhrrgn)\n* [Brian Fenton](http://github.com/fentie)\n* [Tim Kinnane](http://twitter.com/etherealtim)\n* [Onno Vos](https://github.com/onno-vos-dev)\n* [Cameron Will](https://github.com/cwill747)\n* [Kamil Wylegała](https://github.com/kamilwylegala)\n\n## License\n\nThe MIT License\n\nCopyright (c) 2008-2015 Kenny Katzgrau \u003ckatzgrau@gmail.com\u003e\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkatzgrau%2FKLogger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkatzgrau%2FKLogger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkatzgrau%2FKLogger/lists"}