• Stars
    star
    423
  • Rank 98,865 (Top 3 %)
  • Language
    JavaScript
  • License
    Other
  • Created almost 12 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The logger that npm uses

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.

More Repositories

1

npm

This repository is moving to: https://github.com/npm/cli
17,473
star
2

cli

the package manager for JavaScript
JavaScript
8,032
star
3

node-semver

The semver parser for node (the one npm uses)
JavaScript
4,772
star
4

npm-expansions

Send us a pull request by editing expansions.txt
JavaScript
2,209
star
5

tink

a dependency unwinder for javascript
JavaScript
2,156
star
6

ini

An ini parser/serializer in JavaScript
JavaScript
733
star
7

npx

npm package executor
JavaScript
721
star
8

rfcs

Public change requests/proposals & ideation
JavaScript
711
star
9

npm-registry-couchapp

couchapp bits of registry.npmjs.org
JavaScript
615
star
10

nopt

Node/npm Option Parsing
JavaScript
527
star
11

registry

npm registry documentation
422
star
12

marky-markdown

npm's markdown parser
JavaScript
406
star
13

arborist

npm's tree doctor
JavaScript
370
star
14

pacote

npm fetcher
JavaScript
329
star
15

download-counts

Background jobs and a minimal service for collecting and delivering download counts
JavaScript
328
star
16

gauge

A terminal based horizontal guage aka, a progress bar
JavaScript
319
star
17

node-which

Like which(1) unix command. Find the first instance of an executable in the PATH.
JavaScript
305
star
18

documentation

Documentation for the npm registry, website, and command-line interface.
MDX
291
star
19

init-package-json

A node module to get your node module started
JavaScript
284
star
20

validate-npm-package-name

Is the given string an acceptable npm package name?
JavaScript
282
star
21

npm-merge-driver

git merge driver for resolving conflicts in npm-related files
JavaScript
271
star
22

cacache

npm's content-addressable cache
JavaScript
266
star
23

npm-registry-client

JavaScript
264
star
24

lockfile

A very polite lock file utility, which endeavors to not litter, and to wait patiently for others.
JavaScript
259
star
25

registry-issue-archive

An archive of the old npm registry issue tracker
250
star
26

write-file-atomic

Write files in an atomic fashion w/configurable ownership
JavaScript
217
star
27

read-package-json

The thing npm uses to read package.json files with semantics and defaults and validation and stuff
JavaScript
214
star
28

roadmap

Public roadmap for npm
214
star
29

hosted-git-info

Provides metadata and conversions from repository urls for Github, Bitbucket and Gitlab
JavaScript
206
star
30

fstream

Advanced FS Streaming for Node
JavaScript
205
star
31

read

read(1) for node.
JavaScript
187
star
32

normalize-package-data

normalizes package metadata, typically found in package.json file.
JavaScript
184
star
33

make-fetch-happen

making fetch happen for npm
JavaScript
183
star
34

ndm

ndm allows you to deploy OS-specific service-wrappers directly from npm-packages.
JavaScript
181
star
35

are-we-there-yet

Track complex hiearchies of asynchronous task completion statuses.
JavaScript
173
star
36

abbrev-js

Like ruby's Abbrev module
JavaScript
158
star
37

statusboard

Public monitor/status/health board for @npm/cli-team's maintained projects
JavaScript
146
star
38

security-holder

An npm package that holds a spot.
145
star
39

feedback

Public feedback discussions for npm
138
star
40

osenv

Look up environment settings specific to different operating systems.
JavaScript
137
star
41

npm-registry-fetch

like fetch() but for the npm registry
JavaScript
118
star
42

npm-package-arg

Parse the things that can be arguments to `npm install`
JavaScript
116
star
43

libnpm

programmatic npm API
JavaScript
113
star
44

npm-collection-staff-picks

JavaScript
112
star
45

promzard

A prompting json thingie
JavaScript
101
star
46

npm-packlist

Walk through a folder and figure out what goes in an npm package
JavaScript
101
star
47

npm-remote-ls

Examine a package's dependency graph before you install it
JavaScript
89
star
48

npmconf

npm config thing
JavaScript
75
star
49

cmd-shim

The cmd-shim used in npm
JavaScript
75
star
50

npm-tips

