yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.23k stars 6.91k forks source link

Incorrect log level of \yii\db #17870

Closed dicrtarasov closed 4 years ago

dicrtarasov commented 4 years ago

yii\db package log low-level trace messages to info level:

2020-02-18 02:15:17 [46.146.34.244][9075][-][info][yii\web\Session::open] Session started
2020-02-18 02:15:17 [46.146.34.244][9075][-][info][yii\db\Connection::open] Opening DB
2020-02-18 02:15:17 [46.146.34.244][9075][-][info][yii\db\Command::query] SELECT * FROM `user`  

Default application log must not contains low level DB messages at info level, because it generates huge log files which become unusabe for important messages. There must be more important information messages at this level.

Excluding yii\db\* from log target by adding exception:

'except' => ['yii\db\*']

is not a right way for default configuration and also will disable error and warning messages from \yii\db.

There are no good workaround for this except of separate db-error.log for yii\db :(

dicrtarasov commented 4 years ago

SQL queries is most for debugging purposes.

From Wiki: https://en.wikipedia.org/wiki/Syslog#Severity_level

Info level used for information messages such as staring/stopping jobs or business logic, ex. "use login", "order send". Dumping full SQL queries with data is a debugging level, not a info.

https://dzone.com/articles/logging-levels-what-they-are-and-how-they-help-you quote: "INFO messages correspond to normal application behavior and milestones. You probably won’t care too much about these entries during normal operations, but they provide the skeleton of what happened. A service started or stopped. You added a new user to the database. That sort of thing."

https://reflectoring.io/logging-levels/ quote: "The INFO level should be used to document state changes in the application or some entity within the application. This information can be helpful during development and sometimes even in production to track what is actually happening in the system. Concrete examples for using the INFO level are: the application has started with configuration parameter x having the value y a new entity (e.g. a user) has been created or changed its state the state of a certain business process (e.g. an order) has changed from “open” to “processed” a regularly scheduled batch job has finished and processed z items."

http://thejoyofcode.com/Logging_Levels_and_how_to_use_them.aspx quote: "The Information level is typically used to output information that is useful to the running and management of your system. Information would also be the level used to log Entry and Exit points in key areas of your application. However, you may choose to add more entry and exit points at Debug level for more granularity during development and testing."

samdark commented 4 years ago

You are correct but the change may cause issues for many projects already relying on this logging level.

rob006 commented 4 years ago

Related: https://github.com/yiisoft/yii2/issues/17750 and https://github.com/yiisoft/yii2/pull/16671.

cebe commented 4 years ago

The problem with changing to trace level is that these are excluded before being added to the logger in production environment, so you can not log SQL queries in production with a higher log level.

https://github.com/yiisoft/yii2/blob/55793471eafbcac75b0f1e0bd3ea187b9abed5fe/framework/BaseYii.php#L406-L408

cebe commented 4 years ago

You can disable logging these messages:

https://www.yiiframework.com/doc/api/2.0/yii-db-connection#$enableLogging-detail

See also https://github.com/yiisoft/yii2/issues/1662#issuecomment-438719977