added all files to project

This commit is contained in:
2022-03-10 10:36:59 +01:00
parent 09dd957b33
commit 46a936d7de
25351 changed files with 3883356 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
language: node_js
node_js:
- "node"
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 Evgeniy Pavlov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+218
View File
@@ -0,0 +1,218 @@
# loglevel-plugin-prefix
Plugin for [loglevel](https://github.com/pimterry/loglevel) message prefixing.
[![NPM version](https://img.shields.io/npm/v/loglevel-plugin-prefix.svg?style=flat-square)](https://www.npmjs.com/package/loglevel-plugin-prefix)[![Build Status](https://img.shields.io/travis/kutuluk/loglevel-plugin-prefix/master.svg?style=flat-square)](https://travis-ci.org/kutuluk/loglevel-plugin-prefix)
## Installation
```sh
npm install loglevel-plugin-prefix
```
## API
**This plugin is under active development and should be considered as an unstable. No guarantees regarding API stability are made. Backward compatibility is guaranteed only by path releases.**
#### `reg(loglevel)`
This method registers plugin for loglevel. This method must be called at least once before any call to the apply method. Repeated calls to this method are ignored.
#### Parameters
`loglevel` - the root logger, imported from loglevel module
#### `apply(logger, options)`
This method applies the plugin to the logger. Before using this method, the `reg` method must be called, otherwise a warning will be logged. **From the next release, the call apply before reg will throw an error.**
#### Parameters
`logger` - any logger of loglevel
`options` - an optional configuration object
```javascript
var defaults = {
template: '[%t] %l:',
levelFormatter: function (level) {
return level.toUpperCase();
},
nameFormatter: function (name) {
return name || 'root';
},
timestampFormatter: function (date) {
return date.toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, '$1');
},
format: undefined
};
```
Plugin formats the prefix using `template` option as a printf-like format. The `template` is a string containing zero or more placeholder tokens. Each placeholder token is replaced with the value from loglevel messages parameters. Supported placeholders are:
- `%l` - level of message
- `%n` - name of logger
- `%t` - timestamp of message
The `levelFormatter`, `nameFormatter` and `timestampFormatter` is a functions for formatting corresponding values.
Alternatively, you can use `format` option. This is a function that receives formatted values (level, name, timestamp) and should returns a prefix string.
If both `format` and` template` are present in the configuration, the `template` parameter is ignored. When both these parameters are missing in the configuration, the inherited behavior is used.
## Usage
### Browser directly
```html
<script src="https://unpkg.com/loglevel/dist/loglevel.min.js"></script>
<script src="https://unpkg.com/loglevel-plugin-prefix@^0.8/dist/loglevel-plugin-prefix.min.js"></script>
<script>
var logger = log.noConflict();
var prefixer = prefix.noConflict();
prefixer.reg(logger);
prefixer.apply(logger);
logger.warn('prefixed message');
</script>
```
Output
```
[16:53:46] WARN: prefixed message
```
### Node
```javascript
const chalk = require('chalk');
const log = require('loglevel');
const prefix = require('loglevel-plugin-prefix');
const colors = {
TRACE: chalk.magenta,
DEBUG: chalk.cyan,
INFO: chalk.blue,
WARN: chalk.yellow,
ERROR: chalk.red,
};
prefix.reg(log);
log.enableAll();
prefix.apply(log, {
format(level, name, timestamp) {
return `${chalk.gray(`[${timestamp}]`)} ${colors[level.toUpperCase()](level)} ${chalk.green(`${name}:`)}`;
},
});
prefix.apply(log.getLogger('critical'), {
format(level, name, timestamp) {
return chalk.red.bold(`[${timestamp}] ${level} ${name}:`);
},
});
log.trace('trace');
log.debug('debug');
log.getLogger('critical').info('Something significant happened');
log.log('log');
log.info('info');
log.warn('warn');
log.error('error');
```
Output
![output](https://raw.githubusercontent.com/kutuluk/loglevel-plugin-prefix/master/colored.png "output")
## Custom options
```javascript
const log = require('loglevel');
const prefix = require('loglevel-plugin-prefix');
prefix.reg(log);
log.enableAll();
prefix.apply(log, {
template: '[%t] %l (%n) static text:',
levelFormatter(level) {
return level.toUpperCase();
},
nameFormatter(name) {
return name || 'global';
},
timestampFormatter(date) {
return date.toISOString();
},
});
log.info('%s prefix', 'template');
const fn = (level, name, timestamp) => `[${timestamp}] ${level} (${name}) static text:`;
prefix.apply(log, { format: fn });
log.info('%s prefix', 'functional');
prefix.apply(log, { template: '[%t] %l (%n) static text:' });
log.info('again %s prefix', 'template');
```
Output
```
[2017-05-29T12:53:46.000Z] INFO (global) static text: template prefix
[2017-05-29T12:53:46.000Z] INFO (global) static text: functional prefix
[2017-05-29T12:53:46.000Z] INFO (global) static text: again template prefix
```
## Option inheritance
```javascript
const log = require('loglevel');
const prefix = require('loglevel-plugin-prefix');
prefix.reg(log);
log.enableAll();
log.info('root');
const chicken = log.getLogger('chicken');
chicken.info('chicken');
prefix.apply(chicken, { template: '%l (%n):' });
chicken.info('chicken');
prefix.apply(log);
log.info('root');
const egg = log.getLogger('egg');
egg.info('egg');
const fn = (level, name) => `${level} (${name}):`;
prefix.apply(egg, { format: fn });
egg.info('egg');
prefix.apply(egg, {
levelFormatter(level) {
return level.toLowerCase();
},
});
egg.info('egg');
chicken.info('chicken');
log.info('root');
```
Output
```
root
chicken
INFO (chicken): chicken
[16:53:46] INFO: root
[16:53:46] INFO: egg
INFO (egg): egg
info (egg): egg
INFO (chicken): chicken
[16:53:46] INFO: root
```
Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

@@ -0,0 +1 @@
!function(e,t){"function"==typeof define&&define.amd?define(t):"object"==typeof module&&module.exports?module.exports=t():e.prefix=t(e)}(this,function(e){"use strict";var n,t,a={template:"[%t] %l:",levelFormatter:function(e){return e.toUpperCase()},nameFormatter:function(e){return e||"root"},timestampFormatter:function(e){return e.toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/,"$1")},format:void 0},d={},r={reg:function(e){if(!e||!e.getLogger)throw new TypeError("Argument is not a root logger");n=e},apply:function(e,t){if(!e||!e.setLevel)throw new TypeError("Argument is not a logger");var r=e.methodFactory,s=e.name||"",o=d[s]||d[""]||a;return d[s]||(e.methodFactory=function(i,e,f){var p=r(i,e,f),m=d[f]||d[""],u=-1!==m.template.indexOf("%t"),c=-1!==m.template.indexOf("%l"),g=-1!==m.template.indexOf("%n");return function(){for(var e="",t=arguments.length,r=Array(t),o=0;o<t;o++)r[o]=arguments[o];if(s||!d[f]){var n=m.timestampFormatter(new Date),a=m.levelFormatter(i),l=m.nameFormatter(f);m.format?e+=m.format(a,l,n):(e+=m.template,u&&(e=e.replace(/%t/,n)),c&&(e=e.replace(/%l/,a)),g&&(e=e.replace(/%n/,l))),r.length&&"string"==typeof r[0]?r[0]=e+" "+r[0]:r.unshift(e)}p.apply(void 0,r)}}),(t=t||{}).template&&(t.format=void 0),d[s]=function(e){for(var t,r=1,o=arguments.length;r<o;r++)for(t in arguments[r])Object.prototype.hasOwnProperty.call(arguments[r],t)&&(e[t]=arguments[r][t]);return e}({},o,t),e.setLevel(e.getLevel()),n||e.warn("It is necessary to call the function reg() of loglevel-plugin-prefix before calling apply. From the next release, it will throw an error. See more: https://github.com/kutuluk/loglevel-plugin-prefix/blob/master/README.md"),e}};return e&&(t=e.prefix,r.noConflict=function(){return e.prefix===r&&(e.prefix=t),r}),r});
+7
View File
@@ -0,0 +1,7 @@
{
"extends": "airbnb-base",
"env": {
"es6": true
},
"rules": {}
}
+35
View File
@@ -0,0 +1,35 @@
// eslint-disable-next-line import/no-extraneous-dependencies
const log = require('loglevel');
const prefix = require('../lib/loglevel-plugin-prefix');
prefix.reg(log);
log.enableAll();
log.info('root');
const chicken = log.getLogger('chicken');
chicken.info('chicken');
prefix.apply(chicken, { template: '%l (%n):' });
chicken.info('chicken');
prefix.apply(log);
log.info('root');
const egg = log.getLogger('egg');
egg.info('egg');
const fn = (level, name) => `${level} (${name}):`;
prefix.apply(egg, { format: fn });
egg.info('egg');
prefix.apply(egg, {
levelFormatter(level) {
return level.toLowerCase();
},
});
egg.info('egg');
chicken.info('chicken');
log.info('root');
+36
View File
@@ -0,0 +1,36 @@
// eslint-disable-next-line import/no-extraneous-dependencies
const log = require('loglevel');
// eslint-disable-next-line import/no-extraneous-dependencies
const chalk = require('chalk');
const prefix = require('../lib/loglevel-plugin-prefix');
const colors = {
TRACE: chalk.magenta,
DEBUG: chalk.cyan,
INFO: chalk.blue,
WARN: chalk.yellow,
ERROR: chalk.red,
};
prefix.reg(log);
log.enableAll();
prefix.apply(log, {
format(level, name, timestamp) {
return `${chalk.gray(`[${timestamp}]`)} ${colors[level.toUpperCase()](level)} ${chalk.green(`${name}:`)}`;
},
});
prefix.apply(log.getLogger('critical'), {
format(level, name, timestamp) {
return chalk.red.bold(`[${timestamp}] ${level} ${name}:`);
},
});
log.trace('trace');
log.debug('debug');
log.getLogger('critical').info('Something significant happened');
log.log('log');
log.info('info');
log.warn('warn');
log.error('error');
+31
View File
@@ -0,0 +1,31 @@
// eslint-disable-next-line import/no-extraneous-dependencies
const log = require('loglevel');
const prefix = require('../lib/loglevel-plugin-prefix');
prefix.reg(log);
log.enableAll();
prefix.apply(log, {
template: '[%t] %l (%n) static text:',
timestampFormatter(date) {
return date.toISOString();
},
levelFormatter(level) {
return level.toUpperCase();
},
nameFormatter(name) {
return name || 'global';
},
});
log.info('%s prefix', 'template');
const fn = (level, name, timestamp) => `[${timestamp}] ${level} (${name}) static text:`;
prefix.apply(log, { format: fn });
log.info('%s prefix', 'functional');
prefix.apply(log, { template: '[%t] %l (%n) static text:' });
log.info('again %s prefix', 'template');
+14
View File
@@ -0,0 +1,14 @@
declare module 'loglevel-plugin-prefix' {
import { Logger } from 'loglevel';
interface LoglevelPluginPrefixOptions {
template?: string;
levelFormatter?: (level: string) => string;
nameFormatter?: (name: string | undefined) => string;
timestampFormatter?: (date: Date) => string;
format?: (level: string, name: string | undefined, timestamp: Date) => string | undefined;
}
function reg(loglevel: Logger): void;
function apply(logger: Logger, options?: LoglevelPluginPrefixOptions): Logger;
}
+15
View File
@@ -0,0 +1,15 @@
{
"extends": "airbnb-base/legacy",
"env": {
"browser": true,
"amd": true,
"es6": false
},
"rules": {
"no-param-reassign": "off",
"prefer-rest-params": "off",
"no-restricted-syntax": "off",
"no-plusplus": "off",
"func-names": "off"
}
}
+149
View File
@@ -0,0 +1,149 @@
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define(factory);
} else if (typeof module === 'object' && module.exports) {
module.exports = factory();
} else {
root.prefix = factory(root);
}
}(this, function (root) {
'use strict';
var merge = function (target) {
var i = 1;
var length = arguments.length;
var key;
for (; i < length; i++) {
for (key in arguments[i]) {
if (Object.prototype.hasOwnProperty.call(arguments[i], key)) {
target[key] = arguments[i][key];
}
}
}
return target;
};
var defaults = {
template: '[%t] %l:',
levelFormatter: function (level) {
return level.toUpperCase();
},
nameFormatter: function (name) {
return name || 'root';
},
timestampFormatter: function (date) {
return date.toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, '$1');
},
format: undefined
};
var loglevel;
var configs = {};
var reg = function (rootLogger) {
if (!rootLogger || !rootLogger.getLogger) {
throw new TypeError('Argument is not a root logger');
}
loglevel = rootLogger;
};
var apply = function (logger, config) {
if (!logger || !logger.setLevel) {
throw new TypeError('Argument is not a logger');
}
/* eslint-disable vars-on-top */
var originalFactory = logger.methodFactory;
var name = logger.name || '';
var parent = configs[name] || configs[''] || defaults;
/* eslint-enable vars-on-top */
function methodFactory(methodName, logLevel, loggerName) {
var originalMethod = originalFactory(methodName, logLevel, loggerName);
var options = configs[loggerName] || configs[''];
var hasTimestamp = options.template.indexOf('%t') !== -1;
var hasLevel = options.template.indexOf('%l') !== -1;
var hasName = options.template.indexOf('%n') !== -1;
return function () {
var content = '';
var length = arguments.length;
var args = Array(length);
var key = 0;
for (; key < length; key++) {
args[key] = arguments[key];
}
// skip the root method for child loggers to prevent duplicate logic
if (name || !configs[loggerName]) {
/* eslint-disable vars-on-top */
var timestamp = options.timestampFormatter(new Date());
var level = options.levelFormatter(methodName);
var lname = options.nameFormatter(loggerName);
/* eslint-enable vars-on-top */
if (options.format) {
content += options.format(level, lname, timestamp);
} else {
content += options.template;
if (hasTimestamp) {
content = content.replace(/%t/, timestamp);
}
if (hasLevel) content = content.replace(/%l/, level);
if (hasName) content = content.replace(/%n/, lname);
}
if (args.length && typeof args[0] === 'string') {
// concat prefix with first argument to support string substitutions
args[0] = content + ' ' + args[0];
} else {
args.unshift(content);
}
}
originalMethod.apply(undefined, args);
};
}
if (!configs[name]) {
logger.methodFactory = methodFactory;
}
// for remove inherited format option if template option preset
config = config || {};
if (config.template) config.format = undefined;
configs[name] = merge({}, parent, config);
logger.setLevel(logger.getLevel());
if (!loglevel) {
logger.warn(
'It is necessary to call the function reg() of loglevel-plugin-prefix before calling apply. From the next release, it will throw an error. See more: https://github.com/kutuluk/loglevel-plugin-prefix/blob/master/README.md'
);
}
return logger;
};
var api = {
reg: reg,
apply: apply
};
var save;
if (root) {
save = root.prefix;
api.noConflict = function () {
if (root.prefix === api) {
root.prefix = save;
}
return api;
};
}
return api;
}));
+79
View File
@@ -0,0 +1,79 @@
{
"_args": [
[
"loglevel-plugin-prefix@0.8.4",
"/home/pi/Desktop/smartMirrorTestEnvironment/MagicMirror"
]
],
"_development": true,
"_from": "loglevel-plugin-prefix@0.8.4",
"_id": "loglevel-plugin-prefix@0.8.4",
"_inBundle": false,
"_integrity": "sha512-WpG9CcFAOjz/FtNht+QJeGpvVl/cdR6P0z6OcXSkr8wFJOsV2GRj2j10JLfjuA4aYkcKCNIEqRGCyTife9R8/g==",
"_location": "/loglevel-plugin-prefix",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "loglevel-plugin-prefix@0.8.4",
"name": "loglevel-plugin-prefix",
"escapedName": "loglevel-plugin-prefix",
"rawSpec": "0.8.4",
"saveSpec": null,
"fetchSpec": "0.8.4"
},
"_requiredBy": [
"/@wdio/logger"
],
"_resolved": "https://registry.npmjs.org/loglevel-plugin-prefix/-/loglevel-plugin-prefix-0.8.4.tgz",
"_spec": "0.8.4",
"_where": "/home/pi/Desktop/smartMirrorTestEnvironment/MagicMirror",
"author": {
"name": "kutuluk"
},
"bugs": {
"url": "https://github.com/kutuluk/loglevel-plugin-prefix/issues"
},
"description": "Plugin for loglevel message prefixing",
"devDependencies": {
"chai": "^4.1.2",
"chalk": "^2.4.1",
"eslint": "^3.19.0",
"eslint-config-airbnb-base": "^11.3.2",
"eslint-plugin-chai-friendly": "^0.3.6",
"eslint-plugin-import": "^2.12.0",
"loglevel": "^1.6.1",
"loglevel-plugin-mock": "^0.1.0",
"mocha": "^3.5.3",
"sinon": "^2.4.1",
"uglify-js": "^3.4.0"
},
"homepage": "https://github.com/kutuluk/loglevel-plugin-prefix",
"keywords": [
"log",
"logger",
"logging",
"browser",
"node",
"prefix",
"colored",
"loglevel",
"plugin"
],
"license": "MIT",
"main": "./lib/loglevel-plugin-prefix",
"name": "loglevel-plugin-prefix",
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/kutuluk/loglevel-plugin-prefix.git"
},
"scripts": {
"build": "npm install && npm run eslint && npm run test && npm run uglifyjs",
"eslint": "eslint ./lib/loglevel-plugin-prefix.js",
"example": "node ./example/example.js",
"test": "mocha",
"uglifyjs": "uglifyjs ./lib/loglevel-plugin-prefix.js -o ./dist/loglevel-plugin-prefix.min.js -c -m"
},
"types": "index.d.ts",
"version": "0.8.4"
}
+15
View File
@@ -0,0 +1,15 @@
{
"extends": "airbnb-base",
"plugins": [
"chai-friendly"
],
"env": {
"mocha": true,
"es6": true
},
"rules": {
"no-unused-expressions": "off",
"chai-friendly/no-unused-expressions": 2,
"comma-dangle": "off"
}
}
+108
View File
@@ -0,0 +1,108 @@
const expect = require('chai').expect;
const loglevel = require('loglevel');
const other = require('loglevel-plugin-mock');
const sinon = require('sinon');
const prefix = require('../lib/loglevel-plugin-prefix');
const spy = sinon.spy();
loglevel.enableAll();
describe('API', () => {
it('Methods', () => {
expect(prefix).to.have.property('apply').with.be.a('function');
expect(prefix).to.have.property('reg').with.be.a('function');
expect(prefix).not.to.have.property('noConflict');
});
it('Reg: empty arguments', () => {
expect(prefix.reg).to.throw(TypeError, 'Argument is not a root logger');
});
it('Reg: incorrect argument', () => {
expect(() => prefix.reg('logger')).to.throw(TypeError, 'Argument is not a root logger');
});
it('Apply: empty arguments', () => {
expect(prefix.apply).to.throw(TypeError, 'Argument is not a logger');
});
it('Apply: incorrect argument', () => {
expect(() => prefix.apply('logger')).to.throw(TypeError, 'Argument is not a logger');
});
});
describe('Prefix', () => {
other.apply(loglevel, { method: spy });
beforeEach(() => {
spy.reset();
});
it('Root applying', () => {
expect(() => prefix.apply(loglevel)).to.not.throw();
});
it('Root reapplyng', () => {
prefix.apply(loglevel, { template: '%l (%n):' });
loglevel.info('test');
expect(spy.calledWith('INFO (root): test')).to.be.true;
});
it('Format', () => {
prefix.apply(loglevel, {
format: (level, logger) => `${level} (${logger}):`
});
loglevel.info('test');
expect(spy.calledWith('INFO (root): test')).to.be.true;
});
it('Unformat', () => {
prefix.apply(loglevel, { template: '%l:' });
loglevel.info('test');
expect(spy.calledWith('INFO: test')).to.be.true;
});
it('The prefix must be combined with the first argument, if it is a string', () => {
prefix.apply(loglevel, { template: '%l:' });
loglevel.info('foo %s', 'bar');
expect(spy.calledWith('INFO: foo %s', 'bar')).to.be.true;
});
it('All methods of the previous plugin should be called', () => {
prefix.apply(loglevel);
// for warn in apply
spy.reset();
loglevel.trace();
loglevel.debug();
loglevel.info();
loglevel.warn();
loglevel.error();
expect(spy.callCount).to.equal(5);
});
it('Child applying', () => {
const child = loglevel.getLogger('child');
prefix.apply(child, { template: '%l (%n):' });
child.info('test');
expect(spy.calledWith('INFO (child): test')).to.be.true;
});
it('Child reapplyng', () => {
const child = loglevel.getLogger('child');
prefix.apply(child, {
levelFormatter(level) {
return level;
}
});
child.info('test');
expect(spy.calledWith('info (child): test')).to.be.true;
});
});