Skip to content
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

Prettify #2185

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Prettifying the repo
a4fbd5ddf3a617cad936b292430d25df4c9ffc61
4 changes: 2 additions & 2 deletions examples/color-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

const winston = require('../');

const logger = module.exports = winston.createLogger({
const logger = (module.exports = winston.createLogger({
transports: [new winston.transports.Console()],
format: winston.format.combine(
winston.format.colorize({ all: true }),
winston.format.simple()
)
});
}));

logger.log('info', 'This is an information message.');
12 changes: 7 additions & 5 deletions examples/create-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ const filename = path.join(__dirname, 'created-logfile.log');
//
// Remove the file, ignoring any errors
//
try { fs.unlinkSync(filename); }
catch (ex) { }
try {
fs.unlinkSync(filename);
} catch (ex) {}

//
// Create a new winston logger instance with two tranports: Console, and File
Expand All @@ -23,12 +24,13 @@ const logger = winston.createLogger({
]
});

logger.log('info', 'Hello created log files!', { 'foo': 'bar' });
logger.log('info', 'Hello created log files!', { foo: 'bar' });

setTimeout(function () {
//
// Remove the file, ignoring any errors
//
try { fs.unlinkSync(filename); }
catch (ex) { }
try {
fs.unlinkSync(filename);
} catch (ex) {}
}, 1000);
10 changes: 4 additions & 6 deletions examples/custom-levels-colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,14 @@ const config = {

winston.addColors(config.colors);

const logger = module.exports = winston.createLogger({
const logger = (module.exports = winston.createLogger({
levels: config.levels,
format: winston.format.combine(
winston.format.colorize(),
winston.format.simple()
),
transports: [
new winston.transports.Console()
],
transports: [new winston.transports.Console()],
level: 'custom'
});
}));

logger.custom('hello')
logger.custom('hello');
4 changes: 1 addition & 3 deletions examples/custom-levels.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ const myCustomLevels = {
const customLevelLogger = winston.createLogger({
level: 'foobar',
levels: myCustomLevels.levels,
transports: [
new winston.transports.Console()
]
transports: [new winston.transports.Console()]
});

customLevelLogger.foobar('some foobar level-ed message');
Expand Down
15 changes: 8 additions & 7 deletions examples/custom-pretty-print.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ const logger = winston.createLogger({
return JSON.stringify(info)
.replace(/\{/g, '< wow ')
.replace(/\:/g, ' such ')
.replace(/\}/g, ' >')
.replace(/\}/g, ' >');
}),
transports: [
new winston.transports.Console(),
]
transports: [new winston.transports.Console()]
});

logger.info('Hello, this is a logging event with a custom pretty print', { 'foo': 'bar' });
logger.info('Hello, this is a logging event with a custom pretty print2', { 'foo': 'bar' });

logger.info('Hello, this is a logging event with a custom pretty print', {
foo: 'bar'
});
logger.info('Hello, this is a logging event with a custom pretty print2', {
foo: 'bar'
});
4 changes: 1 addition & 3 deletions examples/custom-timestamp.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ const logger = createLogger({
//
// format.printf(info => `${info.timestamp} ${info.level}: ${info.message}`)
),
transports: [
new transports.Console()
]
transports: [new transports.Console()]
});

logger.info('Hello there. How are you?');
7 changes: 3 additions & 4 deletions examples/custom-transport.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

const { createLogger } = require('../');
const Transport = require('winston-transport');

Expand Down Expand Up @@ -27,10 +26,10 @@ class CustomTransport extends Transport {

callback();
}
};
}

