Skip to content
Snippets Groups Projects
Commit 6715f1f6 authored by Sigmund, Dominik's avatar Sigmund, Dominik
Browse files

Added Option to create File if not exists

parent 0f756f3a
Branches
Tags
1 merge request!1Update index.test.js, examples/all-options.js, examples/log-to-file.js,...
...@@ -41,6 +41,6 @@ These Tags will be added to the line with octothorpes added. ...@@ -41,6 +41,6 @@ These Tags will be added to the line with octothorpes added.
name: 'Name of App. Default: Name of BaseFolder', name: 'Name of App. Default: Name of BaseFolder',
hostname: 'Server Hostname, Default: os.hostname()', hostname: 'Server Hostname, Default: os.hostname()',
file: 'File to Append Log to', file: 'File to Append Log to',
logLevel: 'Minimal LogLevel. Default: WARN' loglevel: 'Minimal LogLevel. Default: WARN'
} }
``` ```
\ No newline at end of file
...@@ -26,6 +26,13 @@ function Log (options) { ...@@ -26,6 +26,13 @@ function Log (options) {
} }
if (this.options.file) { if (this.options.file) {
this.fs = require('fs') 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) { this.info = function (message, tags) {
if (this.loglevel >= this.levels.INFO) { if (this.loglevel >= this.levels.INFO) {
......
{ {
"name": "lib-log", "name": "lib-log",
"version": "1.0.0", "version": "1.1.0",
"description": "A simple Logger with Options!", "description": "A simple Logger with Options!",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment