Initial import from local backup (Documents-Playground/pakerpale)

This commit is contained in:
jeonghwa
2026-07-03 05:27:45 +09:00
commit 95f2ab1713
2784 changed files with 1066361 additions and 0 deletions

176
node_modules/logops/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,176 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.

13
node_modules/logops/NOTICE generated vendored Normal file
View File

@@ -0,0 +1,13 @@
Copyright 2014,2015 Telefónica I+D
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

269
node_modules/logops/README.md generated vendored Normal file
View File

@@ -0,0 +1,269 @@
# logops
Really simple and performant JSON logger for node.js.
[![npm version](https://img.shields.io/npm/v/logops.svg)](http://badge.fury.io/js/logops)
[![Build Status](https://img.shields.io/travis/telefonicaid/logops.svg)](https://travis-ci.org/telefonicaid/logops)
[![Coveralls branch](https://img.shields.io/coveralls/telefonicaid/logops/master.svg)](https://coveralls.io/r/telefonicaid/logops?branch=master)
[![Dependency Status](https://img.shields.io/gemnasium/telefonicaid/logops.svg)](https://gemnasium.com/telefonicaid/logops)
![Typescript definitions](https://img.shields.io/badge/TypeScript%20Definition-.d.ts-blue.svg)
## Installation
```bash
npm install logops
```
## Basic usage
```js
var logger = require('logops');
//plain strings
logger.debug('This is an example');
// {"time":"2015-12-22T16:31:39.220Z","lvl":"DEBUG","msg":"This is an example"}
//util.format support
logger.info('Request %s %d %j', 'is', 5, {key: 'value'}, 'guy');
// {"time":"2015-12-22T16:31:56.184Z","lvl":"INFO","msg":"Request is 5 {\"key\":\"value\"} guy"}
//properties in the log trace
logger.warn({ip: '127.0.0.0'}, 'Something went wrong');
// {"ip":"127.0.0.0","time":"2015-12-22T16:33:17.002Z","lvl":"WARN","msg":"Something went wrong"}
//special case: error instance to print error info (and stack traces)...
logger.error(new TypeError('String required'));
/* {"time":"2015-12-22T16:36:39.650Z","lvl":"ERROR",
* "err":{"message":"String required","name":"TypeError","constructor":"TypeError","stack":"TypeError: String required\n at...",
* "msg":"TypeError: String required"} */
//... or specify the message
logger.fatal(new Error('Out of memory'), 'SYSTEM UNSTABLE. BYE');
/* {"time":"2015-12-22T16:45:36.468Z","lvl":"FATAL",
* "err":{"message":"Out of memory","name":"Error","constructor":"Error","stack":"Error: Out of memory\n at...",
* "msg":"SYSTEM UNSTABLE. BYE"} */
```
* If you give an object as the first argument, you will print its properties but not a String representation of it. `logger.info(req)` will set all `req` properties in the final json. `logger.info({a:'guy'}) =>
{"a":"guy","time":"2015-12-23T12:09:12.610Z","lvl":"INFO","msg":"undefined"}`
* The pattern `logger.error(err)` is very common. This API embraces the requirenment, and makes an special management of it. But getting an error stack trace is not cheap. It only will be get and printed when `log.error` or `log.fatal` is used, so you can use `logger.info(new Error('User Not Found'));` to not print useless stackstraces for your bussiness logic errors. _You can override it, btw_
* With the rest of arguments is just like calling `console.log`. It will be serialized as the trace message. Easy to remember.
## Context support
Logops supports using global properties that will be merged with the specific ones defined in the call. Simply override the `logger.getContext` method to let the logger get it. See `logops.child` to see how to also create loggers with context
```js
var logger = require('logops'),
hostname = require('os').hostname();
logger.getContext = function getContext() {
return {
hostname: hostname,
pid: process.pid
};
}
logger.info({app: 'server'}, 'Startup');
// {"hostname":"host.local","pid":35502,"app":"server","time":"2015-12-23T11:47:25.862Z","lvl":"INFO","msg":"Startup"}
```
## Logger Level
You can set the logging level at any time. All the disabled logging methods are replaced by a noop,
so there is not any performance penalty at production using an undesired level
```js
var logger = require('logops');
// {String} level one of the following values ['DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL']
logger.setLevel('DEBUG');
```
You can also set the logging level using the `LOGOPS_LEVEL` environment variable:
```bash
export LOGOPS_LEVEL=DEBUG
```
You can get the logging level using the `getLevel()` function of the logger:
```
currentLevel = logger.getLevel();
```
## Trace format
This library incorporates two flavors of trace formatting:
* "json": writes logs as JSON. This is the **DEFAULT in v1.0.0**
* "dev": for development. Used with 'de-facto' NODE_ENV variable is set to 'development'
* "pipe": writes logs separating fields with pipes. **DEPRECATED in v1.0.0**
```js
logger.format = logger.formatters.json;
logger.info({key:'value'}, 'This is an example: %d', 5);
// {"key":"value","time":"2015-12-23T11:55:27.041Z","lvl":"INFO","msg":"This is an example: 5"}
logger.format = logger.formatters.dev;
logger.info({key:'value'}, 'This is an example: %d', 5);
// INFO This is an example: 5 { key: 'value' }
logger.format = logger.formatters.pipe; //DEPRECATED in v1.0.0
logger.info({key:'value'}, 'This is an example: %d', 5);
// time=2015-12-23T11:57:24.879Z | lvl=INFO | corr=n/a | trans=n/a | op=n/a | msg=This is an example: 5
```
You can also set the format specifying the formatter with `LOGOPS_FORMAT` environment variable:
```bash
export LOGOPS_FORMAT=json
# export LOGOPS_FORMAT=dev
```
## Child Loggers
You can create an specialized logger for a part of your app with bound static context/properties. The child logger
will inherit its parent config: level, format, stream and context. If the parent logger has a context returned by `parent.getContext()`, the conflicting child logger context will take precedence
```js
let child = logger.child({component: 'client'});
child.info('Startup');
// {"component":"client","time":"2015-12-23T11:47:25.862Z","lvl":"INFO","msg":"Startup"}
```
**TIP: Using with express/connect**
You can create a simply middleware to add a logger to every request with something like
```js
app.use(function(req, res, next) {
req.logger = logger.child({
requestId: uuid.v4()
});
next();
});
```
So your `req.logger` will log the requestId to allow correlation of traces in your server traces.
_Note: setting `child.getContext` property, will override the context used to create the logger and its merge with its parent one. So you can use it to create a context free logger_
## Advanced Usage
### Trace format
You can override the format function and manage by yourself the formatting taking into account your own environment variables by
overriding the `logger.format` function
### Don't print specific properties with `dev` format
Omit some boring/repeated/always-the-same context properties from being logged with the `dev` formatter:
```js
logger.format = logger.formatters.dev;
logger.getContext = () => ({ pid: process.pid });
logger.info({key:'value', ip:'127.0.0.1'}, 'This is an example: %d', 5);
// INFO This is an example: 5 { pid: 123342, key: 'value', ip: '127.0.0.1' }
// Specify the context fields to omit as an array
logger.formatters.dev.omit = ['pid', 'ip'];
logger.info({key:'value', ip:'127.0.0.1'}, 'This is an example: %d', 5);
// INFO This is an example: 5 { key: 'value' }
```
### Don't print Error Stack traces
Set `logger.formatters.stacktracesWith` array with the error levels that will print stacktraces. Default is `stacktracesWith: ['ERROR', 'FATAL']`
### Writing to files
This library writes by default to `process.stdout`, the safest, fastest and easy way to manage logs. It's how you execute your app when you define how to manage logs.
This approach is also compatible with [logrotate](http://linuxcommand.org/man_pages/logrotate8.html) as this is how many servers and PaaS manage the logs.
Therefore you don't need to put __anything__ in your source code relative to logs, and all is done at execution time depending on the deployment.
__Recommended execution:__ Pipelining the stdout to [tee](http://en.wikipedia.org/wiki/Tee_(command)).
With this configuration, you will not fail when the disk is full
```bash
# write all traces to out.log
set -o pipefail
node index.js | tee -a out.log > /dev/null
```
```bash
# write error and fatal traces to error.log and all traces to out.log (using json formatter)
set -o pipefail
LOGOPS_FORMAT=json node index.js | tee >(grep -a -F -e '"lvl":"ERROR"' -e '"lvl":"FATAL"' > error.log) > out.log
```
You can also write logs and fail miserably stopping your app when the disk is full by doing
```bash
node index.js > out.log
```
Please read carefully in the node documentation how the `stdout`/`stderr` stream behaves [regarding synchronous/asynchronous writing](https://nodejs.org/api/process.html#process_process_stdout)
If you want to pipe the output stream to any other stream in your source code, or even write to files *(not recommended)*,
you can override the stream used by this library
```js
var logger = require('logops');
logger.stream = new MyOtherSuperStreamThatDoesGreatThingsExceptWriteToDisk();
```
## History
This project was created initially for logging using the now deprecated pipe format, used internally at Telefonica by some logging infrastructure deployments.
Now we are switching to a new one one, based on documents and a NoSQL infrastructure, where the JSON format is the one that
fits best. We got inspired by the wonderful [`bunyan`](https://github.com/trentm/node-bunyan) project and made some little adjustments in our API
to be compliant with it, to reduce developer learning curve, make our preexisting code compatible and keep (or even improve) [its great performance](https://www.loggly.com/blog/a-benchmark-of-five-node-js-logging-libraries/).
## Benchmark
A very basic [benchmark](./benchmark/index.js) with the most common use case has
been setup to compare with [`bunyan`](https://github.com/trentm/node-bunyan)
Running on a MAC OS X Yosemite, 2,5 GHz Intel Core i5, 8 GB 1333 MHz DDR3, SSD disk, node 6.10.0
```
$ cd benchmark; npm start
> benchmarklogops@1.0.0 tee /Users/javier/Documents/Proyectos/logops/benchmark
> node index.js | tee -a out.log > /dev/null
logops x 70,675 ops/sec ±11.89% (65 runs sampled)
bunyan x 81,981 ops/sec ±4.76% (70 runs sampled)
Basic logging: Fastest is bunyan,logops
logops x 67,169,402 ops/sec ±2.79% (80 runs sampled)
bunyan x 5,774,822 ops/sec ±5.74% (75 runs sampled)
Disabled logging: Fastest is logops
> benchmarklogops@1.0.0 file /Users/javier/Documents/Proyectos/logops/benchmark
> node index.js > out.log
logops x 37,479 ops/sec ±5.69% (76 runs sampled)
bunyan x 36,211 ops/sec ±2.72% (77 runs sampled)
Basic logging: Fastest is logops
logops x 70,740,515 ops/sec ±1.71% (82 runs sampled)
bunyan x 6,324,283 ops/sec ±2.68% (78 runs sampled)
Disabled logging: Fastest is logops
> benchmarklogops@1.0.0 null /Users/javier/Documents/Proyectos/logops/benchmark
> node index.js > /dev/null
logops x 49,509 ops/sec ±4.92% (77 runs sampled)
bunyan x 47,759 ops/sec ±4.34% (69 runs sampled)
Basic logging: Fastest is logops
logops x 68,293,618 ops/sec ±2.64% (80 runs sampled)
bunyan x 6,232,825 ops/sec ±2.42% (81 runs sampled)
Disabled logging: Fastest is logops
```
## License
Copyright 2014, 2015 [Telefonica Investigación y Desarrollo, S.A.U](http://www.tid.es)
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

211
node_modules/logops/lib/formatters.js generated vendored Normal file
View File

@@ -0,0 +1,211 @@
/**
* @license
* Copyright 2015 Telefonica Investigación y Desarrollo, S.A.U
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*jshint -W072*/
'use strict';
var util = require('util'),
colors = require('colors/safe'),
safeStringify = require('safe-json-stringify'),
serializeErr = require('serr'),
_ = require('lodash');
var DEFAULT_NOT_AVAILABLE = 'n/a';
var notAvailable = DEFAULT_NOT_AVAILABLE,
templateTrace = 'time=%s | lvl=%s | corr=%s | trans=%s | op=%s | msg=';
/**
* The exported formatters.
*
* @type {Object}
*/
var API = module.exports = {
dev: formatDevTrace,
json: formatJsonTrace,
stacktracesWith: ['ERROR', 'FATAL'],
pipe: formatTrace, // Deprecated
setNotAvailable: setNotAvailable // Deprecated
};
/**
* Sets a value for those fields that are not available in the context. This field
* will only be used in the 'pipes' formatter.
*
* @param {String} na New value for not available fields.
* @deprecated
*/
function setNotAvailable(na) {
notAvailable = na;
}
/**
* Formats a trace message with some nice TTY colors
*
* @param {String} level One of the following values
* ['DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL']
* @param {Object} context Additional information to add to the trace
* @param {String} message The main message to be added to the trace
* @param {Array} args More arguments provided to the log function
* @param {Error|undefined} err A cause error used to log extra information
*
* @return {String} The trace formatted
*/
function formatDevTrace(level, context, message, args, err) {
var str,
mainMessage = util.format.apply(global, [message].concat(args)),
printStack = API.stacktracesWith.indexOf(level) > -1,
errCommomMessage = err && (err.name + ': ' + err.message),
isErrorLoggingWithoutMessage = mainMessage === errCommomMessage;
switch (level) {
case 'DEBUG':
str = colors.grey(level);
break;
case 'INFO':
str = colors.blue(level) + ' '; // Pad to 5 chars
break;
case 'WARN':
str = colors.yellow(level) + ' '; // Pad to 5 chars
break;
case 'ERROR':
str = colors.red(level);
break;
case 'FATAL':
str = colors.red.bold(level);
break;
}
str += ' ' + mainMessage;
if (isErrorLoggingWithoutMessage) {
str += colorize(colors.gray, serializeErr(err).toString(printStack).substr(mainMessage.length));
} else if (err) {
str += '\n' + colorize(colors.gray, serializeErr(err).toString(printStack));
}
var localContext = _.omit(context, formatDevTrace.omit);
str += Object.keys(localContext).length ?
' ' + colorize(colors.gray, util.inspect(localContext)) :
'';
// pad all subsequent lines with as much spaces as "DEBUG " or "INFO " have
return str.replace(new RegExp('\r?\n','g'), '\n ');
}
/**
* Context properties that should be skipped from printing in dev format
* @type {Array.<String>}
*/
formatDevTrace.omit = [];
// Damm! colors are not applied to multilines! split, apply and join!
function colorize(color, str) {
return str
.split('\n')
.map(part => color(part))
.join('\n');
}
/**
* Formats a trace message with fields separated by pipes.
*
* DEPRECATED!
*
* @param {String} level One of the following values
* ['DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL']
* @param {Object} context Additional information to add to the trace
* @param {String} message The main message to be added to the trace
* @param {Array} args More arguments provided to the log function
* @param {Error|undefined} err A cause error used to log extra information
*
* @return {String} The trace formatted
* @deprecated
*/
function formatTrace(level, context, message, args, err) {
var recontext = {
time: (new Date()).toISOString(),
lvl: level,
corr: context.corr || notAvailable,
trans: context.trans || notAvailable,
op: context.op || notAvailable
};
Object.keys(context)
.filter((key) => {
return !(context[key] && Object.prototype.toString.call(context[key]) === '[object Function]');
})
.forEach((key) => {
recontext[key] = context[key] || notAvailable;
});
if (message instanceof Date || message instanceof Error) {
// Node6 related hack. See https://github.com/telefonicaid/logops/issues/36
recontext.msg = util.format(message);
} else {
recontext.msg = message;
}
var str = Object.keys(recontext)
.map((key) => key + '=' + recontext[key])
.join(' | ');
args.unshift(str);
if (err && message !== '' + err) {
args.push(err);
}
return util.format.apply(global, args);
}
/**
* Formats a trace message in JSON format
*
* @param {String} level One of the following values
* ['DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL']
* @param {Object} context Additional information to add to the trace
* @param {String} message The main message to be added to the trace
* @param {Array} args More arguments provided to the log function
* @param {Error|null} err A cause error used to log extra information
*
* @return {String} The trace formatted
*/
function formatJsonTrace(level, context, message, args, err) {
return formatJsonTrace.stringify(formatJsonTrace.toObject(level, context, message, args, err));
}
formatJsonTrace.stringify = (obj) => {
try {
return JSON.stringify(obj);
} catch (err) {
return safeStringify(obj);
}
};
formatJsonTrace.toObject = (level, context, message, args, err) => {
let log = {};
for (let attrname in context) {
log[attrname] = context[attrname];
}
log.time = new Date();
log.lvl = level;
log.err = err && serializeErr(err).toObject(API.stacktracesWith.indexOf(level) > -1);
log.msg = util.format.apply(global, [message].concat(args));
return log;
};

354
node_modules/logops/lib/logops.d.ts generated vendored Normal file
View File

@@ -0,0 +1,354 @@
/** Simple and performant nodejs JSON logger */
interface Logops {
/**
* The NODEJS stream where the logger will write string traces
* Defaults to process.stdout
*/
setStream(stream: NodeJS.WritableStream): void;
stream: NodeJS.WritableStream;
/**
* Gets the current log level. The default level is INFO
*/
getLevel(): Level;
/**
* Sets the enabled logging level.
* All the disabled logging methods are replaced by a noop,
* so there is not any performance penalty at production using an undesired level
* You can also set the logging level using the `LOGOPS_LEVEL` environment variable:
* ```
* $> LOGOPS_LEVEL=DEBUG node app.js
* ```
*
* @param level one of 'DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL'
*/
setLevel(level: Level): void;
/**
* Sets a global context that should be printed and merged with specific
* log context props
*
* @example
* ```
* logops.setContextGetter(function getContext() {
* return {
* hostname: require('os').hostname,
* pid: process.pid
* };
* });
*
* logger.info({app: 'server'}, 'Startup');
* // {"hostname":"host.local","pid":35502,"app":"server","time":"2015-12-23T11:47:25.862Z","lvl":"INFO","msg":"Startup"}
* ```
* @return The context object
*/
setContextGetter(getContext: () => Context): void;
getContext(): Context;
/**
* Specifies the Formatter used for printing traces
* @example
* ```
* logops.setFormat(logops.formatters.dev);
* ```
*
* You can also set the format specifying the formatter with `LOGOPS_FORMAT` environment variable:
* @example
* ```
* $> LOGOPS_FORMAT=json node app.js
* ```
*/
setFormat(format: Formatter): void;
format: Formatter;
/**
* Creates a child logger with the this logger settings that will append the
* passed context to the parent one (if any)
* ```
* let child = logger.child({hostname: 'host.local'});
* child.info({app: 'server'}, 'Startup');
* // {"hostname":"host.local","app":"server","time":"2015-12-23T11:47:25.862Z","lvl":"INFO","msg":"Startup"}
* ```
*/
child(context?: Context): Logops;
/**
* The available formatters
*/
formatters: Formatters;
/**
* Logs a debug trace with the provided Context
* ```
* logger.debug({ip: '127.0.0.0'}, 'Something went wrong');
* // {"ip":"127.0.0.0","time":"2015-12-22T16:33:17.002Z","lvl":"DEBUG","msg":"Something went wrong"}
* ```
*
* @param props the Context to print
* @param format A printf-like format string as you will use in console.log()
* @param params Additional properties to be coerced in the format string
*/
debug(props: Context, format?: string, ...params: any[]): void;
/**
* Logs an Error as a debug trace.
* See Logops.stacktracesWith to print the stack traces
* ```
* logger.debug(new Error('Out of memory'), 'SYSTEM UNSTABLE. BYE');
* ```
*
* @param error the Error to serialize and print
* @param format A printf-like format string as you will use in console.log().
* If not present, the message will be the Error message itself
* @param params Additional properties to be coerced in the format string
*/
debug(error: Error, format?: string, ...params: any[]): void;
/**
* Logs a debug trace, as you will do with console.log
* ```
* logger.debug('Request %s %d %j', 'is', 5, {key: 'value'}, 'guy');
* // {"time":"2015-12-22T16:31:56.184Z","lvl":"DEBUG","msg":"Request is 5 {\"key\":\"value\"} guy"}
* ```
*
* @param format A printf-like format string as you will use in console.log().
* @param params Additional properties to be coerced in the format string
*/
debug(format: string, ...params: any[]): void;
/**
* Logs an info trace with the provided Context
* ```
* logger.info({ip: '127.0.0.0'}, 'Something went wrong');
* // {"ip":"127.0.0.0","time":"2015-12-22T16:33:17.002Z","lvl":"INFO","msg":"Something went wrong"}
* ```
*
* @param props the Context to print
* @param format A printf-like format string as you will use in console.log()
* @param params Additional properties to be coerced in the format string
*/
info(props: Context, format?: string, ...params: any[]): void;
/**
* Logs an Error as a info trace.
* See Logops.stacktracesWith to print the stack traces
* ```
* logger.info(new Error('Out of memory'), 'SYSTEM UNSTABLE. BYE');
* ```
*
* @param error the Error to serialize and print
* @param format A printf-like format string as you will use in console.log().
* If not present, the message will be the Error message itself
* @param params Additional properties to be coerced in the format string
*/
info(error: Error, format?: string, ...params: any[]): void;
/**
* Logs a info trace, as you will do with console.log
* ```
* logger.info('Request %s %d %j', 'is', 5, {key: 'value'}, 'guy');
* // {"time":"2015-12-22T16:31:56.184Z","lvl":"INFO","msg":"Request is 5 {\"key\":\"value\"} guy"}
* ```
*
* @param format A printf-like format string as you will use in console.log().
* @param params Additional properties to be coerced in the format string
*/
info(format: string, ...params: any[]): void;
/**
* Logs a warning trace with the provided Context
* ```
* logger.warn({ip: '127.0.0.0'}, 'Something went wrong');
* // {"ip":"127.0.0.0","time":"2015-12-22T16:33:17.002Z","lvl":"WARN","msg":"Something went wrong"}
* ```
*
* @param props the Context to print
* @param format A printf-like format string as you will use in console.log()
* @param params Additional properties to be coerced in the format string
*/
warn(props: Context, format?: string, ...params: any[]): void;
/**
* Logs an Error as a warn trace.
* See Logops.stacktracesWith to print the stack traces
* ```
* logger.warn(new Error('Out of memory'), 'SYSTEM UNSTABLE. BYE');
* ```
*
* @param error the Error to serialize and print
* @param format A printf-like format string as you will use in console.log().
* If not present, the message will be the Error message itself
* @param params Additional properties to be coerced in the format string
*/
warn(error: Error, format?: string, ...params: any[]): void;
/**
* Logs a warn trace, as you will do with console.log
* ```
* logger.warn('Request %s %d %j', 'is', 5, {key: 'value'}, 'guy');
* // {"time":"2015-12-22T16:31:56.184Z","lvl":"WARN","msg":"Request is 5 {\"key\":\"value\"} guy"}
* ```
*
* @param format A printf-like format string as you will use in console.log().
* @param params Additional properties to be coerced in the format string
*/
warn(format: string, ...params: any[]): void;
/**
* Logs an error trace with the provided Context
* ```
* logger.error({ip: '127.0.0.0'}, 'Something went wrong');
* // {"ip":"127.0.0.0","time":"2015-12-22T16:33:17.002Z","lvl":"ERROR","msg":"Something went wrong"}
* ```
*
* @param props the Context to print
* @param format A printf-like format string as you will use in console.log()
* @param params Additional properties to be coerced in the format string
*/
error(props: Context, format?: string, ...params: any[]): void;
/**
* Logs an Error as an error trace.
* See Logops.stacktracesWith to print the stack traces
* ```
* logger.error(new Error('Out of memory'), 'SYSTEM UNSTABLE. BYE');
* ```
*
* @param error the Error to serialize and print
* @param format A printf-like format string as you will use in console.log().
* If not present, the message will be the Error message itself
* @param params Additional properties to be coerced in the format string
*/
error(error: Error, format?: string, ...params: any[]): void;
/**
* Logs a error trace, as you will do with console.log
* ```
* logger.error('Request %s %d %j', 'is', 5, {key: 'value'}, 'guy');
* // {"time":"2015-12-22T16:31:56.184Z","lvl":"ERROR","msg":"Request is 5 {\"key\":\"value\"} guy"}
* ```
*
* @param format A printf-like format string as you will use in console.log().
* @param params Additional properties to be coerced in the format string
*/
error(format: string, ...params: any[]): void;
/**
* Logs a fatal trace with the provided Context
* ```
* logger.fatal({ip: '127.0.0.0'}, 'Something went wrong');
* // {"ip":"127.0.0.0","time":"2015-12-22T16:33:17.002Z","lvl":"FATAL","msg":"Something went wrong"}
* ```
*
* @param props the Context to print
* @param format A printf-like format string as you will use in console.log()
* @param params Additional properties to be coerced in the format string
*/
fatal(props: Context, format?: string, ...params: any[]): void;
/**
* Logs an Error as a debug trace.
* See Logops.stacktracesWith to print the stack traces
* ```
* logger.fatal(new Error('Out of memory'), 'SYSTEM UNSTABLE. BYE');
* ```
*
* @param error the Error to serialize and print
* @param format A printf-like format string as you will use in console.log().
* If not present, the message will be the Error message itself
* @param params Additional properties to be coerced in the format string
*/
fatal(error: Error, format?: string, ...params: any[]): void;
/**
* Logs a fatal trace, as you will do with console.log
* ```
* logger.fatal('Request %s %d %j', 'is', 5, {key: 'value'}, 'guy');
* // {"time":"2015-12-22T16:31:56.184Z","lvl":"FATAL","msg":"Request is 5 {\"key\":\"value\"} guy"}
* ```
*
* @param format A printf-like format string as you will use in console.log().
* @param params Additional properties to be coerced in the format string
*/
fatal(format: string, ...params: any[]): void;
}
declare let logops: Logops;
export = logops;
/**
* Log levels
*/
type Level = 'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'FATAL';
/**
* A key value map that should be printed and serialized as first class
* citizien in the traces.
*/
interface Context {
[key: string]: any;
}
/**
* Interface for a logops formatter, that formats the user input as a readable
* string ready to be written to a Stream
*/
interface Formatter {
/**
* Format the user input as a readable string ready to be written to a Stream
* @param level One of the following values
* ['DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL']
* @param context Additional information to add to the trace
* @param message The main message to be added to the trace
* @param args More arguments provided to the log function
* @param err A cause error used to log extra information
*/
format(level: string, context: Context, message: string, args: any[], err?: Error): string;
}
/**
* The additional properties in a DevFormatter
*/
interface DevFormatter extends Formatter {
/**
* Context properties keys that should be skipped from printing in dev format
*/
omit: string[];
}
/**
* The formatters interface. All relative to customization of how a trace
* is printed is located here
*/
interface Formatters {
/**
* Formats a trace message in JSON format
*/
json: Formatter;
/**
* Formats a trace message with some nice TTY colors
*/
dev: DevFormatter;
/**
* Formats a trace message with fields separated by pipes.
* @deprecated
*/
pipe: Formatter;
/**
* Array of logger levels that will print error stacktraces
* Defaults to `['ERROR', 'FATAL']
*/
stacktracesWith: Level[];
/**
* Sets a value for those fields that are not available in the context. This field
* will only be used in the 'pipes' formatter.
*
* @param str New value for not available fields.
* @deprecated
*/
setNotAvailable(str: string): void;
}

276
node_modules/logops/lib/logops.js generated vendored Normal file
View File

@@ -0,0 +1,276 @@
/**
* @license
* Copyright 2015 Telefonica Investigación y Desarrollo, S.A.U
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const formatters = require('./formatters');
const levels = ['DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL'];
const DEFAULT_LEVEL = 'INFO';
module.exports = logops();
function noop() {};
function logops(options) {
let opts = merge({
level: process.env.LOGOPS_LEVEL || DEFAULT_LEVEL,
format: formatters[process.env.LOGOPS_FORMAT] || (process.env.NODE_ENV === 'development' ?
formatters.dev :
formatters.json
),
getContext: noop,
stream: process.stdout,
}, options);
let API = {};
/**
* Internal private function that implements a decorator to all
* the level functions.
*
* @param {String} level one of
* ['DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL']
*/
function logWrap(level) {
return function log() {
let context, message, args, trace, err;
if (arguments[0] instanceof Error) {
// log.<level>(err, ...)
context = API.getContext();
args = Array.prototype.slice.call(arguments, 1);
if (!args.length) {
// log.<level>(err)
err = arguments[0];
message = err.name + ': ' + err.message;
} else {
// log.<level>(err, "More %s", "things")
// Use the err as context information
err = arguments[0];
message = arguments[1];
args = Array.prototype.slice.call(args, 1);
}
} else if (arguments[0] == null || (typeof (arguments[0]) !== 'object' && arguments[0] !== null) ||
Array.isArray(arguments[0])) {
// log.<level>(msg, ...)
context = API.getContext();
message = arguments[0];
args = Array.prototype.slice.call(arguments, 1);
} else {
// log.<level>(fields, msg, ...)
context = merge(API.getContext(), arguments[0]);
message = arguments[1];
args = Array.prototype.slice.call(arguments, 2);
}
trace = API.format(level, context || {}, message, args, err);
API.stream.write(trace + '\n');
};
}
/**
* Sets the enabled logging level.
* All the disabled logging methods are replaced by a noop,
* so there is not any performance penalty at production using an undesired level
*
* @param {String} level
*/
function setLevel(level) {
opts.level = level;
let logLevelIndex = levels.indexOf(opts.level.toUpperCase());
levels.forEach((logLevel) => {
let fn;
if (logLevelIndex <= levels.indexOf(logLevel)) {
fn = logWrap(logLevel);
} else {
fn = noop;
}
API[logLevel.toLowerCase()] = fn;
});
}
/**
* The exported API.
* The following methods are added dynamically
* API.debug
* API.info
* API.warn
* API.error
* API.fatal
*
* @type {Object}
*/
API = {
/**
* The stream where the logger will write string traces
* Defaults to process.stdout
*/
stream: opts.stream,
setStream: (stream) => {
API.stream = stream;
},
/**
* Sets the enabled logging level.
* All the disabled logging methods are replaced by a noop,
* so there is not any performance penalty at production using an undesired level
*
* @param {String} level one of the following values
* ['DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL']
*/
setLevel: setLevel,
/**
* Gets the current log level.
*/
getLevel: () => opts.level,
/**
* Gets the context for a determinate trace. By default, this is a noop that
* you can override if you are managing your execution context with node domains
*
* This function must return an object with the following fields
* {
* corr: {String},
* trans: {String},
* op: {String}
* }
*
* If you are not using domain, you should pass the context information for
* EVERY log call
*
* Both examples will produce the same trace
*
* Example usage not using getContext:
* var logger = require('logops');
* req.context = {
* corr: 'cbefb082-3429-4f5c-aafd-26b060d6a9fc',
* trans: 'cbefb082-3429-4f5c-aafd-26b060d6a9fc',
* op: 'SendEMail'
* }
* logger.info(req.context, 'This is an example');
*
* Example using this feature:
* var logger = require('logops'),
* domain = require('domain');
*
* logger.getContext = function domainContext() {
* return domain.active.myCustomContext;
* }
* //...
*
* logger.info('This is an example');
*
* @return {Object} The context object
*/
getContext: opts.getContext,
setContextGetter: (fn) => {
API.getContext = fn;
},
/**
* Creates a string representation for a trace.
*
* It checks the `LOGOPS_FORMAT` environment variable to use the built-in
* format functions. It fallbacks to check the de-facto `NODE_ENV` env var
* to use the `formatters.dev` when the value is `development`. Otherwise, it
* will use the `formatters.pipe` (while in production, for example)
*
* Example
* NODE_ENV=development node index.js
* the logger will write traces for developers
*
* node index.js
* the logger will write traces in a pipe format (assuming NODE_ENV nor
* LOGOPS_FORMAT environment vars are defined with valid values)
*
* LOGOPS_FORMAT=json node index.js
* the logger will write json traces
*
* You can override this func and manage by yourself the formatting.
*
* @param {String} level One of the following values
* ['DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL']
* @param {Object} context Additional information to add to the trace
* @param {String} message The main message to be added to the trace
* @param {Array} args More arguments provided to the log function
*
* @return {String} The trace formatted
*/
format: opts.format,
setFormat: (format) => {
API.format = format;
},
/**
* Return an Object containing the available formatters ("dev", "pipe", "json").
*
* Example using this feature to write JSON logs.
*
* var logger = require('logops');
* logger.format = logger.formatters.json;
* logger.info('This is an example')
*
* @return {Object} The available formatters.
*/
formatters: formatters,
/**
* Creates a child logger with the this logger settings that will append the
* passed context to the parent one (if any)
* ```
* let child = logger.child({hostname: 'host.local'});
* child.info({app: 'server'}, 'Startup');
* // {"hostname":"host.local","app":"server","time":"2015-12-23T11:47:25.862Z","lvl":"INFO","msg":"Startup"}
* ```
*/
child: (localContext) => {
// the current limitation for this approach is that child
// loggers will overwrite the parent and localcontext when
// calling againg `child.setContextGetter(fn)` or assign a function
// to `child.getContext = fn`
// But as the context is specified then creating the child, we can
// considerer it a corner case and dont optimize for the use case
return logops({
level: API.getLevel(),
getContext: () => merge(API.getContext(), localContext),
format: API.format,
stream: API.stream,
});
}
};
setLevel(opts.level);
return API;
}
/**
* Merges accesible properties in two objects.
* obj2 takes precedence when common properties are found
*
* @param {Object} obj1
* @param {Object} obj2
* @returns {{}} The merged, new, object
*/
function merge(obj1, obj2) {
var res = {}, attrname;
for (attrname in obj1) {
res[attrname] = obj1[attrname];
}
for (attrname in obj2) {
res[attrname] = obj2[attrname];
}
return res;
}

101
node_modules/logops/package.json generated vendored Normal file
View File

@@ -0,0 +1,101 @@
{
"_from": "logops",
"_id": "logops@2.1.1",
"_inBundle": false,
"_integrity": "sha512-4VKuufobS4yzCsU3iyKJSudYhZfzg1aHO6j2aTdYf1K1kWz6+Mhfi91BqD+RXtokLpSfocc9vOkzbsun5U4OiQ==",
"_location": "/logops",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "logops",
"name": "logops",
"escapedName": "logops",
"rawSpec": "",
"saveSpec": null,
"fetchSpec": "latest"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/logops/-/logops-2.1.1.tgz",
"_shasum": "bd55f02af9cdf3c08bd3c8494a408fc5b25706e8",
"_spec": "logops",
"_where": "D:\\dev\\crossmap\\backend-services\\cm-app-youtube",
"author": {
"name": "Javier Mendiara Cañardo",
"email": "javier.mendiaracanardo@telefonica.com"
},
"bugs": {
"url": "https://github.com/telefonicaid/logops/issues"
},
"bundleDependencies": false,
"contributors": [
{
"name": "Juan Antonio Hernando Labajo",
"email": "juanantonio.hernandolabajo@telefonica.com"
},
{
"name": "Guido García Bernardo",
"email": "guido.garciabernardo@telefonica.com"
},
{
"name": "Germán Toro del Valle",
"email": "german.torodelvalle@telefonica.com"
},
{
"name": "Daniel Morán Jiménez",
"email": "daniel.moranjimenez@telefonica.com"
},
{
"name": "Juan de Bravo Diez",
"email": "juande.bravodiez@telefonica.com"
}
],
"dependencies": {
"colors": "^1.1.2",
"lodash": "^4.17.15",
"safe-json-stringify": "^1.2.0",
"serr": "^1.0.1"
},
"deprecated": false,
"description": "Simple and performant nodejs JSON logger",
"devDependencies": {
"@types/node": "^8.0.42",
"chai": "^4.2.0",
"coveralls": "^3.0.6",
"eslint": "^6.1.0",
"mocha": "^6.0.2",
"nyc": "14.1.1",
"sinon": "^7.4.1",
"sinon-chai": "^3.3.0",
"tslint": "^5.18.0",
"tslint-config-typings": "^0.3.1",
"typescript": "^2.0.3"
},
"engines": {
"node": ">=6"
},
"homepage": "https://github.com/telefonicaid/logops",
"keywords": [
"logger",
"simple",
"performant"
],
"license": "Apache-2.0",
"main": "lib/logops",
"name": "logops",
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/telefonicaid/logops.git"
},
"scripts": {
"coverage": "nyc report --reporter=text-lcov | coveralls",
"lint": "eslint lib && tslint './{lib,test}/**/*.ts'",
"test": "nyc mocha -R spec test/environment.js 'test/**/*.spec.js' && npm run test:ts",
"test:ts": "tsc --noEmit"
},
"typings": "./lib/logops.d.ts",
"version": "2.1.1"
}