Git Product home page Git Product logo

npmlog's Introduction

npmlog

The logger util that npm uses.

This logger is very basic. It does the logging for npm. It supports custom levels and colored output.

By default, logs are written to stderr. If you want to send log messages to outputs other than streams, then you can change the log.stream member, or you can just listen to the events that it emits, and do whatever you want with them.

Installation

npm install npmlog --save

Basic Usage

var log = require('npmlog')

// additional stuff ---------------------------+
// message ----------+                         |
// prefix ----+      |                         |
// level -+   |      |                         |
//        v   v      v                         v
    log.info('fyi', 'I have a kitty cat: %j', myKittyCat)

log.level

  • {String}

The level to display logs at. Any logs at or above this level will be displayed. The special level silent will prevent anything from being displayed ever.

log.record

  • {Array}

An array of all the log messages that have been entered.

log.maxRecordSize

  • {Number}

The maximum number of records to keep. If log.record gets bigger than 10% over this value, then it is sliced down to 90% of this value.

The reason for the 10% window is so that it doesn't have to resize a large array on every log entry.

log.prefixStyle

  • {Object}

A style object that specifies how prefixes are styled. (See below)

log.headingStyle

  • {Object}

A style object that specifies how the heading is styled. (See below)

log.heading

  • {String} Default: ""

If set, a heading that is printed at the start of every line.

log.stream

  • {Stream} Default: process.stderr

The stream where output is written.

log.enableColor()

Force colors to be used on all messages, regardless of the output stream.

log.disableColor()

Disable colors on all messages.

log.enableProgress()

Enable the display of log activity spinner and progress bar

log.disableProgress()

Disable the display of a progress bar

log.enableUnicode()

Force the unicode theme to be used for the progress bar.

log.disableUnicode()

Disable the use of unicode in the progress bar.

log.setGaugeTemplate(template)

Set a template for outputting the progress bar. See the gauge documentation for details.

log.setGaugeThemeset(themes)

Select a themeset to pick themes from for the progress bar. See the gauge documentation for details.

log.pause()

Stop emitting messages to the stream, but do not drop them.

log.resume()

Emit all buffered messages that were written while paused.

log.log(level, prefix, message, ...)

  • level {String} The level to emit the message at
  • prefix {String} A string prefix. Set to "" to skip.
  • message... Arguments to util.format

Emit a log message at the specified level.

log[level](prefix, message, ...)

For example,

  • log.silly(prefix, message, ...)
  • log.verbose(prefix, message, ...)
  • log.info(prefix, message, ...)
  • log.http(prefix, message, ...)
  • log.warn(prefix, message, ...)
  • log.error(prefix, message, ...)

Like log.log(level, prefix, message, ...). In this way, each level is given a shorthand, so you can do log.info(prefix, message).

log.addLevel(level, n, style, disp)

  • level {String} Level indicator
  • n {Number} The numeric level
  • style {Object} Object with fg, bg, inverse, etc.
  • disp {String} Optional replacement for level in the output.

Sets up a new level with a shorthand function and so forth.

Note that if the number is Infinity, then setting the level to that will cause all log messages to be suppressed. If the number is -Infinity, then the only way to show it is to enable all log messages.

log.newItem(name, todo, weight)

  • name {String} Optional; progress item name.
  • todo {Number} Optional; total amount of work to be done. Default 0.
  • weight {Number} Optional; the weight of this item relative to others. Default 1.

This adds a new are-we-there-yet item tracker to the progress tracker. The object returned has the log[level] methods but is otherwise an are-we-there-yet Tracker object.

log.newStream(name, todo, weight)

This adds a new are-we-there-yet stream tracker to the progress tracker. The object returned has the log[level] methods but is otherwise an are-we-there-yet TrackerStream object.

log.newGroup(name, weight)

This adds a new are-we-there-yet tracker group to the progress tracker. The object returned has the log[level] methods but is otherwise an are-we-there-yet TrackerGroup object.

Events

Events are all emitted with the message object.

  • log Emitted for all messages
  • log.<level> Emitted for all messages with the <level> level.
  • <prefix> Messages with prefixes also emit their prefix as an event.

Style Objects

Style objects can have the following fields:

  • fg {String} Color for the foreground text
  • bg {String} Color for the background
  • bold, inverse, underline {Boolean} Set the associated property
  • bell {Boolean} Make a noise (This is pretty annoying, probably.)

Message Objects

Every log event is emitted with a message object, and the log.record list contains all of them that have been created. They have the following fields:

  • id {Number}
  • level {String}
  • prefix {String}
  • message {String} Result of util.format()
  • messageRaw {Array} Arguments to util.format()

Blocking TTYs

We use set-blocking to set stderr and stdout blocking if they are tty's and have the setBlocking call. This is a work around for an issue in early versions of Node.js 6.x, which made stderr and stdout non-blocking on OSX. (They are always blocking Windows and were never blocking on Linux.) npmlog needs them to be blocking so that it can allow output to stdout and stderr to be interlaced.

npmlog's People

Contributors

bengl avatar dependabot[bot] avatar github-actions[bot] avatar helio-frota avatar iarna avatar isaacs avatar jamestalmage avatar lukekarrys avatar max-mapper avatar nlf avatar othiym23 avatar rwaldron avatar wraithgar avatar zearin avatar zkat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

npmlog's Issues

[FEATURE] Disable log colors if environment variable is set

Using the npmlog within IDEs like Eclipse or other tools that does not support colors, the outcome show instead of colors, the special characters equivalents.

This is an example using the node-gyp package that uses npmlog for logging.
image

If someone set a environment variable could this prevent the colors from being displayed?

Node.js already has a environment variable for disabling colors but npmlog does not seems to respect it.
That is NODE_DISABLE_COLORS

Could use the same environment variable or define a new one, doesn't matter.

Hide level, prefix in production

Hi,

Thank you for cool package.

I want hide level, prefix in production.

import log from 'npmlog';

log.info('iamprefix', 'helloworld!');

// result >> info iamprefix helloworld!
// want >> helloworld!

Level, prefix very helpful for development, but not helpful live application. I want hide a level, prefix Like npm.js. But I can't found hide option in README and application source. Is it impossible?

Question: "debug" type messages?

If I'd like to include debug logging in my code, which can be turned off and on with a single variable flag, how would I go about that with this package? For instance, on a production box, I'd be tempted to turn off debug logging, but keep on the errors & warnings.

Reentrancy, multiple instances?

I took a look at the implementation, and, correct me if I'm wrong, it looks like this (otherwise nice) logger supports only a single instance of a logger, and stores status in the module itself, making it non reentrant, and, as such, unsuitable for server applications, where each user might have a different log level.

Could you consider adding a constructor so that multiple separate instances can be created?

Usage might look like:

const Logger = require('npmlog').Logger
const log = new Logger()

Even if this breaks compatibility with existing applications, personally I would completely disable the current non-reentrant usage.

Process is undefined

var ansi = require('ansi')
log.cursor = ansi(process.stderr)

On these lines you guys are sending in process, which is, for some reason, undefined in my project. Which makes me experience this bug:

Uncaught TypeError: Cannot read property '_ansicursor' of undefined

Do you guys have any clue to why this might be happening?

Im using watchify and browserify to make the project.
It all stems out from "serialport" it seems, which uses "node-pre-gyp" which again uses this library.

Im researching around, just looking to solve this problem and be able to continue with my application. So if you have any kind of feedback which might help me in the right direction, il be very glad!

Can I use this with carriage return?

I spawn a child process (protractor) which logs to stdout with a carriage return, but I don't know how to use it with npmlog, because it logs to a new line instead of replacing the old one.

I would like to do this:

    var child = spawn(getProtractorBinary('protractor' + ws.winExt), [ path ], {
      env: process.env
    });

    child.stdout.on('data', data => {
      log.info('protractor', data.toString());
    });

Instead I need to do this:

    var child = spawn(getProtractorBinary('protractor' + ws.winExt), [ path ], {
      env: process.env,
      stdio: [ 'pipe', process.stdout, 'pipe' ]
    });

Any way to combine logs with carriage return in npmlog?

