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 matlab数字图像处理频率域滤波
    • ¥15 ELGamal和paillier计算效率谁快?
    • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
    • ¥15 ubuntu系统下挂载磁盘上执行./提示权限不够
    • ¥15 Arcgis相交分析无法绘制一个或多个图形
    • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
    • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
    • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
    • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
    • ¥30 3天&7天&&15天&销量如何统计同一行