-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3.0.0 winston.query throws exception for File Transport #1130
Comments
For others that have the same problem here is a temporary hack that lets // TODO REMOVE WHEN FIXED
// necessary workarounds for winston 3.0.0-rc1..
function clone(obj) {
var copy = Array.isArray(obj) ? [] : {};
for (var i in obj) {
if (Array.isArray(obj[i])) {
copy[i] = obj[i].slice(0);
} else if (obj[i] instanceof Buffer) {
copy[i] = obj[i].slice(0);
} else if (typeof obj[i] != 'function') {
copy[i] = obj[i] instanceof Object ? clone(obj[i]) : obj[i];
} else if (typeof obj[i] === 'function') {
copy[i] = obj[i];
}
}
return copy;
}
require("winston/lib/winston/common").clone = clone;
let Transport = require("winston-transport");
Transport.prototype.normalizeQuery = function (options) { //
options = options || {};
// limit
options.rows = options.rows || options.limit || 10;
// starting row offset
options.start = options.start || 0;
// now
options.until = options.until || new Date;
if (typeof options.until !== 'object') {
options.until = new Date(options.until);
}
// now - 24
options.from = options.from || (options.until - (24 * 60 * 60 * 1000));
if (typeof options.from !== 'object') {
options.from = new Date(options.from);
}
// 'asc' or 'desc'
options.order = options.order || 'desc';
// which fields to select
options.fields = options.fields;
return options;
};
Transport.prototype.formatResults = function (results, options) {
return results;
}; |
Thanks @Kouzukii, I had to do the same, taking as an example the v 2.x. |
@Kouzukii , this blows up for me:
|
@indexzero I'd like to work on this but I'm unsure of the direction. There must have been a reason for removing some of these functions. Should I reuse 2.x code or did you have something else in mind. |
How to use this hack? |
Hey since there's some unclarity here, And at the very top of your require('./winston-workaround');
// or with babel
import './winston-workaround' And the example posted by the Winston team should work (tested with winston 3.0.0). If I get some time soon, I'll open a pull request that resolves this issue. |
Thank you @Kouzukii, I did what you recommended
// TODO REMOVE WHEN FIXED
// necessary hacks for winston 3.0.0-rc1..
function clone (obj) {
var copy = Array.isArray(obj) ? [] : {}
for (var i in obj) {
if (Array.isArray(obj[i])) {
copy[i] = obj[i].slice(0)
} else if (obj[i] instanceof Buffer) {
copy[i] = obj[i].slice(0)
} else if (typeof obj[i] !== 'function') {
copy[i] = obj[i] instanceof Object ? clone(obj[i]) : obj[i]
} else if (typeof obj[i] === 'function') {
copy[i] = obj[i]
}
}
return copy
}
require('winston/lib/winston/common').clone = clone
let Transport = require('winston-transport')
Transport.prototype.normalizeQuery = function (options) {
options = options || {}
// limit
options.rows = options.rows || options.limit || 10
// starting row offset
options.start = options.start || 0
// now
options.until = options.until || new Date()
if (typeof options.until !== 'object') {
options.until = new Date(options.until)
}
// now - 24
options.from = options.from || (options.until - (24 * 60 * 60 * 1000))
if (typeof options.from !== 'object') {
options.from = new Date(options.from)
}
// 'asc' or 'desc'
options.order = options.order || 'desc'
// which fields to select
options.fields = options.fields
return options
}
Transport.prototype.formatResults = function (results, options) {
return results
} and this is my entry point require('./tools/winston-workaround')
/* Core Libraries */
import chokidar from 'chokidar'
import chalk from 'chalk'
import fs from 'fs'
import path from 'path'
import moment from 'moment'
/* App Libraries */
import { db } from './database'
import upload from './upload'
/* App Config */
import { logger } from './tools'
import CONFIG from '../config.json'
const { AWS: { S3: S3Config } } = CONFIG
const Op = db.Sequelize.Op
...
..
.
const options = {
from: global.processTimeStart,
until: timeEnd
}
logger.query(options, (err, results) => {
if (err) {
throw err
}
console.log(results)
}) but I still have the same error |
This is my winston configuration
import { createLogger, format, transports } from 'winston'
import path from 'path'
import moment from 'moment'
// import CustomTransport from './customTransport'
import stripAnsi from 'strip-ansi'
import CONFIG from '../../config.json'
const { combine, printf } = format
const frmtLog = printf(info => {
// Remove Colors Characters
const level = stripAnsi(info.level)
const message = stripAnsi(info.message)
const now = moment(info.timestamps).format('YYYY-MM-DD hh:mm:ss')
return `[${now}] ${level}: ${message}`
})
const logger = createLogger({
format: combine(
frmtLog
),
transports: [
new transports.File({
filename: path.join(CONFIG.LOGS, 'info.log'),
level: 'info'
}),
new transports.File({
filename: path.join(CONFIG.LOGS, 'warning.log'),
level: 'warning'
}),
new transports.File({
filename: path.join(CONFIG.LOGS, 'error.log'),
level: 'error'
}),
new transports.File({
filename: path.join(CONFIG.LOGS, 'combined.log')
})
]
})
if (process.env.NODE_ENV !== 'production') {
logger.add(new transports.Console({
format: format.combine(
format.colorize({
all: true
}),
format.simple()
)
}))
} |
@jnreynoso that's interesting, I just tried this with Babel and it seems that babel sorts the require('./winston-workaround'); to import './winston-workaround' |
thank you very much @Kouzukii. Your solution worked correctly. |
This issue is still happening as of v3.3.3. Or why is it still open? |
It is still open for libraries like |
Work-around works perfectly though when will this be brought back was it removed unintentionally? |
Why won't this get fixed? |
Lack of any budget at all for maintenance of this project, lack of any PRs for a fix and/or anti-regression test to review even if there were more resources available for that, and presence of an existing workaround which probably eliminates the motivation for potential PR authors, all likely play a role. |
The Functions Transport.prototype.normalizeQuery, Transport.prototype.formatResults and common.clone were removed in 3.0.0, so query will throw an unhandled exception.
The text was updated successfully, but these errors were encountered: