-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Session Id in log message missing #11258
Comments
Do you have active session at the end of request? |
Session is active before I think that session is automatically destroy before log is written |
It seems, that the problem still exists. Steps to reproduce are the following. Installed basic-app. Made 4 actions in SiteController: `
` And got the results respectively: 2018-08-12 10:58:02 [127.0.0.1][-][-][warning][application] osqk2m5mh4oubnobj1fsgs8dam33e7f2 As you can see the session persists between action calls, but it disappears in logs prefix. So as I understand, if the log isn't final-flushed (as it is during errors like not found exceptions) it places [-], because during the time of log writing, the session already is not active. And I think it's not correct behavior, as you should be able to write in log several times, so it's not correct to call final flush. Maybe it is needed to save session when log message is created for later use in prefix. And use that saved session instead of calling $session->getIsActive(). That is method getMessagePrefix in yii\log\Target Btw, the original discussion thread of this feature (for yii1): https://www.yiiframework.com/forum/index.php/topic/2426-session-id-in-the-logger/ |
So, as mentioned before when Target tries to get session, it is already closed. This is how it looks like. The order of execution is following:
And when in Target.getMessagePrefix it tries to do this:
It sees that there is no session, and it thinks that there were none during all execution (which is wrong). When the reason for that is, that the logging is actually executed after everything is finished. This order is based on this two pieces of code: In Session.init:
In Logger.init:
And as mentioned in the comments of code, it is meant to be called last, but unfortunatelly
The 3 is a crazy guess, but could that be connected to these long hunted mysteries: |
Hello
I have the same problem as @tlanyan in the bug #8036.
I always have the string '[-]' in my log file altought my session is active.
Exemple :
Yii::info('Blablablabla','mhm');
Result :
2016-03-30 13:50:43 [127.0.0.1][XXXXXX][-][info][mhm] Blablablabla
Normaly, the issue was resolved in #8174 with a
$this->flush();
(in Logger.php) when the application shutdown.But, it dosn't work anymore. On the other hand, if I change the statement with the param true like this :
$this->flush(true);
It's work. Maybe it's a good solution ?This is my log target configuration :
The text was updated successfully, but these errors were encountered: