From 6715f1f66a642cf6e34de8e7da5767c27e39d03f Mon Sep 17 00:00:00 2001 From: Dominik Sigmund <dominik.sigmund@br.de> Date: Wed, 30 Jan 2019 09:18:23 +0100 Subject: [PATCH] Added Option to create File if not exists --- README.md | 2 +- index.js | 7 +++++++ package.json | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a5ce6fd..8fe141d 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,6 @@ These Tags will be added to the line with octothorpes added. name: 'Name of App. Default: Name of BaseFolder', hostname: 'Server Hostname, Default: os.hostname()', file: 'File to Append Log to', - logLevel: 'Minimal LogLevel. Default: WARN' + loglevel: 'Minimal LogLevel. Default: WARN' } ``` \ No newline at end of file diff --git a/index.js b/index.js index 0bf88a1..3bbb2a3 100644 --- a/index.js +++ b/index.js @@ -26,6 +26,13 @@ function Log (options) { } if (this.options.file) { this.fs = require('fs') + this.path = require('path') + this.options.file = this.path.resolve(this.options.file) + try { + this.fs.accessSync(this.options.file, this.fs.constants.R_OK | this.fs.constants.W_OK) + } catch (err) { + this.fs.writeFileSync(this.options.file, '') + } } this.info = function (message, tags) { if (this.loglevel >= this.levels.INFO) { diff --git a/package.json b/package.json index 36762a7..8b85ad7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lib-log", - "version": "1.0.0", + "version": "1.1.0", "description": "A simple Logger with Options!", "main": "index.js", "scripts": { -- GitLab