diff --git a/lib/log/Readme.md b/lib/log/Readme.md new file mode 100644 index 0000000..61f4e44 --- /dev/null +++ b/lib/log/Readme.md @@ -0,0 +1,13 @@ + + +## createLog(label, filename) ⇒ object +createLog() - Returns a winston logger configured to service + +**Kind**: global function +**Returns**: object - Winston logger + +| Param | Type | Default | Description | +| --- | --- | --- | --- | +| label | string | | Label appearing on logger | +| filename | string | null | Optional file to write log to | + diff --git a/lib/log/index.js b/lib/log/index.js new file mode 100644 index 0000000..8527559 --- /dev/null +++ b/lib/log/index.js @@ -0,0 +1,22 @@ +'use strict' + +const winston = require('winston') + +/** +* createLog() - Returns a winston logger configured to service +* +* @param {string} label Label appearing on logger +* @param {string} filename Optional file to write log to +* @returns {object} Winston logger +*/ +function createLog (label, filename = null) { + const transports = [ new (winston.transports.Console)({ label : label }) ] + if (filename !== null) { + transports.push( new (winston.transports.File)({ label : label, filename : filename }) ) + } + return new (winston.Logger)({ + transports: transports + }) +} + +module.exports = createLog \ No newline at end of file diff --git a/lib/wifi/index.js b/lib/wifi/index.js index 513062a..2f236d2 100644 --- a/lib/wifi/index.js +++ b/lib/wifi/index.js @@ -9,6 +9,7 @@ const refresh = '/sbin/ifdown wlan0 && /sbin/ifup --force wlan0' const iwlist = '/sbin/iwlist wlan0 scanning | grep "ESSID:"' const iwgetid = '/sbin/iwgetid' +const log = require('../log')('wifi') const exec = require('child_process').exec const fs = require('fs')