const transport = new CustomTransport();
transport.on('logged', (info) => {
transport.on('logged', info => {
// Verification that log was called on your transport
console.log(`Logging! It's happening!`, info);
});
Expand All @@ -40,4 +39,4 @@ const logger = createLogger({
transports: [transport]
});

logger.info('hello')
logger.info('hello');
14 changes: 4 additions & 10 deletions examples/delete-level.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,9 @@ const severityLevelOnly = format(info => {
});

const logger = createLogger({
format: combine(
severityLevelOnly(),
json()
),
transports: [
new transports.Console(),
]
format: combine(severityLevelOnly(), json()),
transports: [new transports.Console()]
});

logger.info('This will print without { level }', { 'foo': 'bar' });
logger.info('This will also print without { level }', { 'foo': 'bar' });

logger.info('This will print without { level }', { foo: 'bar' });
logger.info('This will also print without { level }', { foo: 'bar' });
9 changes: 2 additions & 7 deletions examples/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@ const { createLogger, format, transports } = require('../');
const { combine, errors, json } = format;

const logger = createLogger({
format: combine(
errors({ stack: true }),
json()
),
transports: [
new transports.Console(),
]
format: combine(errors({ stack: true }), json()),
transports: [new transports.Console()]
});

logger.warn(new Error('Error passed as info'));
Expand Down
4 changes: 1 addition & 3 deletions examples/exception.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ const winston = require('../');
//
const logger = winston.createLogger({
format: winston.format.simple(),
transports: [
new winston.transports.Console({ handleExceptions: true })
]
transports: [new winston.transports.Console({ handleExceptions: true })]
});

throw new Error('Hello, winston!');
8 changes: 3 additions & 5 deletions examples/finish-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ const winston = require('../');
// **AND** all data has been flushed (i.e. all your logs have been written).
//
const logger = winston.createLogger({
transports: [
new winston.transports.Console()
]
transports: [new winston.transports.Console()]
});

process.on('exit', function () {
Expand All @@ -22,7 +20,7 @@ logger.on('finish', function () {
console.log('Your logger is done logging');
});

logger.log('info', 'Hello, this is a raw logging event', { 'foo': 'bar' });
logger.log('info', 'Hello, this is a raw logging event 2', { 'foo': 'bar' });
logger.log('info', 'Hello, this is a raw logging event', { foo: 'bar' });
logger.log('info', 'Hello, this is a raw logging event 2', { foo: 'bar' });

logger.end();
4 changes: 2 additions & 2 deletions examples/format-dynamic-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const winston = require('../');

const logger = module.exports = winston.createLogger({
const logger = (module.exports = winston.createLogger({
transports: [new winston.transports.Console()],
format: winston.format.combine(
winston.format(function dynamicContent(info, opts) {
Expand All @@ -11,6 +11,6 @@ const logger = module.exports = winston.createLogger({
})(),
winston.format.simple()
)
});
}));

logger.log('info', 'This is an information message.');
9 changes: 4 additions & 5 deletions examples/format-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ const { createLogger, format, transports } = require('../');

// Ignore log messages if the have { private: true }
const ignorePrivate = format((info, opts) => {
if (info.private) { return false; }
if (info.private) {
return false;
}
return info;
});

const logger = createLogger({
format: format.combine(
ignorePrivate(),
format.json()
),
format: format.combine(ignorePrivate(), format.json()),
transports: [new transports.Console()]
});

Expand Down
7 changes: 2 additions & 5 deletions examples/format-logger-and-transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ const winston = require('../');
const { createLogger, format, transports } = winston;

const logger = createLogger({
format: format.combine(
format.timestamp(),
format.simple()
),
format: format.combine(format.timestamp(), format.simple()),
transports: [
new transports.Console({
format: format.combine(
Expand All @@ -19,7 +16,7 @@ const logger = createLogger({
stream: fs.createWriteStream('./example.log')
})
]
})
});

logger.log({
level: 'info',
Expand Down
4 changes: 1 addition & 3 deletions examples/format-mutate.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ const logger = winston.createLogger({
maskFormat(),
winston.format.json()
),
transports: [
new winston.transports.Console()
]
transports: [new winston.transports.Console()]
});

logger.info('transaction ok', { creditCard: 123456789012345 });
12 changes: 3 additions & 9 deletions examples/interpolation.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@

const { createLogger, format, transports } = require('../');
const logger = createLogger({
format: format.combine(
format.splat(),
format.simple()
),
transports: [
new transports.Console()
]
format: format.combine(format.splat(), format.simple()),
transports: [new transports.Console()]
});

// info: test message my string {}
Expand All @@ -25,6 +20,5 @@ logger.info('Found %s at %s', 'error', new Date());
logger.info('Found %s at %s', 'error', new Error('chill winston'));
logger.info('Found %s at %s', 'error', /WUT/);
logger.info('Found %s at %s', 'error', true);
logger.info('Found %s at %s', 'error', 100.00);
logger.info('Found %s at %s', 'error', 100.0);
logger.info('Found %s at %s', 'error', ['1, 2, 3']);

8 changes: 3 additions & 5 deletions examples/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ const winston = require('../');
// As of winston@3, the default logging format is JSON.
//
const logger = winston.createLogger({
transports: [
new winston.transports.Console(),
]
transports: [new winston.transports.Console()]
});

logger.log('info', 'Hello, this is a raw logging event', { 'foo': 'bar' });
logger.log('info', 'Hello, this is a raw logging event 2', { 'foo': 'bar' });
logger.log('info', 'Hello, this is a raw logging event', { foo: 'bar' });
logger.log('info', 'Hello, this is a raw logging event 2', { foo: 'bar' });
4 changes: 3 additions & 1 deletion examples/levels.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ const defaultLevels = winston.createLogger({

function logAllLevels() {
Object.keys(winston.config.npm.levels).forEach(level => {
defaultLevels[level](`is logged when logger.level="${defaultLevels.level}"`);
defaultLevels[level](
`is logged when logger.level="${defaultLevels.level}"`
);
});
}

Expand Down
4 changes: 1 addition & 3 deletions examples/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ const logger = winston.createLogger({
})(),
winston.format.json()
),
transports: [
new winston.transports.Console()
]
transports: [new winston.transports.Console()]
});

logger.info('my message', { reason: 'whatever', promise: 'whenever' });
13 changes: 6 additions & 7 deletions examples/quick-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ const logger = createLogger({
// with the colorized simple format.
//
if (process.env.NODE_ENV !== 'production') {
logger.add(new transports.Console({
format: format.combine(
format.colorize(),
format.simple()
)
}));
logger.add(
new transports.Console({
format: format.combine(format.colorize(), format.simple())
})
);
}

// ***************
Expand Down Expand Up @@ -83,7 +82,7 @@ logger.info('Found %s at %s', 'error', new Date());
logger.info('Found %s at %s', 'error', new Error('chill winston'));
logger.info('Found %s at %s', 'error', /WUT/);
logger.info('Found %s at %s', 'error', true);
logger.info('Found %s at %s', 'error', 100.00);
logger.info('Found %s at %s', 'error', 100.0);
logger.info('Found %s at %s', 'error', ['1, 2, 3']);

// ***************
Expand Down
4 changes: 1 addition & 3 deletions examples/simple-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ const filePath = path.join(__dirname, 'winston.log');
const stream = fs.createWriteStream(filePath);

const logger = winston.createLogger({
transports: [
new winston.transports.Stream({ stream })
]
transports: [new winston.transports.Stream({ stream })]
});

setTimeout(() => {
Expand Down
6 changes: 3 additions & 3 deletions examples/splat-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ const loggers = {
winston.format.splat(),
winston.format.simple()
),
transports: [new winston.transports.Console()],
transports: [new winston.transports.Console()]
}),
simple: winston.createLogger({
level: 'info',
format: winston.format.simple(),
transports: [new winston.transports.Console()],
transports: [new winston.transports.Console()]
})
};

const meta = {
subject: 'Hello, World!',
message: 'This message is a unique property separate from implicit merging.',
message: 'This message is a unique property separate from implicit merging.'
};

loggers.simple.info('email.message is hidden', meta);
Expand Down
Loading