Setting string stack of some Errors causes `cannot set property stack`...

Using lerna, I came across this problem:

TypeError: Cannot set property stack of JSONError which has only a getter
    at EventEmitter.<anonymous> (/home/user/.config/yarn/global/node_modules/npmlog/log.js:185:17)
    at EventEmitter.<anonymous> (/home/user/.config/yarn/global/node_modules/npmlog/log.js:281:23)
    at BootstrapCommand.runPreparations 
...

Switching from:

error.stack = stack + ''

to

Object.defineProperty(error, 'stack', foo)

Fixes this for me. PR incoming

Example for gauge/tracker usage

Hey folks,
unfortunately I can't figure out how to use the Tracker stuff. I'm trying to display a download progress for example, but I have no Idea how I display the gauge (which brings the feature of overwriting the line, I guess?) or how Tracker items and groups are meant to play together.

Might anybody provide an explanation or example, please?

Allow creating log levels that have an empty string defined for "disp"

Presently:

log.addLevel('entry', 1000, { fg: 'white' }, '');
log.entry('', 'Some entry thinger');
// "entry Some entry thinger"

(We expose curried npmlog functions that fill in the "prefix" with an empty string)

I would like to propose the following: If an empty string is explicitly provided to log.addLevel, then it should be respected as the intended "disp" for that newly defined log level:

log.addLevel('entry', 1000, { fg: 'white' }, '');
log.entry('', 'Some entry thinger');
// "Some entry thinger"

If this is a desirable feature, I have prepared a patch w/ tests to submit as a PR.

Reporting a vulnerability

Hello!

I hope you are doing well!

We are a security research team. Our tool automatically detected a vulnerability in this repository. We want to disclose it responsibly. GitHub has a feature called Private vulnerability reporting, which enables security research to privately disclose a vulnerability. Unfortunately, it is not enabled for this repository.

Can you enable it, so that we can report it?

Thanks in advance!

PS: you can read about how to enable private vulnerability reporting here: https://docs.github.com/en/code-security/security-advisories/repository-security-advisories/configuring-private-vulnerability-reporting-for-a-repository

stderr for logs?

I may be reading the code wrong but it looks like warnings are sent to stderr.
I think this may be causing issues for some folks with the lodash deprecation message as it causes a non-0 exit code.

\cc @phated

Install instructions incomplete

I followed the basic usage instructions and got this output:

module.js:327
    throw err;
    ^

Error: Cannot find module 'npmlog'

The install instructions are missing: npm install npmlog.

Every node package has them.

[ISSUE] how to use npmlog in a script?

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

This was my test script

const log = require('npmlog');
log.info('test npmlog');

I ran it like this
node test_npmlog.js
I got error

node:internal/modules/cjs/loader:998
  throw err;
  ^

