feat: ✨ Created a mini nodeJS server with NewMan for testing without PostMan GUI.
This will mimic a run in a CD/CI environment or docker container.
This commit is contained in:
104
node_modules/intel/CHANGELOG.md
generated
vendored
Normal file
104
node_modules/intel/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
# intel ChangeLog
|
||||
|
||||
### v1.2.0 - 2017-06-01
|
||||
|
||||
- changed handleExceptions exitOnError to exit immediately, instead of
|
||||
on a timout.
|
||||
|
||||
#### v1.1.2 - 2016-12-02
|
||||
|
||||
- fixed error when error does not have a stack property
|
||||
|
||||
#### v1.1.1 - 2016-06-22
|
||||
|
||||
- fixed error message when handler is undefined in `intel.config()`
|
||||
|
||||
### v1.1.0 - 2015-12-14
|
||||
|
||||
- added `basename` option to `intel.console()`
|
||||
|
||||
#### v1.0.2 - 2015-09-10
|
||||
|
||||
- fixed formatting of RegExps by default
|
||||
|
||||
#### v1.0.1 - 2015-08-19
|
||||
|
||||
- fixed Filter bug when more than 1 filter was added
|
||||
- fixed debug() interception when using intel.console()
|
||||
|
||||
## v1.0.0 - 2014-12-17
|
||||
|
||||
- added `intel.console({ logger: str })` to specify a parent logger
|
||||
- added `record.v` to indicate log record format
|
||||
- added `record.host` equal the `os.hostname()`
|
||||
- added `%j` alias to `%O` in printf
|
||||
- added `%?` default formatting for an argument
|
||||
- added `:4` flag for indenting JSON in printf. such as `%:2j`.
|
||||
- fixed `logger.trace()` to no longer set `record.exception=true`
|
||||
- fixed cirular references in log arguments
|
||||
- fixed `intel.console(debug)` with uncolored output
|
||||
- changed `log.info('%s', false)` string interpolation to use internal printf
|
||||
- changed JSON format of `Record` to not include interpolated `message`, since it already contains `args`
|
||||
- changed Record.timestamp to use Date.now() instead of new Date()
|
||||
- removed `Promise`s being returned from log methods. Not useful, slows it down.
|
||||
- removed `Rotating` handler from core. Use [logrotate-stream](https://npmjs.org/package/logrotate-stream) or similar.
|
||||
- performance **HUGE BOOST ACROSS THE BOARD**
|
||||
|
||||
#### v0.5.2 - 2014-02-19
|
||||
|
||||
- added `strip` option to Formatter, which will strip all ANSI code
|
||||
|
||||
#### v0.5.1 - 2014-02-12
|
||||
|
||||
- added bgBlue to TRACE
|
||||
- changed uncaught exceptions log level to CRITICAL
|
||||
- fixed error if null was passed an argument to Logger.log()
|
||||
|
||||
### v0.5.0 - 2014-02-10
|
||||
|
||||
- added direct integration with `dbug` module
|
||||
- added `Logger.removeAllHandlers()`
|
||||
- added `formatFn` for Formatters and `regex`, `flags`, and `function` for Filters to ease `intel.config()`
|
||||
- added `Logger#trace` and `intel.TRACE` level
|
||||
- added `exception: boolean` and `uncaughtException: boolean` to LogRecord
|
||||
- added `Logger.NONE` and `Logger.ALL` levels
|
||||
- changed `intel.config` to remove default ROOT console handler
|
||||
- changed `intel.console` to remove "lib" from logger names like "connect.lib.session" to be "connect.session"
|
||||
- performance improved for `Logger#getEffectiveLevel()`
|
||||
|
||||
### v0.4.0 - 2013-12-04
|
||||
|
||||
- added intel.console({ debug: 'foo' }) option
|
||||
- performance gains
|
||||
|
||||
#### v0.3.1 - 2013-11-04
|
||||
|
||||
- fixed Rotating handler writing lock (thanks @chopachom)
|
||||
|
||||
### v0.3.0 - 2013-10-22
|
||||
|
||||
- added intel.handlers.Rotating
|
||||
- added ignore options to intel.console()
|
||||
- added chalk.enabled when colorize is used
|
||||
- added padding and truncation to printf
|
||||
- added Logger#handleExceptions to catch uncaught exceptions
|
||||
- added stack traces when an exception is logged
|
||||
- changed datetime to strftime, adds `%L` to output milliseconds
|
||||
- changed Promises from Q to bluebird, significantly faster
|
||||
- fixed Console handler from using accepting format options
|
||||
- optimizations for common cases, big boost
|
||||
|
||||
### v0.2.0 - 2013-10-04
|
||||
|
||||
- added Filters for Handlers and Loggers
|
||||
- added Handler timeout option
|
||||
- added pid to LogRecord
|
||||
- added configuration using JSON
|
||||
- changed Promises to LazyPromises
|
||||
- changed printf to faster, smaller printf
|
||||
- changed internal forEach to faster while loops
|
||||
- removed node v0.6 support (it didn't work anyways)
|
||||
|
||||
### v0.1.0 - 2013-09-30
|
||||
|
||||
- Initial release.
|
373
node_modules/intel/LICENSE
generated
vendored
Normal file
373
node_modules/intel/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,373 @@
|
||||
Mozilla Public License Version 2.0
|
||||
==================================
|
||||
|
||||
1. Definitions
|
||||
--------------
|
||||
|
||||
1.1. "Contributor"
|
||||
means each individual or legal entity that creates, contributes to
|
||||
the creation of, or owns Covered Software.
|
||||
|
||||
1.2. "Contributor Version"
|
||||
means the combination of the Contributions of others (if any) used
|
||||
by a Contributor and that particular Contributor's Contribution.
|
||||
|
||||
1.3. "Contribution"
|
||||
means Covered Software of a particular Contributor.
|
||||
|
||||
1.4. "Covered Software"
|
||||
means Source Code Form to which the initial Contributor has attached
|
||||
the notice in Exhibit A, the Executable Form of such Source Code
|
||||
Form, and Modifications of such Source Code Form, in each case
|
||||
including portions thereof.
|
||||
|
||||
1.5. "Incompatible With Secondary Licenses"
|
||||
means
|
||||
|
||||
(a) that the initial Contributor has attached the notice described
|
||||
in Exhibit B to the Covered Software; or
|
||||
|
||||
(b) that the Covered Software was made available under the terms of
|
||||
version 1.1 or earlier of the License, but not also under the
|
||||
terms of a Secondary License.
|
||||
|
||||
1.6. "Executable Form"
|
||||
means any form of the work other than Source Code Form.
|
||||
|
||||
1.7. "Larger Work"
|
||||
means a work that combines Covered Software with other material, in
|
||||
a separate file or files, that is not Covered Software.
|
||||
|
||||
1.8. "License"
|
||||
means this document.
|
||||
|
||||
1.9. "Licensable"
|
||||
means having the right to grant, to the maximum extent possible,
|
||||
whether at the time of the initial grant or subsequently, any and
|
||||
all of the rights conveyed by this License.
|
||||
|
||||
1.10. "Modifications"
|
||||
means any of the following:
|
||||
|
||||
(a) any file in Source Code Form that results from an addition to,
|
||||
deletion from, or modification of the contents of Covered
|
||||
Software; or
|
||||
|
||||
(b) any new file in Source Code Form that contains any Covered
|
||||
Software.
|
||||
|
||||
1.11. "Patent Claims" of a Contributor
|
||||
means any patent claim(s), including without limitation, method,
|
||||
process, and apparatus claims, in any patent Licensable by such
|
||||
Contributor that would be infringed, but for the grant of the
|
||||
License, by the making, using, selling, offering for sale, having
|
||||
made, import, or transfer of either its Contributions or its
|
||||
Contributor Version.
|
||||
|
||||
1.12. "Secondary License"
|
||||
means either the GNU General Public License, Version 2.0, the GNU
|
||||
Lesser General Public License, Version 2.1, the GNU Affero General
|
||||
Public License, Version 3.0, or any later versions of those
|
||||
licenses.
|
||||
|
||||
1.13. "Source Code Form"
|
||||
means the form of the work preferred for making modifications.
|
||||
|
||||
1.14. "You" (or "Your")
|
||||
means an individual or a legal entity exercising rights under this
|
||||
License. For legal entities, "You" includes any entity that
|
||||
controls, is controlled by, or is under common control with You. For
|
||||
purposes of this definition, "control" means (a) the power, direct
|
||||
or indirect, to cause the direction or management of such entity,
|
||||
whether by contract or otherwise, or (b) ownership of more than
|
||||
fifty percent (50%) of the outstanding shares or beneficial
|
||||
ownership of such entity.
|
||||
|
||||
2. License Grants and Conditions
|
||||
--------------------------------
|
||||
|
||||
2.1. Grants
|
||||
|
||||
Each Contributor hereby grants You a world-wide, royalty-free,
|
||||
non-exclusive license:
|
||||
|
||||
(a) under intellectual property rights (other than patent or trademark)
|
||||
Licensable by such Contributor to use, reproduce, make available,
|
||||
modify, display, perform, distribute, and otherwise exploit its
|
||||
Contributions, either on an unmodified basis, with Modifications, or
|
||||
as part of a Larger Work; and
|
||||
|
||||
(b) under Patent Claims of such Contributor to make, use, sell, offer
|
||||
for sale, have made, import, and otherwise transfer either its
|
||||
Contributions or its Contributor Version.
|
||||
|
||||
2.2. Effective Date
|
||||
|
||||
The licenses granted in Section 2.1 with respect to any Contribution
|
||||
become effective for each Contribution on the date the Contributor first
|
||||
distributes such Contribution.
|
||||
|
||||
2.3. Limitations on Grant Scope
|
||||
|
||||
The licenses granted in this Section 2 are the only rights granted under
|
||||
this License. No additional rights or licenses will be implied from the
|
||||
distribution or licensing of Covered Software under this License.
|
||||
Notwithstanding Section 2.1(b) above, no patent license is granted by a
|
||||
Contributor:
|
||||
|
||||
(a) for any code that a Contributor has removed from Covered Software;
|
||||
or
|
||||
|
||||
(b) for infringements caused by: (i) Your and any other third party's
|
||||
modifications of Covered Software, or (ii) the combination of its
|
||||
Contributions with other software (except as part of its Contributor
|
||||
Version); or
|
||||
|
||||
(c) under Patent Claims infringed by Covered Software in the absence of
|
||||
its Contributions.
|
||||
|
||||
This License does not grant any rights in the trademarks, service marks,
|
||||
or logos of any Contributor (except as may be necessary to comply with
|
||||
the notice requirements in Section 3.4).
|
||||
|
||||
2.4. Subsequent Licenses
|
||||
|
||||
No Contributor makes additional grants as a result of Your choice to
|
||||
distribute the Covered Software under a subsequent version of this
|
||||
License (see Section 10.2) or under the terms of a Secondary License (if
|
||||
permitted under the terms of Section 3.3).
|
||||
|
||||
2.5. Representation
|
||||
|
||||
Each Contributor represents that the Contributor believes its
|
||||
Contributions are its original creation(s) or it has sufficient rights
|
||||
to grant the rights to its Contributions conveyed by this License.
|
||||
|
||||
2.6. Fair Use
|
||||
|
||||
This License is not intended to limit any rights You have under
|
||||
applicable copyright doctrines of fair use, fair dealing, or other
|
||||
equivalents.
|
||||
|
||||
2.7. Conditions
|
||||
|
||||
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
|
||||
in Section 2.1.
|
||||
|
||||
3. Responsibilities
|
||||
-------------------
|
||||
|
||||
3.1. Distribution of Source Form
|
||||
|
||||
All distribution of Covered Software in Source Code Form, including any
|
||||
Modifications that You create or to which You contribute, must be under
|
||||
the terms of this License. You must inform recipients that the Source
|
||||
Code Form of the Covered Software is governed by the terms of this
|
||||
License, and how they can obtain a copy of this License. You may not
|
||||
attempt to alter or restrict the recipients' rights in the Source Code
|
||||
Form.
|
||||
|
||||
3.2. Distribution of Executable Form
|
||||
|
||||
If You distribute Covered Software in Executable Form then:
|
||||
|
||||
(a) such Covered Software must also be made available in Source Code
|
||||
Form, as described in Section 3.1, and You must inform recipients of
|
||||
the Executable Form how they can obtain a copy of such Source Code
|
||||
Form by reasonable means in a timely manner, at a charge no more
|
||||
than the cost of distribution to the recipient; and
|
||||
|
||||
(b) You may distribute such Executable Form under the terms of this
|
||||
License, or sublicense it under different terms, provided that the
|
||||
license for the Executable Form does not attempt to limit or alter
|
||||
the recipients' rights in the Source Code Form under this License.
|
||||
|
||||
3.3. Distribution of a Larger Work
|
||||
|
||||
You may create and distribute a Larger Work under terms of Your choice,
|
||||
provided that You also comply with the requirements of this License for
|
||||
the Covered Software. If the Larger Work is a combination of Covered
|
||||
Software with a work governed by one or more Secondary Licenses, and the
|
||||
Covered Software is not Incompatible With Secondary Licenses, this
|
||||
License permits You to additionally distribute such Covered Software
|
||||
under the terms of such Secondary License(s), so that the recipient of
|
||||
the Larger Work may, at their option, further distribute the Covered
|
||||
Software under the terms of either this License or such Secondary
|
||||
License(s).
|
||||
|
||||
3.4. Notices
|
||||
|
||||
You may not remove or alter the substance of any license notices
|
||||
(including copyright notices, patent notices, disclaimers of warranty,
|
||||
or limitations of liability) contained within the Source Code Form of
|
||||
the Covered Software, except that You may alter any license notices to
|
||||
the extent required to remedy known factual inaccuracies.
|
||||
|
||||
3.5. Application of Additional Terms
|
||||
|
||||
You may choose to offer, and to charge a fee for, warranty, support,
|
||||
indemnity or liability obligations to one or more recipients of Covered
|
||||
Software. However, You may do so only on Your own behalf, and not on
|
||||
behalf of any Contributor. You must make it absolutely clear that any
|
||||
such warranty, support, indemnity, or liability obligation is offered by
|
||||
You alone, and You hereby agree to indemnify every Contributor for any
|
||||
liability incurred by such Contributor as a result of warranty, support,
|
||||
indemnity or liability terms You offer. You may include additional
|
||||
disclaimers of warranty and limitations of liability specific to any
|
||||
jurisdiction.
|
||||
|
||||
4. Inability to Comply Due to Statute or Regulation
|
||||
---------------------------------------------------
|
||||
|
||||
If it is impossible for You to comply with any of the terms of this
|
||||
License with respect to some or all of the Covered Software due to
|
||||
statute, judicial order, or regulation then You must: (a) comply with
|
||||
the terms of this License to the maximum extent possible; and (b)
|
||||
describe the limitations and the code they affect. Such description must
|
||||
be placed in a text file included with all distributions of the Covered
|
||||
Software under this License. Except to the extent prohibited by statute
|
||||
or regulation, such description must be sufficiently detailed for a
|
||||
recipient of ordinary skill to be able to understand it.
|
||||
|
||||
5. Termination
|
||||
--------------
|
||||
|
||||
5.1. The rights granted under this License will terminate automatically
|
||||
if You fail to comply with any of its terms. However, if You become
|
||||
compliant, then the rights granted under this License from a particular
|
||||
Contributor are reinstated (a) provisionally, unless and until such
|
||||
Contributor explicitly and finally terminates Your grants, and (b) on an
|
||||
ongoing basis, if such Contributor fails to notify You of the
|
||||
non-compliance by some reasonable means prior to 60 days after You have
|
||||
come back into compliance. Moreover, Your grants from a particular
|
||||
Contributor are reinstated on an ongoing basis if such Contributor
|
||||
notifies You of the non-compliance by some reasonable means, this is the
|
||||
first time You have received notice of non-compliance with this License
|
||||
from such Contributor, and You become compliant prior to 30 days after
|
||||
Your receipt of the notice.
|
||||
|
||||
5.2. If You initiate litigation against any entity by asserting a patent
|
||||
infringement claim (excluding declaratory judgment actions,
|
||||
counter-claims, and cross-claims) alleging that a Contributor Version
|
||||
directly or indirectly infringes any patent, then the rights granted to
|
||||
You by any and all Contributors for the Covered Software under Section
|
||||
2.1 of this License shall terminate.
|
||||
|
||||
5.3. In the event of termination under Sections 5.1 or 5.2 above, all
|
||||
end user license agreements (excluding distributors and resellers) which
|
||||
have been validly granted by You or Your distributors under this License
|
||||
prior to termination shall survive termination.
|
||||
|
||||
************************************************************************
|
||||
* *
|
||||
* 6. Disclaimer of Warranty *
|
||||
* ------------------------- *
|
||||
* *
|
||||
* Covered Software is provided under this License on an "as is" *
|
||||
* basis, without warranty of any kind, either expressed, implied, or *
|
||||
* statutory, including, without limitation, warranties that the *
|
||||
* Covered Software is free of defects, merchantable, fit for a *
|
||||
* particular purpose or non-infringing. The entire risk as to the *
|
||||
* quality and performance of the Covered Software is with You. *
|
||||
* Should any Covered Software prove defective in any respect, You *
|
||||
* (not any Contributor) assume the cost of any necessary servicing, *
|
||||
* repair, or correction. This disclaimer of warranty constitutes an *
|
||||
* essential part of this License. No use of any Covered Software is *
|
||||
* authorized under this License except under this disclaimer. *
|
||||
* *
|
||||
************************************************************************
|
||||
|
||||
************************************************************************
|
||||
* *
|
||||
* 7. Limitation of Liability *
|
||||
* -------------------------- *
|
||||
* *
|
||||
* Under no circumstances and under no legal theory, whether tort *
|
||||
* (including negligence), contract, or otherwise, shall any *
|
||||
* Contributor, or anyone who distributes Covered Software as *
|
||||
* permitted above, be liable to You for any direct, indirect, *
|
||||
* special, incidental, or consequential damages of any character *
|
||||
* including, without limitation, damages for lost profits, loss of *
|
||||
* goodwill, work stoppage, computer failure or malfunction, or any *
|
||||
* and all other commercial damages or losses, even if such party *
|
||||
* shall have been informed of the possibility of such damages. This *
|
||||
* limitation of liability shall not apply to liability for death or *
|
||||
* personal injury resulting from such party's negligence to the *
|
||||
* extent applicable law prohibits such limitation. Some *
|
||||
* jurisdictions do not allow the exclusion or limitation of *
|
||||
* incidental or consequential damages, so this exclusion and *
|
||||
* limitation may not apply to You. *
|
||||
* *
|
||||
************************************************************************
|
||||
|
||||
8. Litigation
|
||||
-------------
|
||||
|
||||
Any litigation relating to this License may be brought only in the
|
||||
courts of a jurisdiction where the defendant maintains its principal
|
||||
place of business and such litigation shall be governed by laws of that
|
||||
jurisdiction, without reference to its conflict-of-law provisions.
|
||||
Nothing in this Section shall prevent a party's ability to bring
|
||||
cross-claims or counter-claims.
|
||||
|
||||
9. Miscellaneous
|
||||
----------------
|
||||
|
||||
This License represents the complete agreement concerning the subject
|
||||
matter hereof. If any provision of this License is held to be
|
||||
unenforceable, such provision shall be reformed only to the extent
|
||||
necessary to make it enforceable. Any law or regulation which provides
|
||||
that the language of a contract shall be construed against the drafter
|
||||
shall not be used to construe this License against a Contributor.
|
||||
|
||||
10. Versions of the License
|
||||
---------------------------
|
||||
|
||||
10.1. New Versions
|
||||
|
||||
Mozilla Foundation is the license steward. Except as provided in Section
|
||||
10.3, no one other than the license steward has the right to modify or
|
||||
publish new versions of this License. Each version will be given a
|
||||
distinguishing version number.
|
||||
|
||||
10.2. Effect of New Versions
|
||||
|
||||
You may distribute the Covered Software under the terms of the version
|
||||
of the License under which You originally received the Covered Software,
|
||||
or under the terms of any subsequent version published by the license
|
||||
steward.
|
||||
|
||||
10.3. Modified Versions
|
||||
|
||||
If you create software not governed by this License, and you want to
|
||||
create a new license for such software, you may create and use a
|
||||
modified version of this License if you rename the license and remove
|
||||
any references to the name of the license steward (except to note that
|
||||
such modified license differs from this License).
|
||||
|
||||
10.4. Distributing Source Code Form that is Incompatible With Secondary
|
||||
Licenses
|
||||
|
||||
If You choose to distribute Source Code Form that is Incompatible With
|
||||
Secondary Licenses under the terms of this version of the License, the
|
||||
notice described in Exhibit B of this License must be attached.
|
||||
|
||||
Exhibit A - Source Code Form License Notice
|
||||
-------------------------------------------
|
||||
|
||||
This Source Code Form is subject to the terms of the Mozilla Public
|
||||
License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
If it is not possible or desirable to put the notice in a particular
|
||||
file, then You may include the notice in a location (such as a LICENSE
|
||||
file in a relevant directory) where a recipient would be likely to look
|
||||
for such a notice.
|
||||
|
||||
You may add additional accurate notices of copyright ownership.
|
||||
|
||||
Exhibit B - "Incompatible With Secondary Licenses" Notice
|
||||
---------------------------------------------------------
|
||||
|
||||
This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
defined by the Mozilla Public License, v. 2.0.
|
444
node_modules/intel/README.md
generated
vendored
Normal file
444
node_modules/intel/README.md
generated
vendored
Normal file
@@ -0,0 +1,444 @@
|
||||
# intel
|
||||
|
||||
[](https://travis-ci.org/seanmonstar/intel)
|
||||

|
||||
[](http://badge.fury.io/js/intel)
|
||||
|
||||
An abbreviation of intelligence. In this case, the acquirement of information.
|
||||
|
||||
> I'm ganna need more intel.
|
||||
|
||||
## Motivation
|
||||
|
||||
- hierarchial named loggers
|
||||
- powerful config
|
||||
- console injection works with all libraries
|
||||
- fast where possible
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [Logging](#logging)
|
||||
- [Using Default Logger](#using-default-logger)
|
||||
- [String Interpolation](#string-interpolation)
|
||||
- [Setting the Log Level](#setting-the-log-level)
|
||||
- [Adding a Handler](#adding-a-handler)
|
||||
- [Getting Named Loggers](#getting-a-named-logger)
|
||||
- [Logging Exceptions](#logging-exceptions)
|
||||
- [Handlers](#handlers)
|
||||
- [ConsoleHandler](#consolehandler)
|
||||
- [StreamHandler](#streamhandler)
|
||||
- [FileHandler](#filehandler)
|
||||
- [NullHandler](#nullhandler)
|
||||
- [Creating a Custom Handler](#creating-a-custom-handler)
|
||||
- [Filters](#filters)
|
||||
- [Formatters](#formatters)
|
||||
- [LogRecord Formatting](#logrecord)
|
||||
- [config](#config)
|
||||
- [basicConfig](#basicconfig)
|
||||
- [Full Configuration](#full-configuration)
|
||||
- [console](#console)
|
||||
- [debug()](#console.debug)
|
||||
|
||||
## Logging
|
||||
|
||||
### Using Default Logger
|
||||
|
||||
To get started right away, intel provides a default logger. The module itself is an instance of a `Logger`.
|
||||
|
||||
```js
|
||||
require('intel').info('Hello intel');
|
||||
```
|
||||
|
||||
### String interpolation
|
||||
|
||||
You can log messages using interpolation just as you can when using the `console.log` API:
|
||||
|
||||
```js
|
||||
require('intel').info('Situation %s!', 'NORMAL');
|
||||
```
|
||||
|
||||
### Setting the Log Level
|
||||
|
||||
Loggers have a log level that is compared against log messages. All messages that are of a lower level than the Logger are ignored. This is useful to reduce less important messages in production deployments.
|
||||
|
||||
```js
|
||||
var intel = require('intel');
|
||||
intel.setLevel(intel.WARN);
|
||||
intel.warn('i made it!');
|
||||
intel.debug('nobody loves me');
|
||||
```
|
||||
|
||||
All levels by order: (each level has a corresponding method on a Logger)
|
||||
|
||||
```js
|
||||
intel.TRACE // intel.trace()
|
||||
intel.VERBOSE // intel.verbose()
|
||||
intel.DEBUG // intel.debug()
|
||||
intel.INFO // intel.info()
|
||||
intel.WARN // intel.warn()
|
||||
intel.ERROR // intel.error()
|
||||
intel.CRITICAL // intel.critical()
|
||||
```
|
||||
|
||||
Useful levels that don't have accompanying logger methods are `intel.NONE` and `intel.ALL`.
|
||||
|
||||
### Adding a Handler
|
||||
|
||||
The default logger will use a [ConsoleHandler](#consolehandler) if you don't specify anything else. You can add handlers to any logger:
|
||||
|
||||
```js
|
||||
var intel = require('intel');
|
||||
intel.addHandler(new intel.handlers.File('/path/to/file.log'));
|
||||
|
||||
intel.info('going to a file!');
|
||||
```
|
||||
|
||||
You can remove all handlers from a particular logger with `logger.removeAllHandlers()`.
|
||||
|
||||
### Getting a Named Logger
|
||||
|
||||
Using named loggers gives you a lot of power in `intel`. First, the logger name can be included in the log message, so you can more easily understand where log messages are happening inside your application.
|
||||
|
||||
```js
|
||||
var log = require('intel').getLogger('foo.bar.baz');
|
||||
log.setLevel(log.INFO).warn('baz reporting in');
|
||||
```
|
||||
|
||||
The names are used to build an hierarchy of loggers. Child loggers can inherit their parents' handlers and log level.
|
||||
|
||||
```js
|
||||
var intel = require('intel');
|
||||
var alpha = intel.getLogger('alpha');
|
||||
alpha.setLevel(intel.WARN).addHandler(new intel.handlers.File('alpha.log'));
|
||||
|
||||
var bravo = intel.getLogger('alpha.bravo');
|
||||
bravo.verbose('hungry') // ignored, since alpha has level of WARN
|
||||
bravo.warn('enemy spotted'); // logged to alpha.log
|
||||
```
|
||||
|
||||
The power of logger hierarchies can seen more when using [intel.config](#config).
|
||||
|
||||
### Logging Exceptions
|
||||
|
||||
Any time you pass an exception (an `Error`!) to a log method, the stack
|
||||
will be included in the output. In most cases, it will be appended at
|
||||
the end of the message. If the format is `%O`, meaning JSON output, a
|
||||
stack property will be included.
|
||||
|
||||
```js
|
||||
intel.error('ermahgawd', new Error('boom'));
|
||||
```
|
||||
|
||||
Loggers can also handle `uncaughtException`, passing it to its handlers,
|
||||
and optionally exiting afterwards.
|
||||
|
||||
```js
|
||||
var logger = intel.getLogger('medbay');
|
||||
logger.handleExceptions(exitOnError);
|
||||
```
|
||||
|
||||
Pass a boolean for `exitOnError`. Default is `true` if no value is passed.
|
||||
|
||||
## Handlers
|
||||
|
||||
Loggers build a message and try to pass the message to all of it's handlers and to it's parent. Handlers determine exactly what to do with that message, whether it's sending it to console, to a file, over a socket, or nothing at all.
|
||||
|
||||
All Handlers have a `level` and a [`Formatter`](#formatters).
|
||||
|
||||
```js
|
||||
new intel.Handler({
|
||||
level: intel.WARN, // default is NOTSET
|
||||
formatter: new intel.Formatter(), // default formatter
|
||||
timeout: 5000 // default is 5seconds
|
||||
});
|
||||
```
|
||||
|
||||
Just like Loggers, if a message's level is not equal to or greater than the Handler's level, the Handler won't even be given the message.
|
||||
|
||||
### ConsoleHandler
|
||||
|
||||
```js
|
||||
new intel.handlers.Console(options);
|
||||
```
|
||||
|
||||
The Console handler outputs messages to the `stdio`, just like `console.log()` would.
|
||||
|
||||
### StreamHandler
|
||||
|
||||
```js
|
||||
new intel.handlers.Stream(streamOrOptions);
|
||||
```
|
||||
|
||||
The Stream handler can take any writable stream, and will write messages to the stream. The [Console](#consolehandler) handler essentially uses 2 Stream handlers internally pointed at `process.stdout` and `process.stderr`.
|
||||
|
||||
- **stream**: Any [WritableStream](http://nodejs.org/api/stream.html#stream_class_stream_writable)
|
||||
- Plus options from [Handler](#handlers)
|
||||
|
||||
As a shortcut, you can pass the `stream` directly to the constructor, and all other options will just use default values.
|
||||
|
||||
### FileHandler
|
||||
|
||||
```js
|
||||
new intel.handlers.File(filenameOrOptions);
|
||||
```
|
||||
|
||||
The File handler will write messages to a file on disk. It extends the [Stream](#streamhandler) handler, by using the `WritableStream` created from the filename.
|
||||
|
||||
- **file**: A string of a filename to write messages to.
|
||||
- Plus options from [Handler](#handlers)
|
||||
|
||||
As a shortcut, you can pass the `file` String directly to the constructor, and all other options will just use default values.
|
||||
|
||||
### NullHandler
|
||||
|
||||
```js
|
||||
new intel.handlers.Null();
|
||||
```
|
||||
|
||||
The Null handler will do nothing with received messages. This can useful if there's instances where you wish to quiet certain loggers when in production (or enemy territory).
|
||||
|
||||
### Creating Custom Handlers
|
||||
|
||||
Adding a new custom handler that isn't included in intel is a snap. Just make a subclass of [Handler](#handlers), and implement the `emit` method.
|
||||
|
||||
```js
|
||||
const util = require('util');
|
||||
const intel = require('intel');
|
||||
|
||||
function CustomHandler(options) {
|
||||
intel.Handler.call(this, options);
|
||||
// whatever setup you need
|
||||
}
|
||||
// don't forget to inhert from Handler (or a subclass, like Stream)
|
||||
util.inherits(CustomHandler, intel.Handler);
|
||||
|
||||
CustomHandler.prototype.emit = function customEmit(record) {
|
||||
// do whatever you need to with the log record
|
||||
// this could be storing it in a db, or sending an email, or sending an HTTP request...
|
||||
// if you want the message formatted:
|
||||
// str = this.format(record);
|
||||
}
|
||||
```
|
||||
|
||||
A list of known Handlers is kept on the [wiki](https://github.com/seanmonstar/intel/wiki/Custom-Handlers).
|
||||
|
||||
## Filters
|
||||
|
||||
You can already plug together handlers and loggers, with varying levels, to get powerful filtering of messages. However, sometimes you really need to filter on a specific detail on a message. You can add these filters to a [Handler](#handlers) or [Logger](#logging).
|
||||
|
||||
```js
|
||||
intel.addFilter(new intel.Filter(/^foo/g));
|
||||
intel.addFilter(new intel.Filter('patrol.db'));
|
||||
intel.addFilter(new intel.Filter(filterFunction));
|
||||
```
|
||||
|
||||
Filters come in 3 forms:
|
||||
|
||||
- **string** - pass a string to filter based on Logger name. So, `Filter('foo.bar')` will allow messages from `foo.bar`, `foo.bar.baz`, but not `foo.barstool`.
|
||||
- **regexp** - pass a RegExp to filter based on the text content of the log message. So, `Filter(/^foo/g)` will allow messages like `log.info('foo bar')` but not `log.info('bar baz foo')`;
|
||||
- **function** - pass a function that receives a [LogRecord](#logrecord) object, and returns true if the record meets the filter.
|
||||
|
||||
## Formatters
|
||||
|
||||
```js
|
||||
new intel.Formatter(formatOrOptions);
|
||||
```
|
||||
|
||||
A `Formatter` is used by a [`Handler`](#handlers) to format the message before being sent out. An useful example is wanting logs that go to the [Console](#consolehandler) to be terse and easy to read, but messages sent to a [File](#filehandler) to include a lot more detail.
|
||||
|
||||
- **format**: A format string that will be used with `printf`. Default: `%(message)s`
|
||||
- **datefmt**: A string to be used to format the date. Will replace instances of `%(date)s` in the `format` string. Default: `%Y-%m-%d %H:%M-%S`. See [samsonjs/strftime](https://github.com/samsonjs/strftime#supported-specifiers) for supported specifiers.
|
||||
- **strip**: A boolean for whether to strip [ANSI escape codes](http://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles) from the `message` and `args`. Default: `false`
|
||||
- **colorize**: A boolean for whether to colorize the `levelname`. Disabled when `strip` is used. Default: `false`
|
||||
|
||||
### LogRecord
|
||||
|
||||
The record that is created by loggers is passed to each handler, and handlers pass it to formatters to do their formatting.
|
||||
|
||||
```js
|
||||
{
|
||||
name: "foo.bar",
|
||||
level: 30,
|
||||
levelname: "DEBUG",
|
||||
timestamp: new Date(),
|
||||
message: "all clear",
|
||||
args: [],
|
||||
stack: undefined, // if an Error was passed, or trace()
|
||||
exception: false, // if an Error was passed
|
||||
uncaughtException: false // if passed Error was from process.on('uncaughtException')
|
||||
}
|
||||
```
|
||||
|
||||
You can output the values from these properties using the [Formatter](#formatters) and a string with `%(property)s`. Some example format strings:
|
||||
|
||||
- `%(name)s.%(levelname)s: %(message)s`: foo.bar.DEBUG: all clear
|
||||
- `[%(date)s] %(name)s:: %(message)s`: \[2013-09-18 11:29:32\] foo.bar:: all clear
|
||||
|
||||
#### printf
|
||||
|
||||
The `printf` bundled in intel does basic string interpolation. It can
|
||||
get named properties from an argument, or output several arguments. It
|
||||
can truncate, pad, or indent, and convert values.
|
||||
|
||||
Conversion types:
|
||||
|
||||
- `s` - String. Example: `printf('%s', new Error('foo'))` creates `Error: foo`
|
||||
- `d` - Number.
|
||||
- `j` and `O` - JSON. `JSON.stringify` the value.
|
||||
- `?` - Default. Will output a sane default conversion based on argument type.
|
||||
|
||||
Conversion flags:
|
||||
|
||||
- `:1` - Indent a JSON format with spaces based on number after colon.
|
||||
Example: `printf('%:2j', { a: 'b' })` would indent the `"a": "b"` by 2
|
||||
spaces. Ignored on other conversion types.
|
||||
- `3` - A number will pad the output. Example: `printf('%5s', 'abc')`
|
||||
returns `' abc'`.
|
||||
- `-3` - Pads on the right side. Example: `printf('%-5s', 'abc')`
|
||||
returns `'abc '`.
|
||||
- `.2` - Truncates to specified length. Example: `printf('%.3s', 12345)`
|
||||
returns `'345'`.
|
||||
- `.-2` - Truncates on the right side. Example: `printf('%.-3s', 12345)`
|
||||
returns `'123'`.
|
||||
|
||||
## config
|
||||
|
||||
Once you understand the power of intel's [named loggers](#getting-a-named-logger), you'll appreciate being able to quickly configure logging in your application.
|
||||
|
||||
### basicConfig
|
||||
|
||||
The basicConfig is useful if you don't wish to do any complicated configuration (no way, really?). It's a quick way to setup the root default logger in one function call. Note that if you don't setup any handlers before logging, `basicConfig` will be called to setup the default logger.
|
||||
|
||||
```js
|
||||
intel.basicConfig({
|
||||
'file': '/path/to/file.log', // file and stream are exclusive. only pass 1
|
||||
'stream': stream,
|
||||
'format': '%(message)s',
|
||||
'level': intel.INFO
|
||||
});
|
||||
```
|
||||
|
||||
The options passed to basicConfig can include:
|
||||
- **file** - filename to log
|
||||
- **stream** - any WritableStream
|
||||
- **format** - a format string
|
||||
- **level** - the log level
|
||||
|
||||
You cannot pass a `file` and `stream` to basicConfig. If you don't provide either, a [Console](#consolehandler) handler will be used. If you wish to specify multiple or different handlers, take a look at the more comprehensive [config](#full-configuration).
|
||||
|
||||
### Full Configuration
|
||||
|
||||
```js
|
||||
intel.config({
|
||||
formatters: {
|
||||
'simple': {
|
||||
'format': '[%(levelname)s] %(message)s',
|
||||
'colorize': true
|
||||
},
|
||||
'details': {
|
||||
'format': '[%(date)s] %(name)s.%(levelname)s: %(message)s',
|
||||
'strip': true
|
||||
}
|
||||
},
|
||||
filters: {
|
||||
'db': 'patrol.db'
|
||||
},
|
||||
handlers: {
|
||||
'terminal': {
|
||||
'class': intel.handlers.Console,
|
||||
'formatter': 'simple',
|
||||
'level': intel.VERBOSE
|
||||
},
|
||||
'logfile': {
|
||||
'class': intel.handlers.File,
|
||||
'level': intel.WARN,
|
||||
'file': '/var/log/report.log',
|
||||
'formatter': 'details',
|
||||
'filters': ['db']
|
||||
}
|
||||
},
|
||||
loggers: {
|
||||
'patrol': {
|
||||
'handlers': ['terminal'],
|
||||
'level': 'INFO',
|
||||
'handleExceptions': true,
|
||||
'exitOnError': false,
|
||||
'propagate': false
|
||||
},
|
||||
'patrol.db': {
|
||||
'handlers': ['logfile'],
|
||||
'level': intel.ERROR
|
||||
},
|
||||
'patrol.node_modules.express': { // huh what? see below :)
|
||||
'handlers': ['logfile'],
|
||||
'level': 'WARN'
|
||||
}
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
We set up 2 handlers, one [Console](#consolehandler) with a level of `VERBOSE` and a simple format, and one [File](#filehandler) with a level of `WARN` and a detailed format. We then set up a few options on loggers. Not all loggers need to be defined here, as child loggers will inherit from their parents. So, the root logger that we'll use in this application is `patrol`. It will send all messages that are `INFO` and greater to the the terminal. We also specifically want database errors to be logged to the our log file. And, there's a logger for express? What's that all about? See the [intel.console](#console) section.
|
||||
|
||||
Config also accepts JSON, simply put a require path in any `class` properties.
|
||||
|
||||
```js
|
||||
// logging.json
|
||||
{
|
||||
"handlers": {
|
||||
"foo": {
|
||||
"class": "intel/handlers/console"
|
||||
}
|
||||
}
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
```js
|
||||
intel.config(require('./logging.json'));
|
||||
```
|
||||
|
||||
Passing a `handlers` option to `intel.config` will remove the default ROOT console handler, unless you've previously manually assigned handlers to `intel`.
|
||||
|
||||
## console
|
||||
|
||||
```js
|
||||
require('intel').console();
|
||||
```
|
||||
|
||||
So, a problem with logging libraries is trying to get them to work with 3rd party modules. Many libraries may benefit from logging when certain things occur, but can't really pick a logging library, since that sort of choice should be up to the app developer. The only real options they have are to not log anything, or to use `console.log`. So really, they should [console.log() all the the things](http://seanmonstar.com/post/56448644049/console-log-all-the-things), and `intel` can work just fine with that.
|
||||
|
||||
Intel has the ability to override the global `console`, such that calling any of it's methods will send it through a [Logger](#logging). This means that messages from other libraries can be sent to your log files, or through an email, or whatever. Even better, `intel` will automatically derive a name for the each module that access `console.log` (or `info`, `warn`, `dir`, `trace`, etc). In the [config](#full-configuration) example, we set up rules for `patrol.node_modules.express`. If `express` were to log things as it handled requests, they would all derive a name that was a child of our logger. So, in case it's chatty, we're only interesting in `WARN` or greater messages, and send those to a log file.
|
||||
|
||||
It tries its darndest to best guess a name, by comparing the relative paths from the `root` and the module accessing `console`. By default, the `root` is equal to the `dirname` of the module where you call `intel.console()`.
|
||||
|
||||
Options:
|
||||
|
||||
- **root** - String to define root logger, defaults to calling module's filename
|
||||
- **ignore** - Array of strings of log names that should be ignored and use standard `console` methods. Ex: `['intel.node_modules.mocha']`
|
||||
- **debug** - boolean or String. `true` will set `process.env.DEBUG='*'`. Otherwise, String is used, ex: `'request,express'`
|
||||
|
||||
```js
|
||||
// file: patrol/index.js
|
||||
require('intel').console(); // root is '/path/to/patrol'
|
||||
```
|
||||
|
||||
If you override the console in a file deep inside some directories, you can manually set the root as an option:
|
||||
|
||||
```js
|
||||
// file: patrol/lib/utils/log.js
|
||||
require('intel').console({ root: '/path/to/patrol' });
|
||||
```
|
||||
### console.debug
|
||||
|
||||
The `debug` option for `intel.console()`, huh? Yea, so many libraries use the `debug()` library to handle their internal logging needs. It works by not outputing any logs unless you opt-in with an environment variable. In many case, it would make sense to just leave this off, to keep the noise down. However, you can use this option to turn on a libraries logging, and route it into properly named loggers. Since the `debug` module checks `process.env` at require time, you will need to use this option firstmost, before requiring anything else that may require `debug`.
|
||||
|
||||
Example
|
||||
|
||||
```js
|
||||
// file: patrol/index.js
|
||||
require('intel').console({ debug: 'request,express' });
|
||||
var request = require('request');
|
||||
|
||||
request.get('http://example.domain');
|
||||
// log messages will appear from "patrol.node_modules.request"
|
||||
```
|
157
node_modules/intel/lib/config.js
generated
vendored
Normal file
157
node_modules/intel/lib/config.js
generated
vendored
Normal file
@@ -0,0 +1,157 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
const path = require('path');
|
||||
const util = require('util');
|
||||
|
||||
const intel = require('./');
|
||||
const Formatter = require('./formatter');
|
||||
const Filter = require('./filter');
|
||||
|
||||
const INTEL_PREFIX = 'intel/';
|
||||
|
||||
function req(str, root) {
|
||||
if (str.indexOf(INTEL_PREFIX) === 0) {
|
||||
str = str.replace(INTEL_PREFIX, './');
|
||||
} else if (str.indexOf('./') === 0 || str.indexOf('../') === 0) {
|
||||
str = path.join(root || process.cwd(), str);
|
||||
}
|
||||
return require(str);
|
||||
}
|
||||
|
||||
function isObject(value) {
|
||||
return Object.prototype.toString.call(value) === '[object Object]';
|
||||
}
|
||||
|
||||
|
||||
function evalFunction(source) {
|
||||
/*jshint evil:true*/
|
||||
var fn = Function('return (' + String(source).trim() + ');')();
|
||||
if (!(fn instanceof Function)) {
|
||||
throw new Error('function parameter did not parse as a function');
|
||||
}
|
||||
return fn;
|
||||
}
|
||||
|
||||
function configureFormatter(formatter, options) {
|
||||
if (formatter.formatFn) {
|
||||
var customFormatter = new Formatter();
|
||||
if (formatter.formatFn instanceof Function) {
|
||||
customFormatter.format = formatter.formatFn;
|
||||
} else {
|
||||
customFormatter.format = evalFunction(formatter.formatFn);
|
||||
}
|
||||
return customFormatter;
|
||||
}
|
||||
var FormatterClass = formatter['class'] || Formatter;
|
||||
if (typeof FormatterClass === 'string') {
|
||||
FormatterClass = req(FormatterClass, options.root);
|
||||
}
|
||||
return new FormatterClass(formatter);
|
||||
}
|
||||
|
||||
function configureFilter(filterOptions, options) {
|
||||
|
||||
var FilterClass = filterOptions['class'] || Filter;
|
||||
if (typeof FilterClass === 'string') {
|
||||
FilterClass = req(FilterClass, options.root);
|
||||
}
|
||||
if (isObject(filterOptions)) {
|
||||
var fOpts = filterOptions;
|
||||
var re = fOpts.regexp || fOpts.regex || fOpts.re;
|
||||
var fn = fOpts.function || fOpts.fn;
|
||||
if (re) {
|
||||
filterOptions = new RegExp(re, fOpts.flags);
|
||||
} else if (fn) {
|
||||
filterOptions = evalFunction(fn);
|
||||
}
|
||||
}
|
||||
return new FilterClass(filterOptions);
|
||||
}
|
||||
|
||||
function configureHandler(handler, options) {
|
||||
var HandlerClass = handler['class'];
|
||||
if (typeof HandlerClass === 'string') {
|
||||
HandlerClass = req(HandlerClass, options.root);
|
||||
}
|
||||
delete handler['class'];
|
||||
if (handler.formatter) {
|
||||
handler.formatter = options.formatters[handler.formatter];
|
||||
}
|
||||
var hndlr = new HandlerClass(handler);
|
||||
if (handler.filters) {
|
||||
handler.filters.forEach(function eachHandler(fname) {
|
||||
hndlr.addFilter(options.filters[fname]);
|
||||
});
|
||||
}
|
||||
return hndlr;
|
||||
}
|
||||
|
||||
function getHandler(name, options) {
|
||||
var handler = options.handlers && options.handlers[name];
|
||||
if (!handler) {
|
||||
var errStr = util.format('Handler "%s" is not defined in config', name);
|
||||
throw new Error(errStr);
|
||||
}
|
||||
if (typeof handler.handle !== 'function') {
|
||||
handler = options.handlers[name] = configureHandler(handler, options);
|
||||
}
|
||||
return handler;
|
||||
}
|
||||
|
||||
function configureLogger(name, loggerOptions, options) {
|
||||
var logger = intel.getLogger(name);
|
||||
if (loggerOptions.level != null) {
|
||||
logger.setLevel(loggerOptions.level);
|
||||
}
|
||||
|
||||
if (loggerOptions.handlers) {
|
||||
loggerOptions.handlers.forEach(function eachHandler(hName) {
|
||||
logger.addHandler(getHandler(hName, options));
|
||||
});
|
||||
}
|
||||
if (loggerOptions.filters) {
|
||||
loggerOptions.filters.forEach(function eachHandler(fname) {
|
||||
logger.addFilter(options.filters[fname]);
|
||||
});
|
||||
}
|
||||
|
||||
if (loggerOptions.propagate != null) {
|
||||
logger.propagate = loggerOptions.propagate;
|
||||
}
|
||||
|
||||
if (loggerOptions.handleExceptions) {
|
||||
logger.handleExceptions(loggerOptions.exitOnError);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = function config(options) {
|
||||
// lets do formatters and filters first, since they dont depend on anything
|
||||
// then handlers, since they can depend on formatters
|
||||
// and then loggers, since they can depend on handlers
|
||||
|
||||
var formatters = options.formatters || {};
|
||||
for (var f in formatters) {
|
||||
formatters[f] = configureFormatter(formatters[f], options);
|
||||
}
|
||||
|
||||
var filters = options.filters || {};
|
||||
for (var fi in filters) {
|
||||
filters[fi] = configureFilter(filters[fi], options);
|
||||
}
|
||||
|
||||
if (options.handlers) {
|
||||
intel.basicConfig({ null: true});
|
||||
}
|
||||
|
||||
var loggers = options.loggers || {};
|
||||
for (var l in loggers) {
|
||||
configureLogger(l, loggers[l], options);
|
||||
}
|
||||
|
||||
if (options.console) {
|
||||
var consoleOpts = isObject(options.console) ? options.console : {};
|
||||
consoleOpts.__trace = config;
|
||||
intel.console(consoleOpts);
|
||||
}
|
||||
};
|
307
node_modules/intel/lib/console.js
generated
vendored
Normal file
307
node_modules/intel/lib/console.js
generated
vendored
Normal file
@@ -0,0 +1,307 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const path = require('path');
|
||||
const util = require('util');
|
||||
|
||||
const chalk = require('chalk');
|
||||
const dbug = require('dbug');
|
||||
const stack = require('stack-trace');
|
||||
const utc = require('utcstring');
|
||||
|
||||
const intel = require('./');
|
||||
|
||||
const ALIASES = [
|
||||
'trace',
|
||||
'debug',
|
||||
'info',
|
||||
'warn',
|
||||
'error'
|
||||
];
|
||||
|
||||
function copyProperties(source, target, props) {
|
||||
props.forEach(function(prop) {
|
||||
target[prop] = source[prop];
|
||||
});
|
||||
}
|
||||
|
||||
var ORIGINAL_METHODS = {};
|
||||
const METHOD_NAMES = [
|
||||
'trace',
|
||||
'debug',
|
||||
'dir',
|
||||
'error',
|
||||
'info',
|
||||
'log',
|
||||
'warn'
|
||||
];
|
||||
|
||||
var ORIGINAL_STDERR;
|
||||
|
||||
function endsWith(str, suffix) {
|
||||
return str.indexOf(suffix, str.length - suffix.length) !== -1;
|
||||
}
|
||||
|
||||
var root;
|
||||
var ignore;
|
||||
var parentLogger;
|
||||
var basename;
|
||||
|
||||
function getLoggerName(debugName) {
|
||||
var trace = stack.get();
|
||||
// walk up the stack until we find a function that isn't from this
|
||||
// module. that's the calling module.
|
||||
// ALSO: 'console.js' could be on the stack if console.trace() or
|
||||
// something similar was called, cause we don't modify those, since
|
||||
// they internally call console.log(), which is us!
|
||||
var filename;
|
||||
var debug = [];
|
||||
if (debugName) {
|
||||
debug = [
|
||||
// debug@0.x
|
||||
path.join('node_modules', 'debug', 'lib', 'debug.js'),
|
||||
// debug@1.x
|
||||
path.join('node_modules', 'debug', 'node.js'),
|
||||
path.join('node_modules', 'debug', 'debug.js'),
|
||||
// dbug@0.x
|
||||
path.join('node_modules', 'dbug', 'lib', 'dbug.js'),
|
||||
path.join('node_modules', 'dbug', 'index.js')
|
||||
];
|
||||
}
|
||||
|
||||
function skip(name) {
|
||||
if (name === __filename || name === 'console.js') {
|
||||
return true;
|
||||
}
|
||||
return debug.some(function(d) {
|
||||
return endsWith(name, d);
|
||||
});
|
||||
}
|
||||
|
||||
for (var i = 0, len = trace.length; i < len; i++) {
|
||||
filename = path.normalize(trace[i].getFileName());
|
||||
if (!skip(filename)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
var topName = basename || path.basename(root);
|
||||
topName = topName.replace(path.extname(topName), '');
|
||||
|
||||
var moduleName = path.join(topName, path.relative(root, filename));
|
||||
moduleName = moduleName.replace(path.extname(moduleName), '');
|
||||
moduleName = moduleName.replace(/[\\\/]/g, '.');
|
||||
|
||||
// lib is the defacto place to store js files, but removing lib looks
|
||||
// better: connect.lib.session -> connect.session
|
||||
moduleName = moduleName.replace(/\.lib\./g, '.');
|
||||
|
||||
// index.js filename shouldn't be used, since it's really the folder
|
||||
// up. better: gryphon.index -> gryphon
|
||||
moduleName = moduleName.replace(/\.index/g, '');
|
||||
|
||||
|
||||
if (debugName) {
|
||||
// clean up duplicated parts of the name
|
||||
// ex: node_modules.intel.logger.intel.logger =>
|
||||
// node_modules.intel.logger
|
||||
if (!endsWith(moduleName, debugName)) {
|
||||
moduleName += '.' + debugName;
|
||||
}
|
||||
}
|
||||
|
||||
if (parentLogger) {
|
||||
moduleName = parentLogger + '.' + moduleName;
|
||||
}
|
||||
|
||||
return moduleName;
|
||||
}
|
||||
|
||||
function setRoot(r) {
|
||||
root = r;
|
||||
}
|
||||
|
||||
function setIgnore(i) {
|
||||
if (typeof i === 'string') {
|
||||
i = [i];
|
||||
}
|
||||
ignore = i;
|
||||
}
|
||||
|
||||
const DEBUG_COLORED_RE = new RegExp([
|
||||
'^',
|
||||
' ', // starts with 2 spaces. yea really
|
||||
'\\u001b\\[\\d{1,2};1m', // colored debug has colors
|
||||
'(.+)', // logger name
|
||||
'\\u001b\\[\\d?0m', // color end
|
||||
'(.+)', // message
|
||||
'\n?', // debug 2.0 addes a newline
|
||||
'$'
|
||||
].join(''));
|
||||
|
||||
const DBUG_LEVELS = ['debug', 'info', 'warn', 'error'];
|
||||
|
||||
|
||||
function getLoggerLevel(name) {
|
||||
var i = DBUG_LEVELS.length;
|
||||
while (i--) {
|
||||
var level = DBUG_LEVELS[i];
|
||||
if (endsWith(name, '.' + level)) {
|
||||
return level;
|
||||
}
|
||||
}
|
||||
return 'debug';
|
||||
}
|
||||
|
||||
function dbugName(name) {
|
||||
if (!name) {
|
||||
return;
|
||||
}
|
||||
if (name.indexOf('.') === -1) {
|
||||
return name;
|
||||
}
|
||||
var level = getLoggerLevel(name.toLowerCase());
|
||||
level = new RegExp('\\.' + level + '$', 'i');
|
||||
return name.replace(level, '');
|
||||
}
|
||||
|
||||
|
||||
function parseDebug(args) {
|
||||
// O_O
|
||||
// Dear reader: I'm so sorry.
|
||||
var str = String(args[0]);
|
||||
|
||||
// is it colored debug() ?
|
||||
var match = str.match(DEBUG_COLORED_RE);
|
||||
if (match) {
|
||||
var logger = chalk.stripColor(match[1]).trim();
|
||||
var msg = chalk.stripColor(match[2]).trim();
|
||||
args[0] = msg; // overwrite the message portion
|
||||
return logger.replace(/:/g, '.');
|
||||
} else if (utc.has(str)) {
|
||||
str = str.replace(utc.get(str), '').trim();
|
||||
var logger = str.split(' ').shift();
|
||||
var msg = str.replace(logger, '').trim();
|
||||
args[0] = msg;
|
||||
return logger.replace(/:/g, '.');
|
||||
}
|
||||
}
|
||||
|
||||
// cached loggers that hook into dbug.__log
|
||||
// this way, we don't format a level message, and then parse it with
|
||||
// regex, just to format a new message in intel
|
||||
// ALSO: we only get a stacktrace once, and then save the name, so
|
||||
// PERFORMANCE WIN!
|
||||
var dbugLoggers = {};
|
||||
function dbugHook(name, level, args) {
|
||||
var logger = dbugLoggers[name];
|
||||
if (!logger) {
|
||||
logger = dbugLoggers[name] =
|
||||
intel.getLogger(getLoggerName(name.replace(/:/g, '.')));
|
||||
}
|
||||
logger[level].apply(logger, args);
|
||||
}
|
||||
|
||||
var isDebugging = false;
|
||||
var __log = dbug.__log;
|
||||
function setDebug(debug) {
|
||||
if (debug === true) {
|
||||
process.env.DEBUG = dbug.env = '*';
|
||||
} else if (debug === false) {
|
||||
process.env.DEBUG = dbug.env = '';
|
||||
} else if (debug) {
|
||||
if (process.env.DEBUG) {
|
||||
process.env.DEBUG += ',' + debug;
|
||||
dbug.env = process.env.DEBUG;
|
||||
} else {
|
||||
process.env.DEBUG = dbug.env = '' + debug;
|
||||
}
|
||||
}
|
||||
isDebugging = !!debug;
|
||||
dbug.__log = dbugHook;
|
||||
}
|
||||
|
||||
function setLoggerBaseName(bn){
|
||||
basename = bn;
|
||||
}
|
||||
|
||||
function deliver(method, args) {
|
||||
var debugged = isDebugging && parseDebug(args);
|
||||
var name = getLoggerName(dbugName(debugged));
|
||||
var i = ignore.length;
|
||||
var logger = intel.getLogger(name);
|
||||
name = logger._name;
|
||||
while (i--) {
|
||||
if (name.indexOf(ignore[i]) === 0) {
|
||||
if (method === 'stderr') {
|
||||
ORIGINAL_STDERR.call(process.stderr, args[0]);
|
||||
} else {
|
||||
ORIGINAL_METHODS[method].apply(console, args);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (debugged) {
|
||||
method = getLoggerLevel(debugged);
|
||||
}
|
||||
var level = ALIASES.indexOf(method) !== -1 ? method : 'debug';
|
||||
logger[level].apply(logger, args);
|
||||
}
|
||||
|
||||
|
||||
function overrideConsole(options) {
|
||||
options = options || {};
|
||||
setRoot(options.root || path.join(
|
||||
stack.get(options.__trace || overrideConsole)[0].getFileName(),
|
||||
'..'
|
||||
));
|
||||
setIgnore(options.ignore || []);
|
||||
parentLogger = options.logger;
|
||||
|
||||
setDebug(options.debug);
|
||||
|
||||
setLoggerBaseName(options.basename);
|
||||
if (!ORIGINAL_METHODS.log) {
|
||||
copyProperties(console, ORIGINAL_METHODS, METHOD_NAMES);
|
||||
}
|
||||
|
||||
if (!ORIGINAL_STDERR) {
|
||||
ORIGINAL_STDERR = process.stderr.write;
|
||||
}
|
||||
|
||||
ALIASES.forEach(function(method) {
|
||||
console[method] = function alias(){
|
||||
deliver(method, arguments);
|
||||
};
|
||||
});
|
||||
|
||||
console.log = function log() {
|
||||
deliver('log', arguments);
|
||||
};
|
||||
|
||||
console.dir = function dir(obj) {
|
||||
deliver('dir', [util.inspect(obj)]);
|
||||
};
|
||||
|
||||
process.stderr.write = function write(str) {
|
||||
deliver('stderr', [str]);
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
function restoreConsole() {
|
||||
for (var name in ORIGINAL_METHODS) {
|
||||
if (ORIGINAL_METHODS.hasOwnProperty(name) && ORIGINAL_METHODS[name]) {
|
||||
console[name] = ORIGINAL_METHODS[name];
|
||||
}
|
||||
}
|
||||
copyProperties({}, ORIGINAL_METHODS, METHOD_NAMES);
|
||||
dbug.__log = __log;
|
||||
if (ORIGINAL_STDERR) {
|
||||
process.stderr.write = ORIGINAL_STDERR;
|
||||
ORIGINAL_STDERR = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = overrideConsole;
|
||||
exports.restore = restoreConsole;
|
44
node_modules/intel/lib/filter.js
generated
vendored
Normal file
44
node_modules/intel/lib/filter.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const util = require('util');
|
||||
|
||||
function nameFilter(record) {
|
||||
var filter = this._filter;
|
||||
if (filter === record.name) {
|
||||
return true;
|
||||
} else if (record.name.indexOf(filter) === -1) {
|
||||
return false;
|
||||
} else {
|
||||
return record.name[filter.length] === '.';
|
||||
}
|
||||
}
|
||||
|
||||
function regexpFilter(record) {
|
||||
return this._filter.test(record.message);
|
||||
}
|
||||
|
||||
function Filter(filter) {
|
||||
// valid filters: regexp, string, function
|
||||
var type = typeof filter;
|
||||
if (type === 'function') {
|
||||
this.filter = filter;
|
||||
} else if (type === 'string') {
|
||||
this._filter = filter;
|
||||
this.filter = nameFilter;
|
||||
} else if (util.isRegExp(filter)) {
|
||||
this._filter = filter;
|
||||
this.filter = regexpFilter;
|
||||
}
|
||||
}
|
||||
|
||||
Filter.prototype = {
|
||||
|
||||
filter: function() {
|
||||
throw new Error('Filter type was not defined.');
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
module.exports = Filter;
|
50
node_modules/intel/lib/filterer.js
generated
vendored
Normal file
50
node_modules/intel/lib/filterer.js
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
|
||||
function filter(record) {
|
||||
var i = this._filters.length;
|
||||
while (i--) {
|
||||
if (!this._filters[i].filter(record)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function noop() { return true; }
|
||||
|
||||
function Filterer() {
|
||||
this._filters = [];
|
||||
this.filter = noop;
|
||||
}
|
||||
|
||||
Filterer.prototype = {
|
||||
|
||||
__toggleFilter: function toggleFilter() {
|
||||
this.filter = this.filter === noop ? filter : noop;
|
||||
},
|
||||
|
||||
addFilter: function addFilter(_filter) {
|
||||
if (this._filters.length === 0) {
|
||||
this.__toggleFilter();
|
||||
}
|
||||
this._filters.push(_filter);
|
||||
return this;
|
||||
},
|
||||
|
||||
removeFilter: function removeFilter(_filter) {
|
||||
var index = this._filters.indexOf(_filter);
|
||||
if (index !== -1) {
|
||||
this._filters.splice(index, 1);
|
||||
}
|
||||
if (this._filters.length === 0) {
|
||||
this.__toggleFilter();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
module.exports = Filterer;
|
125
node_modules/intel/lib/formatter.js
generated
vendored
Normal file
125
node_modules/intel/lib/formatter.js
generated
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const chalk = require('chalk');
|
||||
const strftime = require('strftime');
|
||||
const printf = require('./utils/printf');
|
||||
const json = require('./utils/json');
|
||||
|
||||
chalk.enabled = true;
|
||||
|
||||
const COLORS = {
|
||||
'TRACE': chalk.bold.bgBlue,
|
||||
'VERBOSE': chalk.bold.magenta,
|
||||
'DEBUG': chalk.bold.cyan,
|
||||
'INFO': chalk.bold.green,
|
||||
'WARN': chalk.bold.yellow,
|
||||
'ERROR': chalk.bold.red,
|
||||
'CRITICAL': chalk.bold.bgRed
|
||||
};
|
||||
const BOLD = chalk.bold;
|
||||
|
||||
const TO_JSON = '%O';
|
||||
const MESSAGE_ONLY = '%(message)s';
|
||||
const BASIC_FORMAT = '%(name)s.%(levelname)s: %(message)s';
|
||||
|
||||
function messageOnly(record) {
|
||||
return record.message;
|
||||
}
|
||||
function basicFormat(record) {
|
||||
return record.name + '.' + record.levelname + ': ' + record.message;
|
||||
}
|
||||
function sprintf(record) {
|
||||
return printf(this._format, record);
|
||||
}
|
||||
|
||||
function formatDate(record) {
|
||||
record.date = strftime(this._datefmt, new Date(record.timestamp));
|
||||
}
|
||||
|
||||
function noop() {
|
||||
|
||||
}
|
||||
|
||||
function optimize() {
|
||||
switch (this._format) {
|
||||
// faster shortcuts
|
||||
case MESSAGE_ONLY:
|
||||
this.__format = messageOnly;
|
||||
break;
|
||||
case BASIC_FORMAT:
|
||||
this.__format = basicFormat;
|
||||
break;
|
||||
case TO_JSON:
|
||||
this.__format = json;
|
||||
break;
|
||||
// bring on the regexp
|
||||
default:
|
||||
this.__format = sprintf;
|
||||
}
|
||||
|
||||
this.__time = this._usesTime ? formatDate : noop;
|
||||
}
|
||||
|
||||
function Formatter(options) {
|
||||
options = options || {};
|
||||
if (typeof options === 'string') {
|
||||
options = { format: options };
|
||||
}
|
||||
this._format = options.format || this._format;
|
||||
this._datefmt = options.datefmt || this._datefmt;
|
||||
this._strip = options.strip || this._strip;
|
||||
this._colorize = this._strip ? false : options.colorize || this._colorize;
|
||||
this._usesTime = this._format.indexOf('%(date)s') !== -1;
|
||||
|
||||
optimize.call(this);
|
||||
}
|
||||
|
||||
Formatter.prototype = {
|
||||
|
||||
_format: MESSAGE_ONLY,
|
||||
|
||||
_datefmt: '%Y-%m-%d %H:%M:%S',
|
||||
|
||||
_colorize: false,
|
||||
|
||||
_strip: false,
|
||||
|
||||
_usesTime: false,
|
||||
|
||||
format: function format(record) {
|
||||
this.__time(record);
|
||||
|
||||
var levelname = record.levelname;
|
||||
var name = record.name;
|
||||
|
||||
if (this._colorize) {
|
||||
var colorize = COLORS[levelname];
|
||||
if (colorize) {
|
||||
record.levelname = colorize(levelname);
|
||||
}
|
||||
// else levelname doesnt have a color
|
||||
record.name = BOLD(name);
|
||||
}
|
||||
|
||||
var formatted = this.__format(record);
|
||||
|
||||
if (record.stack && this._format !== TO_JSON) {
|
||||
formatted += record.stack;
|
||||
}
|
||||
|
||||
record.levelname = levelname;
|
||||
record.name = name;
|
||||
record.date = undefined;
|
||||
|
||||
if (this._strip) {
|
||||
formatted = chalk.stripColor(formatted);
|
||||
}
|
||||
|
||||
return formatted;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
module.exports = Formatter;
|
33
node_modules/intel/lib/handlers/console.js
generated
vendored
Normal file
33
node_modules/intel/lib/handlers/console.js
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const util = require('util');
|
||||
|
||||
const Handler = require('./handler');
|
||||
const StreamHandler = require('./stream');
|
||||
const LEVELS = require('../levels');
|
||||
|
||||
function ConsoleHandler(options) {
|
||||
options = options || {};
|
||||
options.stream = process.stdout;
|
||||
this._out = new StreamHandler(options);
|
||||
options.stream = process.stderr;
|
||||
this._err = new StreamHandler(options);
|
||||
Handler.call(this, options);
|
||||
}
|
||||
|
||||
util.inherits(ConsoleHandler, Handler);
|
||||
|
||||
ConsoleHandler.prototype.emit = function consoleEmit(record) {
|
||||
var handler = (record.level >= LEVELS.WARN) ? this._err : this._out;
|
||||
handler.emit(record);
|
||||
};
|
||||
|
||||
ConsoleHandler.prototype.setFormatter = function setFormatter(formatter) {
|
||||
Handler.prototype.setFormatter.call(this, formatter);
|
||||
this._out.setFormatter(formatter);
|
||||
this._err.setFormatter(formatter);
|
||||
};
|
||||
|
||||
module.exports = ConsoleHandler;
|
25
node_modules/intel/lib/handlers/file.js
generated
vendored
Normal file
25
node_modules/intel/lib/handlers/file.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const fs = require('fs');
|
||||
const util = require('util');
|
||||
|
||||
const StreamHandler = require('./stream');
|
||||
|
||||
function FileHandler(options) {
|
||||
if (typeof options === 'string') {
|
||||
options = { file: options };
|
||||
}
|
||||
this._file = options.file;
|
||||
|
||||
options.stream = this._open();
|
||||
StreamHandler.call(this, options);
|
||||
}
|
||||
util.inherits(FileHandler, StreamHandler);
|
||||
|
||||
FileHandler.prototype._open = function open() {
|
||||
return fs.createWriteStream(this._file, { flags: 'a' });
|
||||
};
|
||||
|
||||
module.exports = FileHandler;
|
79
node_modules/intel/lib/handlers/handler.js
generated
vendored
Normal file
79
node_modules/intel/lib/handlers/handler.js
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const Formatter = require('../formatter');
|
||||
const Filterer = require('../filterer');
|
||||
const klass = require('../utils/klass');
|
||||
const LEVELS = require('../levels');
|
||||
|
||||
const _defaultFormatter = new Formatter();
|
||||
|
||||
function emit(record) {
|
||||
return this._emit(record);
|
||||
}
|
||||
|
||||
function handleFilter(record) {
|
||||
if (this.filter(record)) {
|
||||
this.__emit(record);
|
||||
}
|
||||
}
|
||||
|
||||
function Handler(options) {
|
||||
if (typeof options !== 'object') {
|
||||
options = { level: options };
|
||||
}
|
||||
var level = options.level;
|
||||
this.setLevel((level !== undefined) ? LEVELS.getLevel(level) : LEVELS.NOTSET);
|
||||
this.setFormatter(options.formatter || _defaultFormatter);
|
||||
this.handle = this.__emit;
|
||||
Filterer.call(this, options);
|
||||
}
|
||||
|
||||
klass(Handler).inherit(Filterer).mixin({
|
||||
|
||||
level: null,
|
||||
|
||||
_formatter: null,
|
||||
|
||||
__toggleFilter: function handlerToggleFilter() {
|
||||
Filterer.prototype.__toggleFilter.call(this);
|
||||
this.handle = this.handle === this.__emit ? handleFilter : this.__emit;
|
||||
},
|
||||
|
||||
// sub-classes should override emit, not handle
|
||||
_emit: function emit(/*record*/) {
|
||||
throw new Error('Handler.emit must be implemented by sub-classes');
|
||||
},
|
||||
|
||||
__emit: emit,
|
||||
|
||||
format: function format(record) {
|
||||
return this._formatter.format(record);
|
||||
},
|
||||
|
||||
setFormatter: function setFormatter(formatter) {
|
||||
this._formatter = formatter;
|
||||
return this;
|
||||
},
|
||||
|
||||
setLevel: function setLevel(level) {
|
||||
this.level = LEVELS.getLevel(level);
|
||||
return this;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Object.defineProperty(Handler.prototype, 'emit', {
|
||||
get: function() {
|
||||
return this._emit;
|
||||
},
|
||||
set: function(val) {
|
||||
if (typeof val !== 'function') {
|
||||
throw new TypeError('emit must be a function');
|
||||
}
|
||||
this._emit = val;
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = Handler;
|
20
node_modules/intel/lib/handlers/index.js
generated
vendored
Normal file
20
node_modules/intel/lib/handlers/index.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
fs.readdirSync(__dirname).forEach(function(file) {
|
||||
if (file === 'index.js' || file === 'handler.js') {
|
||||
return;
|
||||
}
|
||||
|
||||
var handler = file.replace('.js', '');
|
||||
var capital = handler[0].toUpperCase() + handler.substring(1);
|
||||
|
||||
Object.defineProperty(exports, capital, {
|
||||
get: function() {
|
||||
return require('./' + handler);
|
||||
}
|
||||
});
|
||||
});
|
16
node_modules/intel/lib/handlers/null.js
generated
vendored
Normal file
16
node_modules/intel/lib/handlers/null.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const util = require('util');
|
||||
|
||||
const Handler = require('./handler');
|
||||
|
||||
function NullHandler() {
|
||||
Handler.apply(this, arguments);
|
||||
}
|
||||
util.inherits(NullHandler, Handler);
|
||||
|
||||
NullHandler.prototype.emit = function nullEmit(){};
|
||||
|
||||
module.exports = NullHandler;
|
24
node_modules/intel/lib/handlers/stream.js
generated
vendored
Normal file
24
node_modules/intel/lib/handlers/stream.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const util = require('util');
|
||||
|
||||
const Handler = require('./handler');
|
||||
|
||||
function StreamHandler(options) {
|
||||
options = options || {};
|
||||
if (!options.stream) {
|
||||
options = { stream: options };
|
||||
}
|
||||
Handler.call(this, options);
|
||||
this._stream = options.stream;
|
||||
}
|
||||
|
||||
util.inherits(StreamHandler, Handler);
|
||||
|
||||
StreamHandler.prototype.emit = function streamEmit(record) {
|
||||
this._stream.write(this.format(record) + '\n');
|
||||
};
|
||||
|
||||
module.exports = StreamHandler;
|
77
node_modules/intel/lib/index.js
generated
vendored
Normal file
77
node_modules/intel/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const dbug = require('dbug')('intel');
|
||||
|
||||
const Logger = require('./logger');
|
||||
const Handler = require('./handlers/handler');
|
||||
const handlers = require('./handlers');
|
||||
const Formatter = require('./formatter');
|
||||
|
||||
const root = new Logger();
|
||||
|
||||
root.propagate = false;
|
||||
root.setLevel(Logger.TRACE);
|
||||
var oldHandle = root.handle;
|
||||
root.handle = function handle() {
|
||||
if (this._handlers.length === 0) {
|
||||
root.basicConfig();
|
||||
}
|
||||
return oldHandle.apply(this, arguments);
|
||||
};
|
||||
|
||||
const DEFAULT_FORMAT = '%(name)s.%(levelname)s: %(message)s';
|
||||
root.basicConfig = function basicConfig(options) {
|
||||
if (root._handlers.length) {
|
||||
return;
|
||||
}
|
||||
dbug('basicConfig', options);
|
||||
|
||||
// available options:
|
||||
// level, format, filename, stream
|
||||
options = options || {};
|
||||
|
||||
var hdlr;
|
||||
if (options.file) {
|
||||
hdlr = new handlers.File({ file: options.file });
|
||||
} else if (options.stream) {
|
||||
hdlr = new handlers.Stream({ stream: options.stream });
|
||||
} else if (options.null) {
|
||||
hdlr = new handlers.Null();
|
||||
} else {
|
||||
hdlr = new handlers.Console();
|
||||
}
|
||||
hdlr.setFormatter(new Formatter(options.format || DEFAULT_FORMAT));
|
||||
root.addHandler(hdlr);
|
||||
|
||||
if (options.level) {
|
||||
root.setLevel(options.level);
|
||||
}
|
||||
root.handle = oldHandle;
|
||||
};
|
||||
|
||||
root.Logger = Logger;
|
||||
root.Handler = Handler;
|
||||
root.handlers = handlers;
|
||||
root.Formatter = Formatter;
|
||||
root.Filter = require('./filter');
|
||||
|
||||
root.getLogger = function getLogger(name) {
|
||||
return new Logger(name);
|
||||
};
|
||||
|
||||
// lazy load it, since console depends on this module
|
||||
Object.defineProperty(root, 'config', {
|
||||
get: function() {
|
||||
return require('./config');
|
||||
}
|
||||
});
|
||||
Object.defineProperty(root, 'console', {
|
||||
get: function() {
|
||||
return require('./console');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
module.exports = root;
|
47
node_modules/intel/lib/levels.js
generated
vendored
Normal file
47
node_modules/intel/lib/levels.js
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const LEVELS = module.exports = {};
|
||||
|
||||
[
|
||||
'NOTSET',
|
||||
'TRACE',
|
||||
'VERBOSE',
|
||||
'DEBUG',
|
||||
'INFO',
|
||||
'WARN',
|
||||
'ERROR',
|
||||
'CRITICAL'
|
||||
].forEach(function(name, index) {
|
||||
LEVELS[name] = index * 10;
|
||||
});
|
||||
|
||||
|
||||
|
||||
const NUMBERS = {};
|
||||
for (var levelname in LEVELS) {
|
||||
NUMBERS[LEVELS[levelname]] = levelname;
|
||||
}
|
||||
|
||||
// additional levels, but not canonical names
|
||||
LEVELS.WARNING = LEVELS.WARN;
|
||||
LEVELS.ALL = LEVELS.NOTSET;
|
||||
LEVELS.NONE = Infinity;
|
||||
|
||||
LEVELS.getLevelName = function getLevelName(number) {
|
||||
return NUMBERS[number];
|
||||
};
|
||||
|
||||
LEVELS.getLevel = function getLevel(val) {
|
||||
// 5 => 5
|
||||
// '5' => 5
|
||||
// 'five' => undefined
|
||||
// 'debug' => 20
|
||||
// 'DEBUG' = > 20
|
||||
var level = Number(val);
|
||||
if (isNaN(level)) {
|
||||
level = LEVELS[String(val).toUpperCase()];
|
||||
}
|
||||
return level;
|
||||
};
|
308
node_modules/intel/lib/logger.js
generated
vendored
Normal file
308
node_modules/intel/lib/logger.js
generated
vendored
Normal file
@@ -0,0 +1,308 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const assert = require('assert');
|
||||
|
||||
const dbug = require('dbug')('intel:logger');
|
||||
|
||||
const klass = require('./utils/klass');
|
||||
const LEVELS = require('./levels');
|
||||
const Filterer = require('./filterer');
|
||||
const Record = require('./record');
|
||||
const Trace = Record._Trace;
|
||||
|
||||
var __loggers = {};
|
||||
var __levelCache = {};
|
||||
const ROOT = 'root';
|
||||
const DIVIDER = '.';
|
||||
const OTHER_DIVIDERS = /[\/\\]/g;
|
||||
|
||||
function emptyStr() { return ''; }
|
||||
function traceStr() { return 'Trace'; }
|
||||
|
||||
function getEffectiveParent(name) {
|
||||
if (name === ROOT) {
|
||||
return;
|
||||
}
|
||||
|
||||
var parent;
|
||||
while (name.indexOf(DIVIDER) !== -1 && !parent) {
|
||||
name = name.substring(0, name.lastIndexOf(DIVIDER));
|
||||
parent = __loggers[name];
|
||||
}
|
||||
return parent || __loggers[ROOT];
|
||||
}
|
||||
|
||||
function getChildren(name) {
|
||||
var children = [];
|
||||
for (var k in __loggers) {
|
||||
if ((name === ROOT || k.indexOf(name) === 0) &&
|
||||
k !== name &&
|
||||
getEffectiveParent(k) === __loggers[name]) {
|
||||
children.push(__loggers[k]);
|
||||
}
|
||||
}
|
||||
return children;
|
||||
}
|
||||
|
||||
function logNoop() {}
|
||||
|
||||
function disableLevels(logger) {
|
||||
for (var name in LEVELS) {
|
||||
if (typeof LEVELS[name] === 'number') {
|
||||
var level = LEVELS[name];
|
||||
name = name.toLowerCase();
|
||||
if (logger[name]) {
|
||||
if (logger.isEnabledFor(level)) {
|
||||
// delete any noops
|
||||
delete logger[name];
|
||||
} else {
|
||||
Object.defineProperty(logger, name, {
|
||||
configurable: true,
|
||||
value: logNoop
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var children = getChildren(logger._name);
|
||||
children.forEach(function(child) {
|
||||
disableLevels(child);
|
||||
});
|
||||
}
|
||||
|
||||
function logAtLevel(level) {
|
||||
return function(msg /*, args...*/) {
|
||||
switch (arguments.length) {
|
||||
//faster cases
|
||||
case 0:
|
||||
case 1:
|
||||
return this._log(level, msg);
|
||||
case 2:
|
||||
return this._log(level, msg, arguments[1]);
|
||||
default:
|
||||
//turtles
|
||||
var args = new Array(arguments.length + 1);
|
||||
args[0] = level;
|
||||
for (var i = 1; i < args.length; i++) {
|
||||
args[i] = arguments[i - 1];
|
||||
}
|
||||
return this._log.apply(this, args);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
function Logger(name) {
|
||||
if (!name) {
|
||||
name = ROOT;
|
||||
}
|
||||
name = name.replace(OTHER_DIVIDERS, DIVIDER);
|
||||
if (name in __loggers) {
|
||||
return __loggers[name];
|
||||
}
|
||||
__loggers[name] = this;
|
||||
this._name = name;
|
||||
disableLevels(this);
|
||||
|
||||
Filterer.call(this);
|
||||
|
||||
this._handlers = [];
|
||||
|
||||
dbug('Logger (%s) created', name);
|
||||
}
|
||||
|
||||
klass(Logger).inherit(Filterer).mixin({
|
||||
|
||||
//_handlers: [],
|
||||
|
||||
_name: null,
|
||||
|
||||
_level: null,
|
||||
|
||||
_handlesExceptions: false,
|
||||
|
||||
_exitOnError: true,
|
||||
|
||||
propagate: true,
|
||||
|
||||
setLevel: function setLevel(val) {
|
||||
var level = LEVELS.getLevel(val);
|
||||
assert(level != null, 'Cannot set level with provided value: ' + val);
|
||||
this._level = level;
|
||||
// clean __levelsCache
|
||||
__levelCache = {};
|
||||
disableLevels(this);
|
||||
return this;
|
||||
},
|
||||
|
||||
|
||||
getEffectiveLevel: function getEffectiveLevel() {
|
||||
if (this._level != null) {
|
||||
return this._level;
|
||||
} else if (this._name in __levelCache) {
|
||||
return __levelCache[this._name];
|
||||
} else {
|
||||
var parent = getEffectiveParent(this._name);
|
||||
return __levelCache[this._name] = parent ?
|
||||
parent.getEffectiveLevel() :
|
||||
LEVELS.NOTSET;
|
||||
}
|
||||
},
|
||||
|
||||
isEnabledFor: function isEnabledFor(level) {
|
||||
return level >= this.getEffectiveLevel();
|
||||
},
|
||||
|
||||
addHandler: function addHandler(handler) {
|
||||
this._handlers.push(handler);
|
||||
return this;
|
||||
},
|
||||
|
||||
removeHandler: function removeHandler(handler) {
|
||||
var index = this._handlers.indexOf(handler);
|
||||
if (index !== -1) {
|
||||
this._handlers.splice(index, 1);
|
||||
}
|
||||
return this;
|
||||
},
|
||||
|
||||
removeAllHandlers: function removeAllHandlers() {
|
||||
this._handlers = [];
|
||||
},
|
||||
|
||||
handleExceptions: function handleExceptions(exitOnError/* = true */) {
|
||||
this._exitOnError = exitOnError === false ? false : true;
|
||||
if (!this._uncaughtException) {
|
||||
this._uncaughtException = this.catchException.bind(this);
|
||||
this._process.on('uncaughtException', this._uncaughtException);
|
||||
}
|
||||
},
|
||||
|
||||
unhandleExceptions: function unhandleExceptions() {
|
||||
this._process.removeListener('uncaughtException', this._uncaughtException);
|
||||
delete this._uncaughtException;
|
||||
},
|
||||
|
||||
catchException: function catchException(err) {
|
||||
var exits = this._exitOnError;
|
||||
|
||||
err[Record._UNCAUGHT_SYMBOL] = true;
|
||||
this.critical(err);
|
||||
if (exits) {
|
||||
this._exit();
|
||||
}
|
||||
},
|
||||
|
||||
_exit: function _exit() {
|
||||
this._process.exit(1);
|
||||
},
|
||||
|
||||
makeRecord: function makeRecord(name, level, msg) {
|
||||
return new Record(name, level, msg);
|
||||
},
|
||||
|
||||
handle: function handle(record) {
|
||||
if (this.filter(record)) {
|
||||
|
||||
var i = this._handlers.length;
|
||||
while (i--) {
|
||||
if (record.level >= this._handlers[i].level) {
|
||||
this._handlers[i].handle(record);
|
||||
}
|
||||
}
|
||||
|
||||
// if this.propagate, tell our parent
|
||||
if (this.propagate) {
|
||||
var par = getEffectiveParent(this._name);
|
||||
if (par) {
|
||||
par.handle(record);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
dbug('%s filtered message [%s]', this._name, record.message);
|
||||
}
|
||||
},
|
||||
|
||||
_log: function _log(_level, msg /*, args...*/) {
|
||||
var level = LEVELS.getLevel(_level);
|
||||
var args;
|
||||
if (arguments.length < 3) {
|
||||
args = [msg];
|
||||
} else {
|
||||
args = new Array(arguments.length - 1);
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
args[i] = arguments[i + 1];
|
||||
}
|
||||
}
|
||||
var record = this.makeRecord(this._name, level, args);
|
||||
this.handle(record);
|
||||
},
|
||||
|
||||
log: function log(_level /* msg, messageArs... */) {
|
||||
var level = LEVELS.getLevel(_level);
|
||||
// if level >= this.getEffectiveLevel(), tell our handlers
|
||||
if (this.isEnabledFor(level)) {
|
||||
this._log.apply(this, arguments);
|
||||
}
|
||||
},
|
||||
|
||||
trace: function trace(_msg) {
|
||||
var obj = new Trace(trace);
|
||||
|
||||
var slice = 0;
|
||||
var message = _msg;
|
||||
if (typeof message === 'string') {
|
||||
// [TRACE, msg, obj, ...arguments]
|
||||
slice = 1;
|
||||
message = '%s' + message;
|
||||
obj.toString = emptyStr;
|
||||
} else {
|
||||
message = '%s';
|
||||
obj.toString = traceStr;
|
||||
}
|
||||
|
||||
var args = new Array(3 + arguments.length - slice);
|
||||
args[0] = LEVELS.TRACE;
|
||||
args[1] = message;
|
||||
args[2] = obj;
|
||||
for (var i = 3; i < args.length; i++) {
|
||||
args[i] = arguments[i - 3 + slice];
|
||||
}
|
||||
return this._log.apply(this, args);
|
||||
},
|
||||
|
||||
verbose: logAtLevel(LEVELS.VERBOSE),
|
||||
debug: logAtLevel(LEVELS.DEBUG),
|
||||
info: logAtLevel(LEVELS.INFO),
|
||||
warn: logAtLevel(LEVELS.WARNING),
|
||||
error: logAtLevel(LEVELS.ERROR),
|
||||
critical: logAtLevel(LEVELS.CRITICAL),
|
||||
|
||||
// aliases
|
||||
warning: function warning() {
|
||||
return this.warn.apply(this, arguments);
|
||||
},
|
||||
|
||||
/*jshint -W106*/ // ignore camelCase warning for this fun functions
|
||||
o_O: function o_O() {
|
||||
return this.warn.apply(this, arguments);
|
||||
},
|
||||
|
||||
O_O: function O_O() {
|
||||
return this.error.apply(this, arguments);
|
||||
},
|
||||
|
||||
_process: process
|
||||
|
||||
});
|
||||
|
||||
for (var k in LEVELS) {
|
||||
if (typeof LEVELS[k] === 'number') {
|
||||
Logger[k] = Logger.prototype[k] = LEVELS[k];
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Logger;
|
121
node_modules/intel/lib/record.js
generated
vendored
Normal file
121
node_modules/intel/lib/record.js
generated
vendored
Normal file
@@ -0,0 +1,121 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const util = require('util');
|
||||
|
||||
const stacktrace = require('stack-trace');
|
||||
const _Symbol = require('symbol');
|
||||
|
||||
const LEVELS = require('./levels');
|
||||
const printf = require('./utils/printf');
|
||||
|
||||
const UNCAUGHT_SYMBOL = _Symbol();
|
||||
const LOG_VERSION = 1; // increment when log format changes
|
||||
const HOSTNAME = require('os').hostname();
|
||||
const MESSAGE_CACHE = _Symbol();
|
||||
const PID = process.pid;
|
||||
|
||||
// stack formatter helper
|
||||
function stack(e) {
|
||||
return {
|
||||
toString: function() {
|
||||
// first line is err.message, which we already show, so start from
|
||||
// second line
|
||||
return e.stack.substr(e.stack.indexOf('\n'));
|
||||
},
|
||||
toJSON: function() {
|
||||
return stacktrace.parse(e);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function Trace(fn) {
|
||||
Error.captureStackTrace(this, fn);
|
||||
}
|
||||
|
||||
Trace.prototype.toJSON = function() {
|
||||
return '[object Trace]';
|
||||
};
|
||||
|
||||
function Record(name, level, args) {
|
||||
this.name = name;
|
||||
this.level = level;
|
||||
this.levelname = LEVELS.getLevelName(level);
|
||||
this.args = args;
|
||||
this.pid = PID;
|
||||
this.host = HOSTNAME;
|
||||
this.v = LOG_VERSION;
|
||||
this.timestamp = Date.now();
|
||||
|
||||
var trace;
|
||||
var isErr = false;
|
||||
var i = args.length;
|
||||
while (i--) {
|
||||
var a = args[i];
|
||||
if (a && ((isErr = util.isError(a)) || a instanceof Trace)) {
|
||||
trace = a;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.exception = isErr || undefined;
|
||||
this.uncaughtException = isErr ? trace[UNCAUGHT_SYMBOL] : undefined;
|
||||
this.stack = trace && trace.stack ? stack(trace) : undefined;
|
||||
}
|
||||
|
||||
Record.prototype.name = undefined;
|
||||
Record.prototype.level = undefined;
|
||||
Record.prototype.levelname = undefined;
|
||||
Record.prototype.args = undefined;
|
||||
Record.prototype.pid = undefined;
|
||||
Record.prototype.host = undefined;
|
||||
Record.prototype.v = undefined;
|
||||
Record.prototype.timestamp = undefined;
|
||||
Record.prototype.exception = undefined;
|
||||
Record.prototype.uncaughtException = undefined;
|
||||
Record.prototype.stack = undefined;
|
||||
Record.prototype[MESSAGE_CACHE] = undefined;
|
||||
|
||||
Object.defineProperty(Record.prototype, 'message', {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
var message = this[MESSAGE_CACHE];
|
||||
if (!message) {
|
||||
var args = this.args;
|
||||
message = args[0];
|
||||
var isString = typeof message === 'string';
|
||||
if (!isString || args.length > 1) {
|
||||
if (!isString) {
|
||||
args = new Array(this.args.length + 1);
|
||||
args[0] = '%?';
|
||||
var i = args.length - 1;
|
||||
while (i--) {
|
||||
args[i + 1] = this.args[i];
|
||||
}
|
||||
}
|
||||
message = printf.apply(null, args);
|
||||
}
|
||||
this[MESSAGE_CACHE] = message;
|
||||
}
|
||||
return message;
|
||||
}
|
||||
});
|
||||
|
||||
Record.prototype.toJSON = function toJSON() {
|
||||
var json = {};
|
||||
var keys = Object.keys(this);
|
||||
var i = keys.length;
|
||||
while (i--) {
|
||||
var key = keys[i];
|
||||
if (key === 'timestamp') {
|
||||
json.timestamp = new Date(this.timestamp);
|
||||
} else {
|
||||
json[key] = this[key];
|
||||
}
|
||||
}
|
||||
return json;
|
||||
};
|
||||
|
||||
Record._Trace = Trace;
|
||||
Record._UNCAUGHT_SYMBOL = UNCAUGHT_SYMBOL;
|
||||
module.exports = Record;
|
10
node_modules/intel/lib/utils/fn.js
generated
vendored
Normal file
10
node_modules/intel/lib/utils/fn.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
|
||||
module.exports = function fn(args) {
|
||||
/*jshint evil: true*/
|
||||
console.log(args, [].slice.call(arguments, 1).join('\n'));
|
||||
return new Function(args, [].slice.call(arguments, 1).join('\n'));
|
||||
};
|
32
node_modules/intel/lib/utils/json.js
generated
vendored
Normal file
32
node_modules/intel/lib/utils/json.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// util to protect us from circular references when stringifying
|
||||
|
||||
'use strict';
|
||||
|
||||
function stringify(obj, indent) {
|
||||
var seen = [];
|
||||
return JSON.stringify(obj, function filter(key, val) {
|
||||
if (!val || typeof val !== 'object') {
|
||||
return val;
|
||||
} else if (seen.indexOf(val) !== -1) {
|
||||
return '[Circular]';
|
||||
}
|
||||
seen.push(val);
|
||||
return val;
|
||||
}, indent || 0);
|
||||
}
|
||||
|
||||
function nativeJson(obj, indent) {
|
||||
return indent ? JSON.stringify(obj, null, indent) : JSON.stringify(obj);
|
||||
}
|
||||
|
||||
module.exports = function json(obj, indent) {
|
||||
try {
|
||||
return nativeJson(obj, indent);
|
||||
} catch (e) {
|
||||
return stringify(obj, indent);
|
||||
}
|
||||
};
|
27
node_modules/intel/lib/utils/klass.js
generated
vendored
Normal file
27
node_modules/intel/lib/utils/klass.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const util = require('util');
|
||||
|
||||
function klass(ctor) {
|
||||
if (!(this instanceof klass)) {
|
||||
return new klass(ctor);
|
||||
}
|
||||
this._ctor = ctor;
|
||||
}
|
||||
|
||||
klass.prototype = {
|
||||
inherit: function inherit(par) {
|
||||
util.inherits(this._ctor, par);
|
||||
return this;
|
||||
},
|
||||
mixin: function mixin(other) {
|
||||
for (var k in other) {
|
||||
this._ctor.prototype[k] = other[k];
|
||||
}
|
||||
return this;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = klass;
|
126
node_modules/intel/lib/utils/printf.js
generated
vendored
Normal file
126
node_modules/intel/lib/utils/printf.js
generated
vendored
Normal file
@@ -0,0 +1,126 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const json = require('./json');
|
||||
|
||||
const RE = /%(-?\d+)?(\.-?\d+)?(:\d+)?(%|(\([^\)]+\))?([sdOj\?]))/g;
|
||||
|
||||
const toString = Object.prototype.toString;
|
||||
function type(x) {
|
||||
return toString.call(x).slice(8, -1).toLowerCase();
|
||||
}
|
||||
|
||||
function pad(str, value) {
|
||||
var isRight = false;
|
||||
|
||||
if(value < 0) {
|
||||
isRight = true;
|
||||
value = -value;
|
||||
}
|
||||
|
||||
if(str.length < value) {
|
||||
var padding = new Array(value - str.length + 1).join(' ');
|
||||
return isRight ? str + padding : padding + str;
|
||||
} else{
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
function truncate(str, value) {
|
||||
if(value > 0) {// truncate from begining
|
||||
return str.slice(-value);
|
||||
} else {// truncate from end
|
||||
return str.slice(0, -value);
|
||||
}
|
||||
}
|
||||
|
||||
function defaultFmt(x) {
|
||||
switch (type(x)) {
|
||||
case 'arguments':
|
||||
case 'object':
|
||||
return json(x);
|
||||
default:
|
||||
return String(x);
|
||||
}
|
||||
}
|
||||
|
||||
function printfNextValue(format, nextValFn) {
|
||||
var str = String(format).replace(RE,
|
||||
function(match, padding, trunc, indent, kind, name, type) {
|
||||
|
||||
if (kind === '%') {
|
||||
return '%';
|
||||
}
|
||||
|
||||
var val = nextValFn(name);
|
||||
|
||||
|
||||
var fmt = '';
|
||||
|
||||
switch (type) {
|
||||
case 's':
|
||||
fmt = String(val);
|
||||
break;
|
||||
case 'd':
|
||||
fmt = String(Number(val));
|
||||
break;
|
||||
case 'O':
|
||||
case 'j':
|
||||
fmt = json(val, indent && parseInt(indent.slice(1), 10));
|
||||
break;
|
||||
case '?':
|
||||
fmt = defaultFmt(val);
|
||||
break;
|
||||
}
|
||||
|
||||
if (trunc !== undefined) {
|
||||
fmt = truncate(fmt, trunc.slice(1));
|
||||
}
|
||||
|
||||
if (padding !== undefined) {
|
||||
fmt = pad(fmt, padding);
|
||||
}
|
||||
|
||||
return fmt;
|
||||
});
|
||||
return str;
|
||||
}
|
||||
|
||||
function printfObj(format, obj) {
|
||||
return printfNextValue(format, function(name) {
|
||||
name = name && name.slice(1, -1);
|
||||
return obj[name];
|
||||
});
|
||||
}
|
||||
|
||||
function printfArgs(format, args) {
|
||||
var i = 0;
|
||||
var len = args.length;
|
||||
var str = printfNextValue(format, function() {
|
||||
return args[i++];
|
||||
});
|
||||
if (len > 0) {
|
||||
for (var x = args[i]; i < len; x = args[++i]) {
|
||||
str += ' ' + defaultFmt(x);
|
||||
}
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
// Usage:
|
||||
// printf('I am %d %s old', 4, 'years');
|
||||
// printf('%(name)s: %:2(message)j', { name: 'foo', message: { foo: 'bar' }});
|
||||
const OBJECT_FMT = /%([:\-]?\d+)?\([^\)]+\)[sdjO\?]/;
|
||||
module.exports = function printf(format, obj/*, ..args*/) {
|
||||
if (!OBJECT_FMT.test(format)) {
|
||||
var args = new Array(arguments.length - 1);
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
args[i] = arguments[i + 1];
|
||||
}
|
||||
return printfArgs(format, args);
|
||||
} else {
|
||||
return printfObj(format, obj);
|
||||
}
|
||||
};
|
59
node_modules/intel/package.json
generated
vendored
Normal file
59
node_modules/intel/package.json
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
{
|
||||
"name": "intel",
|
||||
"version": "1.2.0",
|
||||
"license": "MPL-2.0",
|
||||
"dependencies": {
|
||||
"chalk": "^1.1.0",
|
||||
"dbug": "~0.4.2",
|
||||
"stack-trace": "~0.0.9",
|
||||
"strftime": "~0.10.0",
|
||||
"symbol": "~0.3.1",
|
||||
"utcstring": "~0.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"bluebird": "^3.5",
|
||||
"debug": "~2.2.0",
|
||||
"insist": "^1.0",
|
||||
"jshint": "2.x",
|
||||
"matcha": "0.x",
|
||||
"mocha": "3.x",
|
||||
"nyc": "^11.0.1",
|
||||
"walk": "2.x",
|
||||
"winston": "^2.0"
|
||||
},
|
||||
"readmeFilename": "README.md",
|
||||
"description": "I need more intel.",
|
||||
"main": "./lib/index.js",
|
||||
"scripts": {
|
||||
"test": "nyc mocha --ui exports -R dot",
|
||||
"bench": "matcha -I exports"
|
||||
},
|
||||
"bugs": "https://github.com/seanmonstar/intel/issues",
|
||||
"homepage": "http://seanmonstar.github.io/intel",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/seanmonstar/intel.git"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4.0.0"
|
||||
},
|
||||
"keywords": [
|
||||
"log",
|
||||
"debug",
|
||||
"dbug",
|
||||
"logging",
|
||||
"logger",
|
||||
"console"
|
||||
],
|
||||
"author": "Sean McArthur <sean.monstar@gmail.com> (http://seanmonstar.com)",
|
||||
"licenses": [
|
||||
{
|
||||
"type": "MPL 2.0",
|
||||
"url": "https://mozilla.org/MPL/2.0/"
|
||||
}
|
||||
],
|
||||
"files": [
|
||||
"LICENSE",
|
||||
"lib"
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user