semlog 0.6.9 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/test/test.spec.js CHANGED
@@ -1,15 +1,11 @@
1
1
  'use strict';
2
2
 
3
- /*global describe, it*/
4
-
5
- var semlog = require('../');
6
- var log = semlog.log;
7
- var expect = require('chai').expect;
8
-
9
- describe('semlog logger', function() {
10
-
11
- it('logs a string message to the console', function() {
3
+ const semlog = require('../');
4
+ const log = semlog.log;
5
+ const expect = require('chai').expect;
12
6
 
7
+ describe('semlog logger', function () {
8
+ it('logs a string message to the console', function () {
13
9
  console.log('');
14
10
  console.log('-------------------------------------------------------------');
15
11
  console.log(' Testing Log Messages');
@@ -40,13 +36,12 @@ describe('semlog logger', function() {
40
36
  log(null);
41
37
  log(Infinity);
42
38
 
43
-
44
39
  console.log('');
45
40
  console.log('-------------------------------------------------------------');
46
41
  console.log(' Testing Log Objects and Errors');
47
42
  console.log('-------------------------------------------------------------');
48
43
 
49
- // Create a new object, that prototypally inherits from the Error constructor.
44
+ // Create a new object, that prototypical inherits from the Error constructor.
50
45
  function MyError(message) {
51
46
  this.name = 'MyError';
52
47
  this.message = message || 'Default Message';
@@ -54,7 +49,7 @@ describe('semlog logger', function() {
54
49
  MyError.prototype = Object.create(Error.prototype);
55
50
  MyError.prototype.constructor = MyError;
56
51
 
57
- log({title: 'Object log entry', number: 10});
52
+ log({ title: 'Object log entry', number: 10 });
58
53
  log(new Error('error log entry'));
59
54
  log(new TypeError('error log entry'));
60
55
  log(new MyError('error log entry'));
@@ -63,132 +58,146 @@ describe('semlog logger', function() {
63
58
  console.log('');
64
59
  });
65
60
 
66
- it('prints objects as colorized YAML', function() {
67
- semlog.updateConfig({printYaml: true});
61
+ it('prints objects as colorized YAML', function () {
62
+ semlog.updateConfig({ printYaml: true });
68
63
  log({
69
64
  text: 'text',
70
65
  number: 42,
71
66
  array: [1, '2'],
72
67
  object: {
73
- key: 'value'
74
- }
68
+ key: 'value',
69
+ },
75
70
  });
76
- semlog.updateConfig({printYaml: false});
71
+ semlog.updateConfig({ printYaml: false });
77
72
  });
78
73
 
79
- it('prints errors', function() {
74
+ it('prints objects as YAML without color when colorize is false', function () {
75
+ semlog.updateConfig({ printYaml: true, colorize: false });
76
+ log({ key: 'value' });
77
+ semlog.updateConfig({ printYaml: false, colorize: true });
78
+ });
79
+
80
+ it('prints errors', function () {
80
81
  semlog.error(new Error('Test Error'));
81
82
  });
82
83
 
83
- it('handles various invalid log objects', function() {
84
+ it('handles various invalid log objects', function () {
84
85
  log(undefined);
85
86
  log(null);
86
87
  log(Error);
87
88
  log(Infinity);
88
89
  });
89
90
 
90
- it('returns the log history as an array', function() {
91
- var logArchive = semlog.getLogHistory();
91
+ it('suppresses verbose and debug messages when configured', function () {
92
+ semlog.updateConfig({ printVerbose: false, printDebug: false });
93
+ log('[V] suppressed verbose');
94
+ log('[D] suppressed debug');
95
+ semlog.updateConfig({ printVerbose: true, printDebug: true });
96
+ });
97
+
98
+ it('returns the log history as an array', function () {
99
+ const logArchive = semlog.getLogHistory();
92
100
 
93
101
  expect(logArchive).to.be.instanceof(Array);
94
102
  expect(logArchive.length).to.be.least(1);
95
103
  });
96
104
 
97
- it('clears global log object', function() {
105
+ it('clears global log object', function () {
98
106
  semlog.clearLogHistory();
99
- var logArchive = semlog.getLogHistory();
107
+ const logArchive = semlog.getLogHistory();
100
108
 
101
109
  expect(logArchive).to.be.instanceof(Array);
102
110
  expect(logArchive.length).to.equal(0);
103
111
  });
104
112
 
105
- it('logs silently', function() {
113
+ it('logs silently', function () {
106
114
  semlog.log(' [i] info log entry ', true);
107
115
  semlog.log(' [W] warning log entry', true);
108
116
  semlog.log(' [E] error log entry', true);
109
117
 
110
- var logArchive = semlog.getLogHistory();
118
+ const logArchive = semlog.getLogHistory();
111
119
 
112
120
  expect(logArchive).to.be.instanceof(Array);
113
121
  expect(logArchive.length).to.equal(3);
114
122
  });
115
123
 
116
- it('gets config', function() {
117
- var config = semlog.getConfig();
124
+ it('gets config', function () {
125
+ const config = semlog.getConfig();
118
126
 
119
127
  expect(config).to.be.instanceof(Object);
120
128
  expect(Object.keys(config).length).to.be.least(3);
121
129
  });
122
130
 
123
- it('updates the config', function() {
124
-
125
- var config = semlog.getConfig();
126
- var newConfig = semlog.updateConfig({printTime: false});
131
+ it('updates the config', function () {
132
+ const config = semlog.getConfig();
133
+ const newConfig = semlog.updateConfig({ printTime: false });
127
134
 
128
135
  expect(newConfig).to.be.instanceof(Object);
129
136
  expect(newConfig.printTime).to.equal(false);
130
137
  expect(newConfig.historySize).to.equal(config.historySize);
131
138
  });
132
139
 
133
- it('keeps the log object at a specific size', function() {
140
+ it('keeps the log object at a specific size', function () {
141
+ const historySize = 7;
142
+ const newConfig = semlog.updateConfig({ historySize: historySize, logDateTime: true });
134
143
 
135
- var historySize = 7;
136
- var newConfig = semlog.updateConfig({historySize: historySize, logDateTime: true});
137
-
138
- for (var i = 0; i < 32; i++) {
144
+ for (let i = 0; i < 32; i++) {
139
145
  log('[i] Index added: ' + i, true);
140
146
  }
141
147
 
142
- var logHistory = semlog.getLogHistory();
148
+ const logHistory = semlog.getLogHistory();
143
149
  expect(newConfig.historySize).to.equal(logHistory.length);
144
150
  expect(logHistory.length).to.equal(historySize);
145
151
  });
146
152
 
147
- it('returns the log archive as non circular array', function() {
153
+ it('handles circular objects in history gracefully', function () {
154
+ const circular = {};
155
+ circular.self = circular;
156
+ semlog.addToHistory(circular);
157
+ const history = semlog.getLogHistory();
158
+ expect(history[history.length - 1]).to.include('[W]');
159
+ });
148
160
 
161
+ it('returns the log archive as non circular array', function () {
149
162
  log(semlog.getLogHistory());
150
- var logHistory = semlog.getLogHistory();
163
+ const logHistory = semlog.getLogHistory();
151
164
 
152
165
  expect(JSON.stringify(logHistory)).to.be.a('string');
153
-
154
166
  });
155
167
 
156
- it('returns log statistics', function() {
157
-
168
+ it('returns log statistics', function () {
158
169
  log(semlog.getStatistics());
159
- var statistics = semlog.getStatistics();
170
+ const statistics = semlog.getStatistics();
160
171
 
161
172
  expect(statistics.total).to.be.a('number');
162
-
163
173
  });
164
-
165
174
  });
166
175
 
167
- describe('semlog utilities', function() {
168
-
169
- it('pad numbers', function() {
176
+ describe('semlog utilities', function () {
177
+ it('pad numbers', function () {
170
178
  expect(semlog.pad(7, 1)).to.equal('7');
171
179
  expect(semlog.pad(7, 2)).to.equal('07');
172
180
  expect(semlog.pad(7, 3)).to.equal('007');
173
181
  });
174
182
 
175
- it('pretty prints numbers', function() {
183
+ it('pretty prints numbers', function () {
176
184
  expect(semlog.prettyNumber(1)).to.equal('1');
177
185
  expect(semlog.prettyNumber(100000)).to.equal('100.000');
178
186
  expect(semlog.prettyNumber(-100000)).to.equal('-100.000');
179
187
  });
180
188
 
181
- it('pretty prints bytes', function() {
189
+ it('pretty prints bytes', function () {
190
+ expect(semlog.prettyBytes(500)).to.equal('500 B');
182
191
  expect(semlog.prettyBytes(1024)).to.be.a('string');
183
192
  expect(semlog.prettyBytes(1024)).to.equal('1.0 KiB');
184
193
  expect(semlog.prettyBytes(1024, true)).to.equal('1.0 kB');
185
194
  });
186
195
 
187
- it('strips trailing slashes from URLs', function() {
196
+ it('strips trailing slashes from URLs', function () {
188
197
  expect(semlog.stripTrailingSlash('http://fannon.de/')).to.equal('http://fannon.de');
189
198
  });
190
199
 
191
- it('strips leading and ending slashes from URLs / URL paths', function() {
200
+ it('strips leading and ending slashes from URLs / URL paths', function () {
192
201
  expect(semlog.cleanUrl('http://fannon.de/')).to.equal('http://fannon.de');
193
202
  expect(semlog.cleanUrl('http://fannon.de ')).to.equal('http://fannon.de');
194
203
  expect(semlog.cleanUrl('/test/')).to.equal('test');
@@ -196,40 +205,44 @@ describe('semlog utilities', function() {
196
205
  expect(semlog.cleanUrl(' test/ ')).to.equal('test');
197
206
  });
198
207
 
199
- it('creates date arrays', function() {
208
+ it('creates date arrays', function () {
200
209
  expect(semlog.getDateArray().length).to.equal(7);
201
210
  expect(semlog.getDateArray()[0]).to.equal(new Date().getFullYear());
202
211
  });
203
212
 
204
- it('return human readable date-times', function() {
213
+ it('return human readable date-times', function () {
205
214
  expect(semlog.humanDate().length).to.equal(19);
206
215
  expect(semlog.humanDate(new Date('October 13, 2014 11:13:00'))).to.equal('2014-10-13 11:13:00');
207
216
  });
208
217
 
209
- it('return machine optimized date-times', function() {
218
+ it('return machine optimized date-times', function () {
210
219
  expect(semlog.roboDate().length).to.equal(19);
211
220
  expect(semlog.roboDate(new Date('October 13, 2014 11:13:00'))).to.equal('2014-10-13_11-13-00');
212
221
  });
213
222
 
214
- it('return human readable time', function() {
223
+ it('return human readable time', function () {
215
224
  expect(semlog.humanTime().length).to.equal(8);
216
225
  expect(semlog.humanTime(new Date('October 13, 2014 11:13:00'))).to.equal('11:13:00');
217
226
  });
218
227
 
219
- it('return machine optimized time', function() {
228
+ it('return machine optimized time', function () {
220
229
  expect(semlog.roboTime().length).to.equal(8);
221
230
  expect(semlog.roboTime(new Date('October 13, 2014 11:13:00'))).to.equal('11-13-00');
222
231
  });
223
232
 
224
- it('calculates the bytesize of strings', function() {
233
+ it('calculates the bytesize of strings', function () {
225
234
  expect(semlog.byteSize('internationalization')).to.be.a('number');
226
235
  expect(semlog.byteSize('internationalization')).to.equal(20);
227
236
  });
228
237
 
229
- it('calculates the bytesize of objects (parsed to JSON)', function() {
230
- expect(semlog.byteSize({title: 'internationalization'})).to.be.a('number');
231
- expect(semlog.byteSize({title: 'internationalization'})).to.equal(32);
238
+ it('calculates the bytesize of objects (parsed to JSON)', function () {
239
+ expect(semlog.byteSize({ title: 'internationalization' })).to.be.a('number');
240
+ expect(semlog.byteSize({ title: 'internationalization' })).to.equal(32);
232
241
  });
233
242
 
234
-
243
+ it('calculates the bytesize of multibyte strings', function () {
244
+ expect(semlog.byteSize('\u00F1')).to.equal(2); // 2-byte UTF-8 (ñ)
245
+ expect(semlog.byteSize('\u20AC')).to.equal(3); // 3-byte UTF-8 (€)
246
+ expect(semlog.byteSize('\uD840\uDC00')).to.equal(4); // 4-byte UTF-8 surrogate pair (𠀀)
247
+ });
235
248
  });
package/.eslintrc DELETED
@@ -1,20 +0,0 @@
1
- extends: 'eslint:recommended'
2
-
3
- rules:
4
- indent:
5
- - 2
6
- - 4
7
- quotes:
8
- - 2
9
- - single
10
- semi:
11
- - 2
12
- - always
13
- no-unused-vars:
14
- - 1
15
- no-console:
16
- - 0
17
-
18
- env:
19
- es6: true
20
- node: true
package/.jscsrc DELETED
@@ -1,61 +0,0 @@
1
- {
2
- "disallowSpacesInNamedFunctionExpression": {
3
- "beforeOpeningRoundBrace": true
4
- },
5
- "disallowSpacesInFunctionExpression": {
6
- "beforeOpeningRoundBrace": true
7
- },
8
- "disallowSpacesInAnonymousFunctionExpression": {
9
- "beforeOpeningRoundBrace": true
10
- },
11
- "disallowSpacesInFunctionDeclaration": {
12
- "beforeOpeningRoundBrace": true
13
- },
14
- "disallowEmptyBlocks": true,
15
- "disallowSpacesInsideArrayBrackets": true,
16
- "disallowSpacesInsideParentheses": true,
17
- "disallowSpaceAfterObjectKeys": true,
18
- "disallowSpaceAfterPrefixUnaryOperators": true,
19
- "disallowSpaceBeforePostfixUnaryOperators": true,
20
- "disallowSpaceBeforeBinaryOperators": [
21
- ","
22
- ],
23
- "disallowMixedSpacesAndTabs": true,
24
- "disallowTrailingWhitespace": "ignoreEmptyLines",
25
- "disallowTrailingComma": true,
26
- "disallowYodaConditions": true,
27
- "disallowKeywords": [ "with" ],
28
- "disallowMultipleVarDecl": true,
29
- "requireSpaceBeforeBlockStatements": true,
30
- "requireParenthesesAroundIIFE": true,
31
- "requireSpacesInConditionalExpression": true,
32
- "requireBlocksOnNewline": 1,
33
- "requireCommaBeforeLineBreak": true,
34
- "requireSpaceBeforeBinaryOperators": true,
35
- "requireSpaceAfterBinaryOperators": true,
36
- "requireLineFeedAtFileEnd": true,
37
- "requireCapitalizedConstructors": true,
38
- "requireDotNotation": true,
39
- "requireSpacesInForStatement": true,
40
- "requireSpaceBetweenArguments": true,
41
- "requireCurlyBraces": [
42
- "do"
43
- ],
44
- "requireSpaceAfterKeywords": [
45
- "if",
46
- "else",
47
- "for",
48
- "while",
49
- "do",
50
- "switch",
51
- "case",
52
- "return",
53
- "try",
54
- "catch",
55
- "typeof"
56
- ],
57
- "safeContextKeyword": "_this",
58
- "validateLineBreaks": "LF",
59
- "validateQuoteMarks": "'",
60
- "validateIndentation": 4
61
- }
package/.npmignore DELETED
@@ -1,4 +0,0 @@
1
- .idea/
2
- /node_modules/
3
- /coverage/
4
- npm-debug.log
package/.travis.yml DELETED
@@ -1,22 +0,0 @@
1
- language: node_js
2
- node_js:
3
- - '0.10'
4
- - '0.12'
5
- - '4.2'
6
- - '5.1'
7
-
8
- sudo: false
9
-
10
- addons:
11
- code_climate:
12
- repo_token: d025e5a435157e5cf3b9573054d1c2777cc6c8eb2d4d6abb6a0c976e9c4b75f6
13
-
14
- notifications:
15
- email:
16
- on_success: [never] # default: change
17
- on_failure: [always] # default: always
18
- recipients:
19
- - info@fannon.de
20
-
21
- after_script:
22
- - cat coverage/lcov.info | codeclimate
package/.yo-rc.json DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "generator-node": {}
3
- }
package/Gruntfile.js DELETED
@@ -1,102 +0,0 @@
1
- 'use strict';
2
- module.exports = function(grunt) {
3
-
4
- // Show elapsed time at the end
5
- require('time-grunt')(grunt);
6
-
7
- // Load all grunt tasks
8
- require('load-grunt-tasks')(grunt);
9
-
10
- grunt.initConfig({
11
- eslint: {
12
- options: {
13
- configFile: '.eslintrc'
14
- },
15
- js: {
16
- src: ['*.js']
17
- },
18
- test: {
19
- src: ['test/**/*.js']
20
- }
21
- },
22
- jscs: {
23
- options: {
24
- config: '.jscsrc',
25
- force: true
26
- },
27
- lib: {
28
- src: ['lib/**/*.js']
29
- },
30
- test: {
31
- src: ['test/**/*.js']
32
- }
33
- },
34
- mochacli: {
35
- options: {
36
- reporter: 'spec',
37
- bail: true,
38
- force: true,
39
- timeout: 16000
40
- },
41
- all: ['test/**/*.spec.js']
42
- },
43
- mocha_istanbul: {
44
- coverage: {
45
- src: ['test/'],
46
- options: {
47
- mask: '*.spec.js',
48
- coverage: true,
49
- reportFormats: ['lcov', 'text']
50
- }
51
- }
52
- },
53
- watch: {
54
- gruntfile: {
55
- files: '<%= jshint.gruntfile.src %>',
56
- tasks: ['jshint:gruntfile']
57
- },
58
- js: {
59
- files: '<%= jshint.js.src %>',
60
- tasks: ['lint', 'test']
61
- },
62
- test: {
63
- files: '<%= jshint.test.src %>',
64
- tasks: ['lint', 'test']
65
- }
66
- },
67
- documentation: {
68
- md: {
69
- files: [{
70
- 'src': ['index.js']
71
- }],
72
- options: {
73
- format: 'md',
74
- destination: 'doc'
75
- }
76
- },
77
- html: {
78
- files: [{
79
- 'src': ['index.js']
80
- }],
81
- options: {
82
- destination: 'doc'
83
- }
84
- }
85
- },
86
- release: {
87
- options: {
88
-
89
- }
90
- }
91
- });
92
-
93
- // Default task.
94
- grunt.registerTask('lint', ['eslint', 'jscs']);
95
- grunt.registerTask('test', ['mochacli']);
96
- grunt.registerTask('coverage', ['mocha_istanbul:coverage']);
97
- grunt.registerTask('default', ['lint', 'coverage', 'documentation']);
98
-
99
- grunt.event.on('coverage', function(content, done) {
100
- done();
101
- });
102
- };
File without changes