{"id":13669512,"url":"https://github.com/jbroadway/analog","last_synced_at":"2025-05-15T20:07:30.915Z","repository":{"id":2174688,"uuid":"3121550","full_name":"jbroadway/analog","owner":"jbroadway","description":"PHP logging library that is highly extendable and simple to use.","archived":false,"fork":false,"pushed_at":"2023-12-10T23:04:37.000Z","size":164,"stargazers_count":345,"open_issues_count":1,"forks_count":49,"subscribers_count":25,"default_branch":"master","last_synced_at":"2025-05-13T01:16:48.283Z","etag":null,"topics":["amon","amon2","analog","apprise","chrome-logger","error-monitoring","errors","firephp","gelf","logger","logging","mongodb","monitoring","php","psr-3","stderr","syslog"],"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/jbroadway.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-01-06T22:31:11.000Z","updated_at":"2025-04-01T16:06:46.000Z","dependencies_parsed_at":"2023-12-09T02:25:49.848Z","dependency_job_id":"9439f002-5b79-4b27-95bb-9c9db0822396","html_url":"https://github.com/jbroadway/analog","commit_stats":{"total_commits":150,"total_committers":15,"mean_commits":10.0,"dds":0.3933333333333333,"last_synced_commit":"7876e8011dad1b3ce08e51f5edbfaa5a2d7893d3"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbroadway%2Fanalog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbroadway%2Fanalog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbroadway%2Fanalog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbroadway%2Fanalog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jbroadway","download_url":"https://codeload.github.com/jbroadway/analog/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254414499,"owners_count":22067272,"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":["amon","amon2","analog","apprise","chrome-logger","error-monitoring","errors","firephp","gelf","logger","logging","mongodb","monitoring","php","psr-3","stderr","syslog"],"created_at":"2024-08-02T08:01:15.998Z","updated_at":"2025-05-15T20:07:25.593Z","avatar_url":"https://github.com/jbroadway.png","language":"PHP","readme":"# Analog - Minimal PHP logging library\n\n![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/jbroadway/analog/ci.yml?branch=master)\n![GitHub](https://img.shields.io/github/license/jbroadway/analog)\n![Packagist Version](https://img.shields.io/packagist/v/analog/analog)\n![Packagist PHP Version Support](https://img.shields.io/packagist/php-v/analog/analog)\n![Packagist Downloads](https://img.shields.io/packagist/dt/analog/analog)\n\nA minimal PHP logging package based on the idea of using closures\nfor configurability and extensibility. It functions as a static class, but you can\ncompletely control the writing of log messages through a closure function\n(aka [anonymous functions](http://ca3.php.net/manual/en/functions.anonymous.php)),\nor use the `Analog\\Logger` wrapper that implements the\n[PSR-3 specification](https://www.php-fig.org/psr/psr-3/).\n\n## Installation\n\nInstall the latest version with:\n\n```bash\n$ composer require analog/analog\n```\n\n## Usage\n\n### Basic Usage\n\n```php\n\u003c?php\n\nuse Analog\\Analog;\nuse Analog\\Handler\\FirePHP;\n\nAnalog::handler (FirePHP::init ());\n\nAnalog::log ('Take me to your browser');\n```\n\n### Usage with [PSR-3](https://www.php-fig.org/psr/psr-3/)\n\n```php\n\u003c?php\n\nuse Analog\\Logger;\nuse Analog\\Handler\\Variable;\n\n$logger = new Logger;\n\n$log = '';\n\n$logger-\u003ehandler (Variable::init ($log));\n\n$logger-\u003ealert ('Things are really happening right now!');\n\n// With context\n$logger-\u003edebug ('Testing {0}:{1}', [__FILE__, __LINE__]);\n\nvar_dump ($log);\n```\n\n### Usage with a custom handler\n\n```php\n\u003c?php\n\nuse Analog\\Analog;\n\n// Default logging to /tmp/analog.txt\nAnalog::log ('Log this error');\n\n// Log to a MongoDB log collection\nAnalog::handler (function ($info) {\n\tstatic $conn = null;\n\tif (! $conn) {\n\t\t$conn = new Mongo ('localhost:27017');\n\t}\n\t$conn-\u003emydb-\u003elog-\u003einsert ($info);\n});\n\n// Log an alert\nAnalog::log ('The sky is falling!', Analog::ALERT);\n\n// Log some debug info\nAnalog::log ('Debugging info', Analog::DEBUG);\n```\n\n### Usage without composer\n\nAnalog uses a simple autoloader internally, so if you don't have access to [composer](https://getcomposer.org/) you can clone this repository and include it like this:\n\n```php\n\u003c?php\n\nrequire 'analog/lib/Analog.php';\n\nAnalog::handler (Analog\\Handler\\Stderr::init ());\n\nAnalog::log ('Output to php://stderr');\n```\n\nFor more examples, see the [examples](https://github.com/jbroadway/analog/tree/master/examples) folder.\n\n## Logging Options\n\nBy default, this class will write to a file named `sys_get_temp_dir() . '/analog.txt'`\nusing the format `\"machine - date - level - message\\n\"`, making it usable with no\ncustomization necessary.\n\nAnalog also comes with dozens of pre-written handlers in the Analog/Handlers folder,\nwith examples for each in the examples folder. These include:\n\n* [Amon](https://github.com/jbroadway/analog/blob/master/examples/amon.php) - Send logs to the [Amon](http://amon.cx/) server monitoring tool\n* [Apprise](https://github.com/jbroadway/analog/blob/master/examples/apprise.php) - Send notifications through the [apprise](https://github.com/caronc/apprise) command line tool\n* [Buffer](https://github.com/jbroadway/analog/blob/master/examples/buffer.php) - Buffer messages to send all at once (works with File, Mail, Stderr, and Variable handlers)\n* [ChromeLogger](https://github.com/jbroadway/analog/blob/master/examples/chromelogger.php) - Sends messages to [Chrome Logger](http://craig.is/writing/chrome-logger) browser plugin\n* [EchoConsole](https://github.com/jbroadway/analog/blob/master/examples/echoconsole.php) - Echo output directly to the console\n* [File](https://github.com/jbroadway/analog/blob/master/examples/file.php) - Append messages to a file\n* [FirePHP](https://github.com/jbroadway/analog/blob/master/examples/firephp.php) - Send messages to [FirePHP](http://www.firephp.org/) browser plugin\n* [GELF](https://github.com/jbroadway/analog/blob/master/examples/gelf.php) - Send message to the [Graylog2](http://www.graylog2.org/) log management server\n* [IFTTT](https://github.com/jbroadway/analog/blob/master/examples/ifttt.php) - Trigger webhooks via the [IFTTT](https://ifttt.com/) service\n* [Ignore](https://github.com/jbroadway/analog/blob/master/examples/ignore.php) - Do nothing\n* [LevelBuffer](https://github.com/jbroadway/analog/blob/master/examples/levelbuffer.php) - Buffer messages and send only if sufficient error level reached\n* [LevelName](https://github.com/jbroadway/analog/blob/master/examples/levelname.php) - Convert log level numbers to names in log output\n* [Mail](https://github.com/jbroadway/analog/blob/master/examples/mail.php) - Send email notices\n* [Mongo](https://github.com/jbroadway/analog/blob/master/examples/mongo.php) - Save to MongoDB collection\n* [Multi](https://github.com/jbroadway/analog/blob/master/examples/multi.php) - Send different log levels to different handlers\n* [PDO](https://github.com/jbroadway/analog/blob/master/examples/pdo.php) - Send messages to any PDO database connection (MySQL, SQLite, PostgreSQL, etc.)\n* [Post](https://github.com/jbroadway/analog/blob/master/examples/post.php) - Send messages over HTTP POST to another machine\n* [Redis](https://github.com/jbroadway/analog/blob/master/examples/redis.php) - Save messages to Redis key using RPUSH\n* [Slackbot](https://github.com/jbroadway/analog/blob/master/examples/slackbot.php) - Post messages to Slack via Slackbot\n* [Stderr](https://github.com/jbroadway/analog/blob/master/examples/stderr.php) - Send messages to STDERR\n* [Syslog](https://github.com/jbroadway/analog/blob/master/examples/syslog.php) - Send messages to syslog\n* [Threshold](https://github.com/jbroadway/analog/blob/master/examples/threshold.php) - Only writes log messages above a certain threshold\n* [Variable](https://github.com/jbroadway/analog/blob/master/examples/variable.php) - Buffer messages to a variable reference\n* [WPMail](https://github.com/jbroadway/analog/blob/master/examples/wpmail.php) - Send email notices using Wordpress `wp_mail()`\n\nSo while it's a micro class, it's highly extensible and very capable out of the box too.\n\n## Rationale\n\nI wrote this because I wanted something very small and simple like\n[KLogger](https://github.com/katzgrau/KLogger), and preferably not torn out\nof a wider framework if possible. After searching, I wasn't happy with the\nsingle-purpose libraries I found. With KLogger for example, I didn't want an\nobject instance but rather a static class, and I wanted more flexibility in\nthe back-end.\n\nI also found some that had the flexibility also had more complexity, for example\n[Monolog](https://github.com/Seldaek/monolog) is dozens of source files (not incl. tests).\nWith closures, this seemed to be a good balance of small without sacrificing\nflexibility.\n\n\u003e What about Analog, the logfile analyzer? Well, since it hasn't been updated\n\u003e since 2004, I think it's safe to call a single-file PHP logging class the\n\u003e same thing without it being considered stepping on toes :)\n","funding_links":[],"categories":["PHP","目录","日志 Logging","日志( Logging )"],"sub_categories":["日志记录 Logging"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjbroadway%2Fanalog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjbroadway%2Fanalog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjbroadway%2Fanalog/lists"}