Error: Cannot find module 'npmlog'
Require stack:
- C:\users\william\examples\test_npmlog.js
←[90m    at Module._resolveFilename (node:internal/modules/cjs/loader:995:15)←[39m
←[90m    at Module._load (node:internal/modules/cjs/loader:841:27)←[39m
←[90m    at Module.require (node:internal/modules/cjs/loader:1061:19)←[39m
←[90m    at require (node:internal/modules/cjs/helpers:103:18)←[39m
    at Object.<anonymous> ←[90m(C:\users\william\examples\←[39mtest_npmlog.js:3:13←[90m)←[39m
←[90m    at Module._compile (node:internal/modules/cjs/loader:1159:14)←[39m
←[90m    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)←[39m
←[90m    at Module.load (node:internal/modules/cjs/loader:1037:32)←[39m
←[90m    at Module._load (node:internal/modules/cjs/loader:878:12)←[39m
←[90m    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)←[39m {
  code: ←[32m'MODULE_NOT_FOUND'←[39m,
  requireStack: [
    ←[32m'C:\\users\\william\\examples\\test_npmlog.js'←[39m
  ]
}

Node.js v18.12.1

I did install npmlog.

My VS Code suggested me to do this way

import { info } from 'npmlog';
info('test npmlog');

Then I got a new error

(node:9392) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
C:\users\william\examples\test_npmlog.js:3
import { info } from 'npmlog';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:360:18)
    at wrapSafe (node:internal/modules/cjs/loader:1088:15)
    at Module._compile (node:internal/modules/cjs/loader:1123:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47

Node.js v18.12.1

I checked example and test folder in this github repo. None of them did anything like 'require(npmlog)'.

What is the basic usage of npmlog in a script?

Expected Behavior

No response

Steps To Reproduce

  1. In this environment...
  2. With this config...
  3. Run '...'
  4. See error...

Environment

  • npm: 9.2.0
  • Node: 18.12.1
  • OS: Windows 10
  • platform: Laptop
  • npmlog: 7.0.1

npmlog error: log.gauge.isEnabled is not a function

2017-6-8 16:15:59 unhandledRejection TypeError: log.gauge.isEnabled is not a function
    at Object.<anonymous> (/home/patrikx3/ramdisk/persistence/content/.p3x-ramdisk-link/Projects/patrikx3/tools/node_modules/npm/node_modules/npmlog/log.js:57:33)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/patrikx3/ramdisk/persistence/content/.p3x-ramdisk-link/Projects/patrikx3/tools/node_modules/npm/lib/utils/umask.js:2:14)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18) Promise {
  <rejected> TypeError: log.gauge.isEnabled is not a function
    at Object.<anonymous> (/home/patrikx3/ramdisk/persistence/content/.p3x-ramdisk-link/Projects/patrikx3/tools/node_modules/npm/node_modules/npmlog/log.js:57:33)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/patrikx3/ramdisk/persistence/content/.p3x-ramdisk-link/Projects/patrikx3/tools/node_modules/npm/lib/utils/umask.js:2:14)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18) }

profiling express application breaks with npmlog v3.0.0

I noticed today while trying to profile a nodejs app which uses express, that the update to v3 of npmlog breaks when running v8 profiling.

Using this reduced test case the following steps will reproduce the error

  1. npm run v3 -> causes an error
  2. npm run v2 -> works as expected

I haven't drilled down into npmlog to determine exactly what is causing this to happen.

Throw error for updating npm

I was trying to install Salesforce's Lightning Design System and other component libraries, have had a ton of issues with Gulp and NPM/Node failing to install properly. More on my post here

I received this error.

`npm install react-lightning-design-system
module.js:442
throw err;
^

Error: Cannot find module 'npmlog'
at Function.Module._resolveFilename (module.js:440:15)
at Function.Module._load (module.js:388:25)
at Module.require (module.js:468:17)
at require (internal/module.js:20:19)
at /usr/local/lib/node_modules/npm/bin/npm-cli.js:20:13
at Object. (/usr/local/lib/node_modules/npm/bin/npm-cli.js:76:3)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)`

Cannot find module 'npmlog' following homebrew update & upgrade

Details: OSX 10.10.5, Node 4.2.1

Hi, I ran brew update && brew upgrade and now when I try to use npm in the command line I get the following (below). Any help would be appreciated as I'm at a loss as to what to do apart from reinstalling node and npm. Thanks

module.js:339
throw err;
^

Error: Cannot find module 'npmlog'
at Function.Module._resolveFilename (module.js:337:15)
at Function.Module._load (module.js:287:25)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at /usr/local/lib/node_modules/npm/bin/npm-cli.js:18:11
at Object. (/usr/local/lib/node_modules/npm/bin/npm-cli.js:75:3)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)

Requiring npmlog enables gauge, even if gauge is never used

When you require('npmlog'), it creates a Gauge, which by default starts out enabled. This calls setInterval with (by default) a 50ms interval. When the gauge is never used, this can have negative effects on performance for no benefit.

Please have the guage start out disabled, and only enable it the first time that you actually need it.

Install react-sripts and start react app on linux

Hello, I'm trying to strart react app on linux.

For that I try to install react-script and npm gives me back an error:

loadDep:workbox-webpack-p ▐ ╢██████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟
npm WARN deprecated [email protected]: This loader has been deprecated. Please use eslint-webpack-plugin
npm ERR! Linux 5.4.0-1028-gcp
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "i" "react-scripts"
npm ERR! node v8.10.0
npm ERR! npm v3.5.2
npm ERR! code EMISSINGARG
npm ERR! typeerror Error: Missing required argument #1
npm ERR! typeerror at andLogAndFinish (/usr/share/npm/lib/fetch-package-metadata.js:31:3)
npm ERR! typeerror at fetchPackageMetadata (/usr/share/npm/lib/fetch-package-metadata.js:51:22)
npm ERR! typeerror at resolveWithNewModule (/usr/share/npm/lib/install/deps.js:456:12)
npm ERR! typeerror at /usr/share/npm/lib/install/deps.js:457:7
npm ERR! typeerror at /usr/share/npm/node_modules/iferr/index.js:13:50
npm ERR! typeerror at /usr/share/npm/lib/fetch-package-metadata.js:37:12
npm ERR! typeerror at addRequestedAndFinish (/usr/share/npm/lib/fetch-package-metadata.js:82:5)
npm ERR! typeerror at returnAndAddMetadata (/usr/share/npm/lib/fetch-package-metadata.js:117:7)
npm ERR! typeerror at pickVersionFromRegistryDocument (/usr/share/npm/lib/fetch-package-metadata.js:134:20)
npm ERR! typeerror at /usr/share/npm/node_modules/iferr/index.js:13:50
npm ERR! typeerror This is an error with npm itself. Please report this error at:
npm ERR! typeerror http://github.com/npm/npm/issues
npm ERR! Please include the following file with any support request:
npm ERR! /root/django_test/react_corr/npm-debug.log

[BUG] Address CVE-2021-3807

What / Why

There is a security vulnerability in transitive dependency ansi-regex.

When

The CVE was published on September 20th, 2021.

Where

The dependency chain that leads to ansi-regex is:
npmlog --> gauge --> wide-align --> string-width --> strip-ansi --> ansi-regex.

How

gauge has no issue tracker, and wide-align may be unmaintained, so it might be worth replacing gauge with an alternative, such as cli-progress, which has already been patched.

Current Behavior

└─ ansi-regex: 3.0.0
├─ Issue: Inefficient Regular Expression Complexity in chalk/ansi-regex
├─ URL: GHSA-93q8-gq69-wqmw
├─ Severity: moderate
├─ Vulnerable Versions: >2.1.1 <5.0.1
├─ Patched Versions: >=5.0.1
├─ Via: npmlog
└─ Recommendation: Upgrade to version 5.0.1 or later

Steps to Reproduce

  1. mkdir ansi-regex-cve
  2. cd ansi-regex-cve
  3. yarn set version berry
  4. yarn add --dev npmlog
  5. yarn npm audit --recursive

Expected Behavior

I expected that no vulnerabilities would be found.

References

  • wide-align pins string-width to v2. string-width already offers a patched version at v5.0.1.
  • There is already an open issue requesting that the dependency on string-width be updated.

Problem with npm and npmlog

Hello,i have install Node.js in my QNAP TS219P II, When i start npm, npm write this :
module.js:340
throw err;
^
Error: Cannot find module 'npmlog'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at /share/HDA_DATA/.qpkg/nodejs/node/bin/npm:18:11
at Object. (/share/HDA_DATA/.qpkg/nodejs/node/bin/npm:86:3)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)

Can you help me to solve this problem Please
Thanx
Lyberty

Get the level numeric value?

If I wanted to use npmlog.level as the source of truth for the logging state in my application how could I get access to the numeric value of the level?

Ie. so I can do...

if (npmlog.levelValue > npmlog.levels.info) { 
  // do something other than just logging that could be based off of this value
}

Atm I have to create another map of level values to their associated numeric values. Would hope that the package could provide it?

TypeError: log.gauge.isEnabled is not a function

I have got the following package.json script definition:

{
    "scripts": {
        "build-css": "node-sass-chokidar --importer=node_modules/node-sass-tilde-importer src/ -o src/"
     }
}

When I run it, it produces the following crash:

[build-css] C:\Projects\Other\react-site\node_modules\npm\node_modules\npmlog\log.js:57
log.progressEnabled = log.gauge.isEnabled()
                                ^

TypeError: log.gauge.isEnabled is not a function
    at Object.<anonymous> (C:\Projects\Other\react-site\node_modules\npm\node_modules\npmlog\log.js:57:33)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Module.require (module.js:579:17)
    at require (internal/module.js:11:18)
    at C:\Projects\Other\react-site\node_modules\npm\bin\npm-cli.js:19:13
    at Object.<anonymous> (C:\Projects\Other\react-site\node_modules\npm\bin\npm-cli.js:75:3)

I have commented out the line log.progressEnabled = log.gauge.isEnabled(), and it started working now.

Provide a way to create "namespaced" log objects

I'd like a way to create "namespaced" loggers which would eliminate the need to provide the prefix to the log methods. Here's how I'd imagine it working:

var npmlog = require('npmlog');
// This is the type of method I'd like added to npmlog proper
npmlog.ns = function namespaceLogger(namespace){
  var logger = {};
  for (var k in this.levels) {
    logger[k] = this[k].bind(this, namespace);
  }
  return logger;
}

var customLog = npmlog.ns('Custom');
customLog.info('Hello %s!', 'World');
// >> info Custom Hello World!

Obviously this only supports the log[level](prefix, message, ...) syntax, but it could probably be improved to support all the npmlog methods.

Log messages flushing after tasks complete

Hi! Apologies if this turns out the be the wrong repo to file this against — I haven't fully wrapped my head around the interplay between npmlog, gauge, are-we-there-yet and the stuff in npm's install command that wraps that all together.

We found in ember-cli/ember-cli#6306 that some final messages/progress bar updates are being printed after the callback given to npm's install command has been invoked. It looks as though no new messages are being emitted from npm after the callback is called, but the periodic flushing of queued up messages continues more or less on autopilot.

I'd be happy to put together a PR to prevent that from happening, but wanted to check in before I spend too much time going down the wrong rabbithole — are there changes to be made here or in one of the other constituent libraries to handle this scenario, or are there additional steps that need to be taken on npm's side to either force a flush or drop the queued updates?

TypeError: log.gauge.isEnabled is not a function

/Users/tyler.liu/src/electron/swagger-app/node_modules/npm/node_modules/npmlog/log.js:57
log.progressEnabled = log.gauge.isEnabled()
                                ^

TypeError: log.gauge.isEnabled is not a function
    at Object.<anonymous> (/Users/tyler.liu/src/electron/swagger-app/node_modules/npm/node_modules/npmlog/log.js:57:33)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/tyler.liu/src/electron/swagger-app/node_modules/npm/lib/utils/umask.js:2:14)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)

How to reproduce

Clone https://github.com/chentsulin/electron-react-boilerplate

yarn install

yarn add npm-check-updates

ncu -ua && yarn upgrade

ncu -ua && yarn upgrade

Run the last command twice to reproduce the issue.

Update

The problem is still present.

I created my own package yarn-upgrade-all to replace npm-check-updates.

[BUG] v5.0.0 - Error: Cannot find module 'object-assign'

What / Why

When requiring v5.0.0 there is an error thrown 'Cannot find module 'object-assign''

When

require("npmlog");

Where

  • npm/npmlog

How

Current Behavior

An error is thrown when the module is required.

Error: Cannot find module 'object-assign'
Require stack:
- ~/tmp/npmlog-issue/node_modules/gauge/theme-set.js
- ~/tmp/npmlog-issue/node_modules/gauge/themes.js
- ~/tmp/npmlog-issue/node_modules/gauge/index.js
- ~/tmp/npmlog-issue/node_modules/npmlog/log.js
- internal/preload
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (~/tmp/npmlog-issue/node_modules/gauge/theme-set.js:2:20)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '~/tmp/npmlog-issue/node_modules/gauge/theme-set.js',
    '~/tmp/npmlog-issue/node_modules/gauge/themes.js',
    '~/tmp/npmlog-issue/node_modules/gauge/index.js',
    '~/tmp/npmlog-issue/node_modules/npmlog/log.js',
    'internal/preload'
  ]
}

Steps to Reproduce

  • Node.js v14.15.5
  • npm v6.14.11
  • macOS 11.4
npm init --yes && npm i [email protected] && node -r npmlog

Expected Behavior

  • There shouldn't be an error when the module is required

Who

  • n/a

References

Unnecessary processing incase the log level is lower than the set level.

I set the log level to "INFO" on production systems .

My code had a lot of verbose statements spread across it and in some cases , there was a massive json placed inside the logger. This led to a severe spike in latency on the average response times.

There already is an option of not writing to the stdout if the statement log level is lower than the general setting but we still do a lot of unnecessary processing in the log.log function (the culprit in my case was util.format)

Can we had the log level check in the log.log function itself ? Or is there some reason that you've added this in the emitLog function ?

Thanks .

Latest version has broken node-gyp

As of 2 hours ago new installs of electron-rebuild started failing with this error

gyp ERR! UNCAUGHT EXCEPTION 
gyp ERR! stack TypeError: Property description must be an object: Error: not found: python2
gyp ERR! stack     at getNotFoundError (/Users/sattard/projects/electron-rebuild/node_modules/which/which.js:13:12)
gyp ERR! stack     at F (/Users/sattard/projects/electron-rebuild/node_modules/which/which.js:68:19)
gyp ERR! stack     at E (/Users/sattard/projects/electron-rebuild/node_modules/which/which.js:80:29)
gyp ERR! stack     at /Users/sattard/projects/electron-rebuild/node_modules/which/which.js:89:16
gyp ERR! stack     at /Users/sattard/projects/electron-rebuild/node_modules/isexe/index.js:42:5
gyp ERR! stack     at /Users/sattard/projects/electron-rebuild/node_modules/isexe/mode.js:8:5
gyp ERR! stack     at FSReqWrap.oncomplete (fs.js:123:15)
gyp ERR! stack     at Function.defineProperty (native)
gyp ERR! stack     at EventEmitter.<anonymous> (/Users/sattard/projects/electron-rebuild/node_modules/npmlog/log.js:185:14)
gyp ERR! stack     at EventEmitter.<anonymous> (/Users/sattard/projects/electron-rebuild/node_modules/npmlog/log.js:281:23)
gyp ERR! stack     at Object.<anonymous> (/Users/sattard/projects/electron-rebuild/node_modules/node-gyp/lib/configure.js:389:18)
gyp ERR! stack     at F (/Users/sattard/projects/electron-rebuild/node_modules/which/which.js:68:16)
gyp ERR! stack     at E (/Users/sattard/projects/electron-rebuild/node_modules/which/which.js:80:29)
gyp ERR! stack     at /Users/sattard/projects/electron-rebuild/node_modules/which/which.js:89:16
gyp ERR! stack     at /Users/sattard/projects/electron-rebuild/node_modules/isexe/index.js:42:5
gyp ERR! stack     at /Users/sattard/projects/electron-rebuild/node_modules/isexe/mode.js:8:5
gyp ERR! stack     at FSReqWrap.oncomplete (fs.js:123:15)
gyp ERR! System Darwin 16.5.0

This error was tracked back to this commit --> c074712

Which appears to be invalid syntax as the third parameter for Object.defineProperty should be an object (the descriptor). See the docs

This needs to be reverted ASAP as all new installs of node-gyp will be failing.

/cc @iarna

[BUG] Changelog not updated for v6

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

The CHANGELOG.md file both at HEAD and in the v6.0.0 tag is still the 5.0.1 changelog. It's more difficult to get people to upgrade if they are forced to inspect commit history.

Expected Behavior

CHANGELOG.md contains list of changes for 6.0.0 release.

Steps To Reproduce

N/A

Environment

N/A

Constructor name

Not really a bug, but a bit confusing:

var log = exports = module.exports = new EE

It would be nice if the constructor name was something like NpmLog.

Missing methods are now blamed on EventEmitter.

var log = require('npmlog');
log.debug('test');
    ^
TypeError: Object #<EventEmitter> has no method 'debug'
    at Object.<anonymous> (/home/rhalff/git/fbpx-cli/test.js:3:5)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:902:3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.