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 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料
    • ¥15 使用R语言marginaleffects包进行边际效应图绘制
    • ¥20 usb设备兼容性问题
    • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
    • ¥15 安装svn网络有问题怎么办