Skip to content
This repository
Browse code

OS-1759 mkdir /var/log/vm if it doesn't exist and if we can't create …

…it, just log to ring buffer.
  • Loading branch information...
commit 397889a49e44188bb68817c2a3486e3911335887 1 parent ddf692e
joshwilsdon authored December 11, 2012

Showing 1 changed file with 23 additions and 8 deletions. Show diff stats Hide diff stats

  1. 31  src/vm/node_modules/VM.js
31  src/vm/node_modules/VM.js
@@ -203,6 +203,14 @@ function ensureLogging(action, side_effects)
203 203
     var logname;
204 204
     var streams = [];
205 205
 
  206
+    function start_logging() {
  207
+        VM.log = bunyan.createLogger({
  208
+            name: logname,
  209
+            streams: streams,
  210
+            serializers: bunyan.stdSerializers
  211
+        });
  212
+    }
  213
+
206 214
     // This is here in case an app calls a lookup first and then a create.  The
207 215
     // logger will get created in no-sideeffects mode for the lookup but when
208 216
     // the create is called this will force the switch to writing.
@@ -228,9 +236,6 @@ function ensureLogging(action, side_effects)
228 236
         streams = streams.concat(VM.logger);
229 237
     }
230 238
 
231  
-    filename = '/var/log/vm/' + Date.now(0) + '-'
232  
-        + sprintf('%06d', process.pid) + '-' + logname + '.log';
233  
-
234 239
     // Add the ringbuffer which we'll dump if we switch from not writing to
235 240
     // writing, and so that they'll show up in dumps.
236 241
     streams.push({
@@ -239,6 +244,20 @@ function ensureLogging(action, side_effects)
239 244
         stream: ringbuffer
240 245
     });
241 246
 
  247
+    try {
  248
+        if (!fs.existsSync('/var/log/vm')) {
  249
+            fs.mkdirSync('/var/log/vm');
  250
+        }
  251
+    } catch (e) {
  252
+        // We can't ever log to a file in /var/log/vm if we can't create it,
  253
+        // so we just log to ring buffer (above).
  254
+        start_logging();
  255
+        return;
  256
+    }
  257
+
  258
+    filename = '/var/log/vm/' + Date.now(0) + '-'
  259
+        + sprintf('%06d', process.pid) + '-' + logname + '.log';
  260
+
242 261
     if (side_effects) {
243 262
         streams.push({
244 263
             level: VM.loglevel,
@@ -252,11 +271,7 @@ function ensureLogging(action, side_effects)
252 271
         });
253 272
     }
254 273
 
255  
-    VM.log = bunyan.createLogger({
256  
-        name: logname,
257  
-        streams: streams,
258  
-        serializers: bunyan.stdSerializers
259  
-    });
  274
+    start_logging();
260 275
 }
261 276
 
262 277
 function ltrim(str, chars)

0 notes on commit 397889a

Please sign in to comment.
Something went wrong with that request. Please try again.