Add log library

This commit is contained in:
mmcwilliams 2017-09-24 22:27:53 -04:00
parent 50262facc2
commit 1b51b50185
3 changed files with 36 additions and 0 deletions

13
lib/log/Readme.md Normal file
View File

@ -0,0 +1,13 @@
<a name="createLog"></a>
## createLog(label, filename) ⇒ <code>object</code>
createLog() - Returns a winston logger configured to service
**Kind**: global function
**Returns**: <code>object</code> - Winston logger
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| label | <code>string</code> | | Label appearing on logger |
| filename | <code>string</code> | <code>null</code> | Optional file to write log to |

22
lib/log/index.js Normal file
View File

@ -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

View File

@ -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')