[PSR-3] [SUGGESTION] Static version of the logger interface?
260 views
Skip to first unread message
Joaquin
unread,
Jun 25, 2017, 2:21:33 PM6/25/17
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to PHP Framework Interoperability Group
Hello. I was wondering if it was at all possible to have a static logger option. For my purposes I do not need an object for logging and calling non-static methods statically is deprecated in PHP 7.
Larry Garfield
unread,
Jun 26, 2017, 7:12:21 PM6/26/17
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to php...@googlegroups.com
If you want to bridge your code to a PSR-3 object, it's trivial enough
to have a global function that returns a singleton version of a PSR-3
object from your PSR-3 implementation of your choice.
I would not encourage doing so, but it's simple enough to make such a
wrapper yourself that I don't see a need for a PSR on it.
--Larry Garfield
Jason Judge
unread,
Jun 28, 2017, 5:50:08 AM6/28/17
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to PHP Framework Interoperability Group
On Sunday, 25 June 2017 19:21:33 UTC+1, Joaquin wrote:
Hello. I was wondering if it was at all possible to have a static logger option. For my purposes I do not need an object for logging and calling non-static methods statically is deprecated in PHP 7.
Most platforms tend to avoid static libraries, because of the difficulty of injecting configuration details. The way to handle it is to instantiate it once at the start, with all the settings you need (e.g. file name and location, or some other logging channel). Then you keep using that single instantiation throughout the remainder of the application.
You just need to be able to *get at* the instantiation from anywhere, which means it will ultimately be in the global scope somewhere. Older applications would use a global `$logger` variable. Newer applications a locator service of some sort. That may be wrapped with a facade to give it some static availability. But the idea is, there is one instantiation, and the point of use - where messages are logged - should be simple and easy to use.
The PSR interface to all this is around the instantiated class, and that will be hidden from your main application code under the locator/global/facade/other layers you put on top.