douhunbei0166 2016-11-04 19:37
浏览 65

PHP中的Singleton vs Static Logger类(Laravel项目)

I have a PHP Laravel project, and I want to create a class that logs some of the user activity in my database (some is meant to be read by the user, some is to be analyzed by the system).

I wanted to know what are the best practices/approaches in regards to this. So far, after some reasoning, I determined that creating a (traditional) Eloquent Model would be inefficient, since in order to call methods, I would have to instantiate an object from my Logger class everytime I want to log some activity.

One of the solutions I am thinking of is to create a Static class that logs the activity with "enums" emulation (abstract/final class that will hold a set of constants). Then, from there create methods that will call Laravel's DB (static) façade and use the constants from the "enums" class to store the log.

The other alternative is to create a "Singleton" like so, and then implement the DB façade again.

I wanted to know if these methods are effective in the way that I won't be really instantiating a new object and cluttering my memory full of loggers (since I am planning to do some heavy logging), and that everytime I use a logger it will be as efficient as possible. I am open to other solutions, such as retrieving/storing enums natively in MySQL or some other solution (as long as it is efficient to high volumes of logging)

Many thanks for your help in advance.

Cheers!

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 安装svn网络有问题怎么办
    • ¥15 Python爬取指定微博话题下的内容,保存为txt
    • ¥15 vue2登录调用后端接口如何实现
    • ¥65 永磁型步进电机PID算法
    • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
    • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
    • ¥15 如何处理复杂数据表格的除法运算
    • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
    • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
    • ¥15 latex怎么处理论文引理引用参考文献