版博士V2.0程序
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. # npmlog
  2. The logger util that npm uses.
  3. This logger is very basic. It does the logging for npm. It supports
  4. custom levels and colored output.
  5. By default, logs are written to stderr. If you want to send log messages
  6. to outputs other than streams, then you can change the `log.stream`
  7. member, or you can just listen to the events that it emits, and do
  8. whatever you want with them.
  9. # Installation
  10. ```console
  11. npm install npmlog --save
  12. ```
  13. # Basic Usage
  14. ```javascript
  15. var log = require('npmlog')
  16. // additional stuff ---------------------------+
  17. // message ----------+ |
  18. // prefix ----+ | |
  19. // level -+ | | |
  20. // v v v v
  21. log.info('fyi', 'I have a kitty cat: %j', myKittyCat)
  22. ```
  23. ## log.level
  24. * {String}
  25. The level to display logs at. Any logs at or above this level will be
  26. displayed. The special level `silent` will prevent anything from being
  27. displayed ever.
  28. ## log.record
  29. * {Array}
  30. An array of all the log messages that have been entered.
  31. ## log.maxRecordSize
  32. * {Number}
  33. The maximum number of records to keep. If log.record gets bigger than
  34. 10% over this value, then it is sliced down to 90% of this value.
  35. The reason for the 10% window is so that it doesn't have to resize a
  36. large array on every log entry.
  37. ## log.prefixStyle
  38. * {Object}
  39. A style object that specifies how prefixes are styled. (See below)
  40. ## log.headingStyle
  41. * {Object}
  42. A style object that specifies how the heading is styled. (See below)
  43. ## log.heading
  44. * {String} Default: ""
  45. If set, a heading that is printed at the start of every line.
  46. ## log.stream
  47. * {Stream} Default: `process.stderr`
  48. The stream where output is written.
  49. ## log.enableColor()
  50. Force colors to be used on all messages, regardless of the output
  51. stream.
  52. ## log.disableColor()
  53. Disable colors on all messages.
  54. ## log.enableProgress()
  55. Enable the display of log activity spinner and progress bar
  56. ## log.disableProgress()
  57. Disable the display of a progress bar
  58. ## log.enableUnicode()
  59. Force the unicode theme to be used for the progress bar.
  60. ## log.disableUnicode()
  61. Disable the use of unicode in the progress bar.
  62. ## log.setGaugeTemplate(template)
  63. Set a template for outputting the progress bar. See the [gauge documentation] for details.
  64. [gauge documentation]: https://npmjs.com/package/gauge
  65. ## log.setGaugeThemeset(themes)
  66. Select a themeset to pick themes from for the progress bar. See the [gauge documentation] for details.
  67. ## log.pause()
  68. Stop emitting messages to the stream, but do not drop them.
  69. ## log.resume()
  70. Emit all buffered messages that were written while paused.
  71. ## log.log(level, prefix, message, ...)
  72. * `level` {String} The level to emit the message at
  73. * `prefix` {String} A string prefix. Set to "" to skip.
  74. * `message...` Arguments to `util.format`
  75. Emit a log message at the specified level.
  76. ## log\[level](prefix, message, ...)
  77. For example,
  78. * log.silly(prefix, message, ...)
  79. * log.verbose(prefix, message, ...)
  80. * log.info(prefix, message, ...)
  81. * log.http(prefix, message, ...)
  82. * log.warn(prefix, message, ...)
  83. * log.error(prefix, message, ...)
  84. Like `log.log(level, prefix, message, ...)`. In this way, each level is
  85. given a shorthand, so you can do `log.info(prefix, message)`.
  86. ## log.addLevel(level, n, style, disp)
  87. * `level` {String} Level indicator
  88. * `n` {Number} The numeric level
  89. * `style` {Object} Object with fg, bg, inverse, etc.
  90. * `disp` {String} Optional replacement for `level` in the output.
  91. Sets up a new level with a shorthand function and so forth.
  92. Note that if the number is `Infinity`, then setting the level to that
  93. will cause all log messages to be suppressed. If the number is
  94. `-Infinity`, then the only way to show it is to enable all log messages.
  95. ## log.newItem(name, todo, weight)
  96. * `name` {String} Optional; progress item name.
  97. * `todo` {Number} Optional; total amount of work to be done. Default 0.
  98. * `weight` {Number} Optional; the weight of this item relative to others. Default 1.
  99. This adds a new `are-we-there-yet` item tracker to the progress tracker. The
  100. object returned has the `log[level]` methods but is otherwise an
  101. `are-we-there-yet` `Tracker` object.
  102. ## log.newStream(name, todo, weight)
  103. This adds a new `are-we-there-yet` stream tracker to the progress tracker. The
  104. object returned has the `log[level]` methods but is otherwise an
  105. `are-we-there-yet` `TrackerStream` object.
  106. ## log.newGroup(name, weight)
  107. This adds a new `are-we-there-yet` tracker group to the progress tracker. The
  108. object returned has the `log[level]` methods but is otherwise an
  109. `are-we-there-yet` `TrackerGroup` object.
  110. # Events
  111. Events are all emitted with the message object.
  112. * `log` Emitted for all messages
  113. * `log.<level>` Emitted for all messages with the `<level>` level.
  114. * `<prefix>` Messages with prefixes also emit their prefix as an event.
  115. # Style Objects
  116. Style objects can have the following fields:
  117. * `fg` {String} Color for the foreground text
  118. * `bg` {String} Color for the background
  119. * `bold`, `inverse`, `underline` {Boolean} Set the associated property
  120. * `bell` {Boolean} Make a noise (This is pretty annoying, probably.)
  121. # Message Objects
  122. Every log event is emitted with a message object, and the `log.record`
  123. list contains all of them that have been created. They have the
  124. following fields:
  125. * `id` {Number}
  126. * `level` {String}
  127. * `prefix` {String}
  128. * `message` {String} Result of `util.format()`
  129. * `messageRaw` {Array} Arguments to `util.format()`
  130. # Blocking TTYs
  131. We use [`set-blocking`](https://npmjs.com/package/set-blocking) to set
  132. stderr and stdout blocking if they are tty's and have the setBlocking call.
  133. This is a work around for an issue in early versions of Node.js 6.x, which
  134. made stderr and stdout non-blocking on OSX. (They are always blocking
  135. Windows and were never blocking on Linux.) `npmlog` needs them to be blocking
  136. so that it can allow output to stdout and stderr to be interlaced.