{"id":18750691,"url":"https://github.com/webiny/logger","last_synced_at":"2025-11-26T21:30:14.518Z","repository":{"id":20227747,"uuid":"23499596","full_name":"webiny/Logger","owner":"webiny","description":"[READ-ONLY] PHP PSR-3 log component. You can use sockets, email and other types for login different information. (master at Webiny/Framework)","archived":false,"fork":false,"pushed_at":"2017-11-26T21:24:53.000Z","size":44,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-12-28T22:54:05.430Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://www.webiny.com/","language":"PHP","has_issues":false,"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/webiny.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2014-08-30T19:56:57.000Z","updated_at":"2023-05-21T17:38:22.000Z","dependencies_parsed_at":"2022-08-22T15:40:25.336Z","dependency_job_id":null,"html_url":"https://github.com/webiny/Logger","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FLogger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FLogger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FLogger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FLogger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webiny","download_url":"https://codeload.github.com/webiny/Logger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239636223,"owners_count":19672305,"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-11-07T17:12:49.686Z","updated_at":"2025-11-26T21:30:14.436Z","avatar_url":"https://github.com/webiny.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Logger\n======\n\nLogger component is used to log data. You can log whatever you want to whatever destination, all you need to do is create a `handler` for your logger driver.\nThis component was heavily inspired by https://github.com/Seldaek/monolog library (if you used that one before, this component will be very familiar to you).\nYou may say it's identical, but we found some things we wanted to change/improve, like having a `Record` class with proper getters/setters,\nwe changed some method namings, processing logic and other bits and pieces to better suite our framework.\nWe do lack different handlers, formatters and processors out-of-the-box, but that will come with time.\n\nInstall the component\n---------------------\nThe best way to install the component is using Composer.\n\n```bash\ncomposer require webiny/logger\n```\nFor additional versions of the package, visit the [Packagist page](https://packagist.org/packages/webiny/logger).\n\n## Drivers\nBuilt-in drivers are:\n- `Null`\n- `Webiny`\n\n`Null` driver is used to turn off logging without changing your code. You simply change your configuration to use `Null` driver and all your logging calls will be sent into the void.\n`Webiny` driver contains most of the functionality you will ever need from a logger, so that driver is used by default.\n\nLogger component uses PSR-3 Logger Interface and PSR-3 Log Levels. All log level constants are located in `LoggerLevel` class.\nWith that being said, you can create your own logger driver, which will not even have handlers, formatters, processors, or anything like that.\nJust implement the logger interface and the rest is up to you. If you do like Monolog concept, then `Webiny` driver is the way to go.\n\n## Logger setup\nHere is an example logger service setup, which uses a `FileHandler`, two processors and a `FileFormatter`.\nThe structure of the config file is identical to all other Webiny components that register services.\n\n```yaml\nLogger:\n    Parameters:\n        Logger.Class: \\Webiny\\Component\\Logger\\Logger\n        Logger.Driver.Class: \\Webiny\\Component\\Logger\\Driver\\Webiny\n        Logger.Processor.FileLine.Class: \\Webiny\\Component\\Logger\\Driver\\Webiny\\Processor\\FileLineProcessor\n        Logger.Processor.MemoryUsage.Class: \\Webiny\\Component\\Logger\\Driver\\Webiny\\Processor\\MemoryUsageProcessor\n        Logger.Formatter.File.Class: \\Webiny\\Component\\Logger\\Driver\\Webiny\\Formatter\\FileFormatter\n        Logger.Handlers.File.Class: \\Webiny\\Component\\Logger\\Driver\\Webiny\\Handler\\FileHandler\n    Services:\n        MyFileLogger:\n            Class: %Logger.Class%\n            Arguments: [System, %Logger.Driver.Class%]\n            Calls:\n                - [addHandler, [@Logger.LogHandler]]\n        LogFile:\n            Class: \\Webiny\\Component\\Storage\\File\\File\n            Arguments:\n                Key: Development/Log.txt\n                Storage: @Storage.Logger # Define this service in your Storage configuration\n        LogHandler:\n            Class: %Logger.Handlers.File.Class%\n            Arguments: [@Logger.LogFile, [], true, false]\n            Calls:\n                - [addProcessor, [%Logger.Processor.FileLine.Class%]]\n                - [addProcessor, [%Logger.Processor.MemoryUsage.Class%]]\n                - [setFormatter, [%Logger.Formatter.File.Class%]]\n    Configs:\n        Formatter:\n            Default:\n                DateFormat: 'H:i:s d-m-Y'\n            File:\n                RecordFormat: '%datetime% [%loggerName%] [%level%]: %message%\\nContext: %context%\\nExtra: %extra%\\n\\n'\n    ClassLoader:\n        Psr: '../Psr'\n```\n\nNOTE: `FileHandler` in our example (LogHandler service) takes a `File` as first argument. We can only write to files\nusing `Storage` component, so we need a service which provides us with a `File` instance.\n\nTo use your logger in PHP:\n\n```php\n// Set component config\nLogger::setConfig($pathToYourConfigFile);\n\n// Now your logger exists in the system as a 'MyFileLogger' service.\n// You can use it by either using a LoggerTrait...\n$logger = $this-\u003elogger('MyFileLogger');\n$logger-\u003einfo('This is pretty simple!');\n\n// ... or by using ServiceManagerTrait. Note that ServiceManager groups services by component\n// So your service is called 'Logger.MyFileLogger'. When using LoggerTrait, it appends the service group for you.\n$logger = $this-\u003eservice('Logger.MyFileLogger');\n$logger-\u003ewarn('This is just a little bit longer...');\n```\n\n## The logic behind logger setup and log message processing\n1. Create a logger instance\n2. Create a handler instance(s) (you can have multiple handlers in your logger)\n3. Add processors and formatters to your handler instance(s)\n4. Add handler(s) to your logger\n5. Use your logger\n\nWhen you log a message, it goes through each handler, which in turn passes it to each processor. Formatter is the last thing to change a record.\nIt simply formats the record into form that is appropriate for your handler. It may be string, array, etc.\nAt the very end of processing - handler writes the formatted record to destination (be it file, database, email, socket, etc.)\n\nResources\n---------\n\nTo run unit tests, you need to use the following command:\n\n    $ cd path/to/Webiny/Component/Logger/\n    $ composer.phar install\n    $ phpunit","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebiny%2Flogger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebiny%2Flogger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebiny%2Flogger/lists"}