-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(configure): add ability to configure formatter and output
- Loading branch information
esysuser
committed
Nov 29, 2017
1 parent
feb7083
commit baf8e42
Showing
11 changed files
with
3,532 additions
and
2,707 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
const ColorName = require('../output/color-name/color-name'); | ||
const stringifyLevel = require('../output/stringify-level/stringify-level'); | ||
const formatTime = require('../output/format-time/format-time'); | ||
const formatBody = require('../output/format-body/format-body'); | ||
|
||
module.exports = function(log) { | ||
return [ | ||
ColorName.addColor(log.name), | ||
stringifyLevel(log.level), | ||
formatTime.elapsedTime(log.time), | ||
formatBody(log) | ||
].join(' '); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict'; | ||
|
||
const debug = require('./debug'); | ||
const ColorName = require('../output/color-name/color-name'); | ||
|
||
describe('debug formatter', function() { | ||
afterEach(function () { | ||
ColorName.reset(); | ||
}); | ||
|
||
it('should format line', function() { | ||
const logLine = { level: 10, time: new Date().toISOString(), name: 'redis', random: 15 }; | ||
|
||
expect(debug(logLine)).to.eql('\u001b[36mredis\u001b[39m TRACE +0ms random=15'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
const jsonFormatter = require('./json'); | ||
const debugFormatter = require('./debug'); | ||
|
||
module.exports = { | ||
json: jsonFormatter, | ||
debug: debugFormatter | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
module.exports = function(log) { | ||
return JSON.stringify(log); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,27 @@ | ||
'use strict'; | ||
|
||
const chalk = require('chalk'); | ||
|
||
const colors = ['cyan', 'magenta', 'grey', 'blue', 'green', 'yellow', 'white', 'red']; | ||
const names = {}; | ||
let colorCounter = 0; | ||
|
||
module.exports = function colorName(name) { | ||
if (!names[name]) { | ||
names[name] = { color: colorCounter % colors.length }; | ||
colorCounter++; | ||
class ColorName { | ||
static addColor(name) { | ||
if (!this.names[name]) { | ||
this.names[name] = { color: this.counter % colors.length }; | ||
this.counter++; | ||
} | ||
|
||
const color = colors[this.names[name].color]; | ||
return chalk[color](name); | ||
} | ||
|
||
static reset() { | ||
this.counter = 0; | ||
this.names = {}; | ||
} | ||
} | ||
|
||
const color = colors[names[name].color]; | ||
return chalk[color](name); | ||
}; | ||
ColorName.counter = 0; | ||
ColorName.names = {}; | ||
ColorName.colors = colors; | ||
|
||
module.exports.colors = colors; | ||
module.exports = ColorName; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
module.exports = function(formattedLog) { | ||
console.log(formattedLog); | ||
}; |