From 28a690fa1c84a79885693a149bd7229fdaacfa12 Mon Sep 17 00:00:00 2001 From: Lloyd Hilaiel <lloyd@hilaiel.com> Date: Fri, 5 Aug 2011 15:08:29 -0600 Subject: [PATCH] local logs should be stored in a directory, make logging stuff create directories as needed --- .gitignore | 3 ++- libs/configuration.js | 6 ++++-- libs/logging.js | 15 ++++++++++++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index a03c5e393..1823f2e57 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *~ \#*\# .\#* -node_modules +/node_modules +/var diff --git a/libs/configuration.js b/libs/configuration.js index e09b7a23c..ced886982 100644 --- a/libs/configuration.js +++ b/libs/configuration.js @@ -7,7 +7,9 @@ * exports.configure(app); */ -const substitution = require('./substitute.js'); +const +substitution = require('./substitute.js'), +path = require('path'); var g_config = { }; @@ -56,7 +58,7 @@ const g_configs = { port: '10002', scheme: 'http', use_minified_resources: false, - log_path: './', + log_path: path.join(__dirname, "..", "var", "logs"), database: { driver: "json" } } }; diff --git a/libs/logging.js b/libs/logging.js index 7cb5a1eb1..34893f6e4 100644 --- a/libs/logging.js +++ b/libs/logging.js @@ -1,7 +1,8 @@ const winston = require("winston"), configuration = require("./configuration"), -path = require('path'); +path = require('path'), +fs = require('fs'); // go through the configuration and determine log location // for now we only log to one place @@ -10,9 +11,21 @@ path = require('path'); var log_path = configuration.get('log_path'); var LOGGERS = []; +// simple inline function for creation of dirs +function mkdir_p(p) { + if (!path.existsSync(p)) { + mkdir_p(path.dirname(p)); + console.log("mkdir", p); + fs.mkdirSync(p, "0755"); + } +} + function setupLogger(category) { if (!log_path) return console.log("no log path! Not logging!"); + else + mkdir_p(log_path); + // don't create the logger if it already exists if (LOGGERS[category]) -- GitLab