Skip to content

Commit

Permalink
Feature/reduce logfile noise (#3)
Browse files Browse the repository at this point in the history
* Comment out a lot of winston calls that are causing noisy logs and at present there is no control to shut them off.

* Bump version - patch v1.1.1
  • Loading branch information
jon-shipley authored and GuyHarwood committed Oct 19, 2018
1 parent 83c047b commit 356aa19
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 21 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@
# 1.1.0

* First working version, some features consumed by [MTC](https://github.com/DFEAGILEDEVOPS/MTC)

# 1.1.1

* reduce logfile noise

2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.0
1.1.1
38 changes: 19 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

const R = require('ramda')
const { Request, TYPES } = require('tedious')
const winston = require('winston')
// winston.level = 'debug'
// const winston = require('winston')
// winston.level = 'error'

const sqlPoolService = require('./pool')
const moment = require('moment')
Expand Down Expand Up @@ -121,7 +121,7 @@ async function generateParams (tableName, data) {
options.precision = cacheData.precision
options.scale = cacheData.scale
}
winston.debug(`sql.service: generateParams: options set for [${column}]`, options)
// winston.debug(`sql.service: generateParams: options set for [${column}]`, options)
params.push({
name: column,
value,
Expand Down Expand Up @@ -162,7 +162,7 @@ function isInsertStatement (sql = '') {
if (s.slice(0, 6) !== 'INSERT') {
return false
}
winston.debug(`sql.service: INSERT statement found: ${sql}`)
// winston.debug(`sql.service: INSERT statement found: ${sql}`)
return true
}

Expand All @@ -179,8 +179,8 @@ sqlService.adminSchema = '[mtc_admin]'
* @return {Promise<*>}
*/
sqlService.query = (sql, params = []) => {
winston.debug(`sql.service.query(): ${sql}`)
winston.debug('sql.service.query(): Params ', R.map(R.pick(['name', 'value']), params))
// winston.debug(`sql.service.query(): ${sql}`)
// winston.debug('sql.service.query(): Params ', R.map(R.pick(['name', 'value']), params))
return new Promise(async (resolve, reject) => {
let con
try {
Expand All @@ -195,11 +195,11 @@ sqlService.query = (sql, params = []) => {
var request = new Request(sql, function (err, rowCount) {
con.release()
if (err) {
winston.debug('ERROR SQL: ', sql)
// winston.debug('ERROR SQL: ', sql)
return reject(err)
}
const objects = parseResults(results)
winston.debug('RESULTS', JSON.stringify(objects))
// winston.debug('RESULTS', JSON.stringify(objects))
resolve(objects)
})

Expand All @@ -225,8 +225,8 @@ sqlService.query = (sql, params = []) => {
* @return {Promise}
*/
sqlService.modify = (sql, params = []) => {
winston.debug('sql.service.modify(): SQL: ' + sql)
winston.debug('sql.service.modify(): Params ', R.map(R.pick(['name', 'value']), params))
// winston.debug('sql.service.modify(): SQL: ' + sql)
// winston.debug('sql.service.modify(): Params ', R.map(R.pick(['name', 'value']), params))

return new Promise(async (resolve, reject) => {
const isInsert = isInsertStatement(sql)
Expand All @@ -239,7 +239,7 @@ sqlService.modify = (sql, params = []) => {
return reject(err)
}
const res = R.assoc('rowsModified', (isInsert ? rowCount - 1 : rowCount), response)
winston.debug('sql.service: modify: result:', res)
// winston.debug('sql.service: modify: result:', res)
return resolve(res)
})

Expand All @@ -260,7 +260,7 @@ sqlService.modify = (sql, params = []) => {
}
const opts = param.options ? param.options : options
if (opts && Object.keys(opts).length) {
winston.debug('sql.service: modify(): opts to addParameter are: ', opts)
// winston.debug('sql.service: modify(): opts to addParameter are: ', opts)
}

request.addParameter(
Expand Down Expand Up @@ -321,12 +321,12 @@ sqlService.getCacheEntryForColumn = async function (table, column) {
await this.updateDataTypeCache()
}
if (!cache.hasOwnProperty(key)) {
winston.debug(`sql.service: cache miss for ${key}`)
// winston.debug(`sql.service: cache miss for ${key}`)
return undefined
}
const cacheData = cache[key]
winston.debug(`sql.service: cache hit for ${key}`)
winston.debug('sql.service: cache', cacheData)
// winston.debug(`sql.service: cache hit for ${key}`)
// winston.debug('sql.service: cache', cacheData)
return cacheData
}

Expand All @@ -338,7 +338,7 @@ sqlService.getCacheEntryForColumn = async function (table, column) {
*/
sqlService.generateInsertStatement = async (table, data) => {
const params = await generateParams(table, data)
winston.debug('sql.service: Params ', R.compose(R.map(R.pick(['name', 'value'])))(params))
// winston.debug('sql.service: Params ', R.compose(R.map(R.pick(['name', 'value'])))(params))
const sql = `
INSERT INTO ${sqlService.adminSchema}.${table} ( ${extractColumns(data)} ) VALUES ( ${createParamIdentifiers(data)} );
SELECT SCOPE_IDENTITY()`
Expand Down Expand Up @@ -376,7 +376,7 @@ sqlService.create = async (tableName, data) => {
const res = await sqlService.modify(sql, params)
return res
} catch (error) {
winston.warn('sql.service: Failed to INSERT', error)
// winston.warn('sql.service: Failed to INSERT', error)
throw error
}
}
Expand Down Expand Up @@ -411,7 +411,7 @@ sqlService.updateDataTypeCache = async function () {
maxLength: row.CHARACTER_MAX_LENGTH
}
})
winston.debug('sql.service: updateDataTypeCache() complete')
// winston.debug('sql.service: updateDataTypeCache() complete')
}

/**
Expand All @@ -433,7 +433,7 @@ sqlService.update = async function (tableName, data) {
const res = await sqlService.modify(sql, params)
return res
} catch (error) {
winston.warn('sql.service: Failed to UPDATE', error)
// winston.warn('sql.service: Failed to UPDATE', error)
throw error
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "less-tedious",
"version": "1.1.0",
"version": "1.1.1",
"description": "helper package for tedious SQL Server module",
"main": "index.js",
"repository": {
Expand Down

0 comments on commit 356aa19

Please sign in to comment.