A collection of short (5 words or so) tips and tricks that can be sprinkled about the npm site.
JavaScript
73
star
51

www

community space for the npm website
68
star
52

policies

Privacy policy, code of conduct, license, and other npm legal stuff
Shell
67
star
53

npm_conf

A conference about npm, maybe. Not to be confused with npmconf.
59
star
54

git

a util for spawning git from npm CLI contexts
JavaScript
58
star
55

registry-follower-tutorial

write you a registry follower for great good
JavaScript
56
star
56

ignore-walk

Nested/recursive `.gitignore`/`.npmignore` parsing and filtering.
JavaScript
55
star
57

ci-detect

Detect what kind of CI environment the program is in
JavaScript
53
star
58

ssri

subresource integrity for npm
JavaScript
53
star
59

read-installed

Read all the installed packages in a folder, and return a tree structure with all the data.
JavaScript
52
star
60

run-script

Run a lifecycle script for a package (descendant of npm-lifecycle)
JavaScript
51
star
61

minipass-fetch

An implementation of window.fetch in Node.js using Minipass streams
JavaScript
51
star
62

package-json

Programmatic API to update package.json
JavaScript
50
star
63

mute-stream

Bytes go in, but they don't come out (when muted).
JavaScript
49
star
64

fs-write-stream-atomic

Like `fs.createWriteStream(...)`, but atomic.
JavaScript
48
star
65

libnpmpublish

programmatically publish and unpublish npm packages
JavaScript
46
star
66

read-package-json-fast

Like read-package-json, but faster
JavaScript
46
star
67

logical-tree

Calculates a nested logical tree using a package.json and a package lock.
JavaScript
44
star
68

read-package-tree

Read the contents of node_modules
JavaScript
42
star
69

jobs

41
star
70

unique-filename

Generate a unique filename for use in temporary directories or caches.
JavaScript
40
star
71

lock-verify

Report if your package.json is out of sync with your package-lock.json
JavaScript
38
star
72

npm-lifecycle

npm lifecycle script runner
JavaScript
37
star
73

fstream-ignore

JavaScript
37
star
74

wombat-cli

The wombat cli tool.
JavaScript
35
star
75

npme-installer

npm Enterprise installer
JavaScript
35
star
76

benchmarks

The npm CLI's benchmark suite
JavaScript
33
star
77

couch-login

A module for doing logged-in requests against a couchdb server
JavaScript
33
star
78

npm-audit-report

npm audit security report
JavaScript
33
star
79

libnpmexec

npm exec (npx) Programmatic API
JavaScript
33
star
80

ansible-nagios

Ansible role for building Nagios 4.
Perl
32
star
81

config

Configuration management for https://github.com/npm/cli
JavaScript
32
star
82

npm-profile

Make changes to your npmjs.com profile via cli or library
JavaScript
31
star
83

unique-slug

Generate a unique character string suitible for use in files and URLs.
JavaScript
31
star
84

parse-conflict-json

Parse a JSON string that has git merge conflicts, resolving if possible
JavaScript
31
star
85

fstream-npm

fstream class for creating npm packages
JavaScript
30
star
86

redsess

Yet another redis session thing for node.
JavaScript
30
star
87

concurrent-couch-follower

a couch follower wrapper that you can use to be sure you don't miss any documents even if you process them asynchronously.
JavaScript
28
star
88

npm-registry-mock

mock the npm registry
JavaScript
27
star
89

lint

lint the npmcli way
JavaScript
26
star
90

libnpmsearch

programmatic API for the shiny new npm search endpoint
JavaScript
25
star
91

fs

filesystem helper functions, wrappers, and promisification for the npm cli
JavaScript
24
star
92

libnpmaccess

programmatic api for `npm access`
JavaScript
24
star
93

bin-links

.bin/ script linker
JavaScript
23
star
94

logos

official logos for npm, Inc
22
star
95

public-api

21
star
96

deprecate-holder

An npm package that holds a spot.
21
star
97

libnpmversion

library to do the things that 'npm version' does
JavaScript
20
star
98

ui

user interface layer for the npm CLI
19
star
99

captain-hook

slack bot that provides subscription service for npm webhooks
JavaScript
19
star
100

npm-hook-slack

Report on registry events to slack, tersely.
JavaScript
19
star