{"id":20121795,"url":"https://github.com/parseword/logger","last_synced_at":"2026-04-17T15:02:00.935Z","repository":{"id":57036031,"uuid":"167624340","full_name":"parseword/logger","owner":"parseword","description":"A PHP class implementing a singleton text file logging facility","archived":false,"fork":false,"pushed_at":"2019-01-26T01:16:46.000Z","size":11,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-02T20:26:14.528Z","etag":null,"topics":["file-logger","logger","php7","singleton"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/parseword.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":"2019-01-25T22:49:36.000Z","updated_at":"2022-02-12T13:19:55.000Z","dependencies_parsed_at":"2022-08-24T06:40:45.677Z","dependency_job_id":null,"html_url":"https://github.com/parseword/logger","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/parseword/logger","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parseword%2Flogger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parseword%2Flogger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parseword%2Flogger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parseword%2Flogger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/parseword","download_url":"https://codeload.github.com/parseword/logger/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parseword%2Flogger/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265026226,"owners_count":23699911,"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":["file-logger","logger","php7","singleton"],"created_at":"2024-11-13T19:32:43.686Z","updated_at":"2026-04-17T15:01:55.909Z","avatar_url":"https://github.com/parseword.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Logger\r\n\r\nLogger is a PHP text file logging facility, implemented as a singleton. It's \r\nnothing special, but I'm breaking a larger code base down into independent \r\ncomponents and I needed this to be in its own repository.\r\n\r\n## Usage\r\n\r\nImplementing `Logger` in 4 easy steps:\r\n\r\n1. Either `composer require parseword/logger` or copy the `Logger.php` file into \r\nyour project.\r\n\r\n2. Make sure `Logger.php` is discoverable by your autoloader, or `require_once` \r\nit manually.\r\n\r\n3. Throughout your application code, call `Logger::debug()`, `Logger::info()`, \r\n`Logger::warning()` and `Logger::error()` to send log messages of differing \r\nseverity levels.\r\n\r\n4. In your application's config file or a common include file, you (or the user) \r\ncall Logger::setFilename() to set the log file, and Logger::setSeverityFilter() \r\nto specify which log messages are written to disk.\r\n\r\n## Example\r\n\r\nIn the following example, a file named `/tmp/my.log` is created. The severity \r\nfilter is set so that only messages with severity of WARNING or higher will be \r\nwritten. Messages with lower severity will be disregarded.\r\n\r\n```php\r\n\u003c?php\r\n//Set up the logger in your config or global include file\r\nuse parseword\\logger\\Logger;\r\nLogger::setFilename('/tmp/my.log');\r\nLogger::setSeverityFilter(Logger::SEVERITY_WARNING);\r\nLogger::setLabel('myCoolApp');\r\n\r\n//Call the static Logger methods throughout your application code\r\nLogger::info(\"Somebody set us up the bomb.\");\r\nLogger::debug(\"Main screen turn on.\");\r\nLogger::warning(\"All your base are belong to us.\");\r\nLogger::info(\"You have no chance to survive make your time.\");\r\nLogger::error(\"Unable to move 'ZIG', aborting\");\r\n```\r\n\r\nThe contents of `/tmp/my.log` will look like this:\r\n\r\n```\r\n[2019-01-25,14:40:13.797 CST]  WARN: myCoolApp: All your base are belong to us.\r\n[2019-01-25,14:40:13.797 CST] ERROR: myCoolApp: Unable to move 'ZIG', aborting\r\n```\r\n\r\nInspect or run the included `test.php` file for more examples.\r\n\r\n## Method overview\r\n\r\nThese methods are used to configure the Logger:\r\n\r\n* `setCollapseEntries()` - Whether or not to replace newlines in log entries \r\nwith spaces, constraining each entry to a single line. Defaults to true.\r\n\r\n* `setDateFormat()` - Set the date format to use when stamping log messages.\r\n\r\n* `setFilename()` - Set the filesystem path and filename for the log file.\r\n\r\n* `setLabel()` - Set an optional text string to include in log messages. If \r\neach instance of your application has a unique ID, setting it here can help \r\nwith tracing and troubleshooting.\r\n\r\n* `setSeverityFilter()` - Set which types of log messages are written to the file.\r\n\r\nThese methods control the logger's functionality:\r\n\r\n* `debug()` - Send a log message of severity DEBUG.\r\n\r\n* `error()` - Send a log message of severity ERROR.\r\n\r\n* `warning()` - Send a log message of severity WARNING.\r\n\r\n* `info()` - Send a log message of severity INFO.\r\n\r\n* `truncate()` - Truncate the log file, wiping out any previous entries.\r\n\r\n## Requirements\r\n\r\nThe Logger class requires PHP7 to support scalar type declarations.\r\n\r\n## Errata\r\n\r\nNone at this time.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparseword%2Flogger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparseword%2Flogger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparseword%2Flogger/lists"}