15
15
use Symfony \Component \HttpFoundation \Request ;
16
16
use Symfony \Component \HttpFoundation \Response ;
17
17
use Symfony \Component \HttpKernel \Log \DebugLoggerInterface ;
18
+ use Symfony \Component \VarDumper \Caster \LinkStub ;
18
19
19
20
/**
20
21
* LogDataCollector.
24
25
class LoggerDataCollector extends DataCollector implements LateDataCollectorInterface
25
26
{
26
27
private $ logger ;
28
+ private $ containerPathPrefix ;
27
29
28
- /**
29
- * @var string
30
- */
31
- private $ cacheDir ;
32
-
33
- /**
34
- * @var string
35
- */
36
- private $ containerClass ;
37
-
38
- public function __construct ($ logger = null , $ cacheDir = null , $ containerClass = null )
30
+ public function __construct ($ logger = null , $ containerPathPrefix = null )
39
31
{
40
32
if (null !== $ logger && $ logger instanceof DebugLoggerInterface) {
41
33
$ this ->logger = $ logger ;
42
34
}
43
35
44
- $ this ->cacheDir = $ cacheDir ;
45
- $ this ->containerClass = $ containerClass ;
36
+ $ this ->containerPathPrefix = $ containerPathPrefix ;
46
37
}
47
38
48
39
/**
@@ -61,17 +52,10 @@ public function lateCollect()
61
52
if (null !== $ this ->logger ) {
62
53
$ this ->data = $ this ->computeErrorsCount ();
63
54
64
- if ($ bootLogs = $ this ->getBootLogsFile ()) {
65
- $ bootLogs = array_map (array ($ this , 'hydrateBootDeprecation ' ), $ bootLogs );
66
- $ this ->data ['deprecation_count ' ] += count ($ bootLogs );
67
- }
68
-
69
- if ($ compilerLogs = $ this ->getCompilerLogsFile ()) {
70
- $ this ->data ['compiler_logs ' ] = $ compilerLogs ;
71
- }
72
-
73
- $ this ->data ['logs ' ] = $ this ->sanitizeLogs ($ this ->logger ->getLogs ());
74
- $ this ->data ['logs ' ] = array_merge ($ this ->data ['logs ' ], $ bootLogs );
55
+ $ containerDeprecationLogs = $ this ->getContainerDeprecationLogs ();
56
+ $ this ->data ['deprecation_count ' ] += count ($ containerDeprecationLogs );
57
+ $ this ->data ['container_compiler_logs ' ] = $ this ->getContainerCompilerLogs ();
58
+ $ this ->data ['logs ' ] = array_merge ($ this ->sanitizeLogs ($ this ->logger ->getLogs ()), $ containerDeprecationLogs );
75
59
$ this ->data = $ this ->cloneVar ($ this ->data );
76
60
}
77
61
}
@@ -113,45 +97,54 @@ public function countScreams()
113
97
114
98
public function getCompilerLogs ()
115
99
{
116
- return isset ($ this ->data ['compiler_logs ' ]) ? $ this ->data ['compiler_logs ' ] : array ();
100
+ return isset ($ this ->data ['container_compiler_logs ' ]) ? $ this ->data ['container_compiler_logs ' ] : array ();
117
101
}
118
102
119
103
/**
120
- * @return array
104
+ * {@inheritdoc}
121
105
*/
122
- private function getBootLogsFile ()
106
+ public function getName ()
123
107
{
124
- $ file = current (glob ($ this ->cacheDir .'/ ' .$ this ->containerClass .'Boot.log ' ));
125
-
126
- return ($ file ) ? unserialize (file_get_contents ($ file )) : array ();
108
+ return 'logger ' ;
127
109
}
128
110
129
- /**
130
- * @return array
131
- */
132
- private function getCompilerLogsFile ()
111
+ private function getContainerDeprecationLogs ()
133
112
{
134
- $ file = current (glob ($ this ->cacheDir .'/ ' .$ this ->containerClass .'Compiler.log ' ));
113
+ if (null === $ this ->containerPathPrefix || !file_exists ($ file = $ this ->containerPathPrefix .'Deprecations.log ' )) {
114
+ return array ();
115
+ }
135
116
136
- return ($ file ) ? file ($ file , FILE_IGNORE_NEW_LINES ) : array ();
137
- }
117
+ $ stubs = array ();
118
+ $ bootTime = filemtime ($ file );
119
+ $ logs = array ();
120
+ foreach (unserialize (file_get_contents ($ file )) as $ log ) {
121
+ $ log += array ('scream ' => false , 'is_deprecation ' => true , 'priorityName ' => '' , 'timestamp ' => $ bootTime );
138
122
139
- /**
140
- * {@inheritdoc}
141
- */
142
- public function getName ()
143
- {
144
- return 'logger ' ;
123
+ if (!isset ($ stubs [$ log ['file ' ]])) {
124
+ $ stubs [$ log ['file ' ]] = new LinkStub ($ log ['file ' ]);
125
+ }
126
+ $ log ['file ' ] = $ stubs [$ log ['file ' ]];
127
+
128
+ $ logs [] = $ log ;
129
+ }
130
+
131
+ return $ logs ;
145
132
}
146
133
147
- /**
148
- * @param array $log
149
- *
150
- * @return array
151
- */
152
- private function hydrateBootDeprecation (array $ log )
134
+ private function getContainerCompilerLogs ()
153
135
{
154
- return array_merge ($ log , array ('scream ' => false , 'is_deprecation ' => true , 'priorityName ' => '' ));
136
+ if (null === $ this ->containerPathPrefix || !file_exists ($ file = $ this ->containerPathPrefix .'Compiler.log ' )) {
137
+ return array ();
138
+ }
139
+
140
+ $ logs = array ();
141
+ foreach (file ($ file , FILE_IGNORE_NEW_LINES ) as $ log ) {
142
+ $ log = explode (': ' , $ log , 2 );
143
+
144
+ $ logs [$ log [0 ]][] = array ('message ' => $ log [1 ]);
145
+ }
146
+
147
+ return $ logs ;
155
148
}
156
149
157
150
private function sanitizeLogs ($ logs )
0 commit comments