├── .github ├── CODEOWNERS ├── PULL_REQUEST_TEMPLATE.md └── ISSUE_TEMPLATE.md ├── docs ├── output.png └── logo.svg ├── .prettierignore ├── .gitignore ├── commitlint.config.js ├── husky.config.js ├── .eslintrc ├── lint-staged.config.js ├── jest.config.js ├── .editorconfig ├── .prettierrc.js ├── .travis.yml ├── CHANGELOG.md ├── test ├── __snapshots__ │ └── test.js.snap └── test.js ├── LICENSE ├── package.json ├── CONTRIBUTING.md ├── src └── index.js └── README.md /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @webpack-contrib/org-maintainers 2 | -------------------------------------------------------------------------------- /docs/output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webpack-contrib/webpack-log/HEAD/docs/output.png -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | coverage 2 | .nyc_output 3 | node_modules 4 | CHANGELOG.md 5 | package-lock.json 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .DS_Store 3 | 4 | npm-debug.log 5 | 6 | .nyc_output 7 | 8 | coverage 9 | node_modules 10 | -------------------------------------------------------------------------------- /commitlint.config.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | extends: ['@commitlint/config-conventional'], 5 | }; 6 | -------------------------------------------------------------------------------- /husky.config.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | hooks: { 5 | 'pre-commit': 'lint-staged', 6 | 'commit-msg': 'commitlint -E HUSKY_GIT_PARAMS', 7 | }, 8 | }; 9 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["webpack", "prettier"], 3 | "parserOptions": { 4 | "sourceType": "script" 5 | }, 6 | "rules": { 7 | "strict": ["error", "safe"] 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /lint-staged.config.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | '*.js': ['prettier --write', 'eslint --fix', 'git add'], 5 | '*.{json,md,yml,css}': ['prettier --write', 'git add'], 6 | }; 7 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | testURL: 'http://localhost/', 5 | collectCoverage: true, 6 | coveragePathIgnorePatterns: ['test'], 7 | moduleFileExtensions: ['js', 'json'], 8 | testMatch: ['**/test/**/*.js'], 9 | }; 10 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | 3 | [*] 4 | charset = utf-8 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | insert_final_newline = false 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | printWidth: 80, 3 | tabWidth: 2, 4 | singleQuote: true, 5 | trailingComma: 'es5', 6 | arrowParens: 'always', 7 | overrides: [ 8 | { 9 | files: '*.json', 10 | options: { 11 | useTabs: false, 12 | }, 13 | }, 14 | ], 15 | }; 16 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | jobs: 4 | fast_finish: true 5 | include: 6 | - stage: Lint 7 | env: SCRIPT=lint 8 | node_js: 'stable' 9 | - &test 10 | stage: Test 11 | env: SCRIPT=test 12 | node_js: 'stable' 13 | - <<: *test 14 | node_js: 'lts/*' 15 | - <<: *test 16 | node_js: 6 17 | 18 | script: npm run $SCRIPT 19 | 20 | after_success: 21 | - npm i codecov 22 | - $(npm bin)/codecov 23 | 24 | notifications: 25 | email: false 26 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. 4 | 5 | 6 | # [2.0.0](https://github.com/webpack-contrib/webpack-log/compare/v1.2.0...v2.0.0) (2018-08-23) 7 | 8 | 9 | ### Code Refactoring 10 | 11 | * **package:** replace `chalk` with `ansi-colors` (`dependencies`) ([#4](https://github.com/webpack-contrib/webpack-log/issues/4)) ([5b793d4](https://github.com/webpack-contrib/webpack-log/commit/5b793d4)) 12 | 13 | 14 | ### BREAKING CHANGES 15 | 16 | * **package:** `module.exports.chalk` was renamed to `module.exports.colors` 17 | -------------------------------------------------------------------------------- /test/__snapshots__/test.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`log should log for unique loggers 1`] = `"ℹ 「wds」: webpack-dev-server"`; 4 | 5 | exports[`log should log for unique loggers 2`] = `"ℹ 「wdm」: webpack-dev-middleware"`; 6 | 7 | exports[`log should return logs with prefix 1`] = `"₸ 「wds」: webpack-dev-server"`; 8 | 9 | exports[`log should return logs with prefix 2`] = `"ℹ 「wds」: webpack-dev-server"`; 10 | 11 | exports[`log should return logs with prefix 3`] = `"⚠ 「wds」: webpack-dev-server"`; 12 | 13 | exports[`log should return logs with prefix 4`] = `"Trace: ₸ 「wds」: webpack-dev-server"`; 14 | 15 | exports[`log should return no color string 1`] = `"「wds」: webpack-dev-server"`; 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright JS Foundation and other contributors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 9 | 10 | - [ ] This is a **bugfix** 11 | - [ ] This is a new **feature** 12 | - [ ] This is a **code refactor** 13 | - [ ] This is a **test update** 14 | - [ ] This is a **typo fix** 15 | - [ ] This is a **metadata update** 16 | 17 | ### For Bugs and Features; did you add new tests? 18 | 19 | 20 | 21 | ### Motivation / Use-Case 22 | 23 | 28 | 29 | ### Breaking Changes 30 | 31 | 35 | 36 | ### Additional Info 37 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "webpack-log", 3 | "version": "2.0.0", 4 | "description": "A common logger for the webpack ecosystem", 5 | "main": "src/index.js", 6 | "files": [ 7 | "src" 8 | ], 9 | "engines": { 10 | "node": ">= 6" 11 | }, 12 | "scripts": { 13 | "lint": "npm run lint:js && npm run lint:prettier", 14 | "lint:js": "eslint src test", 15 | "lint:prettier": "prettier \"{**/*,*}.{js,,md}\" --list-different", 16 | "test": "jest", 17 | "release": "standard-version" 18 | }, 19 | "dependencies": { 20 | "ansi-colors": "^4.1.1", 21 | "loglevelnext": "^1.0.1", 22 | "uuid": "^3.3.2" 23 | }, 24 | "devDependencies": { 25 | "@commitlint/config-conventional": "^8.0.0", 26 | "commitlint": "^8.0.0", 27 | "eslint": "^5.4.0", 28 | "eslint-config-prettier": "^6.0.0", 29 | "eslint-config-webpack": "^1.2.5", 30 | "eslint-plugin-import": "^2.14.0", 31 | "husky": "^3.0.0", 32 | "jest": "^24.8.0", 33 | "lint-staged": "^9.2.0", 34 | "prettier": "^1.18.2", 35 | "standard-version": "^4.4.0", 36 | "strip-ansi": "^4.0.0" 37 | }, 38 | "author": "Andrew Powell ", 39 | "issues": "https://github.com/webpack-contrib/webpack-log/issues", 40 | "homepage": "https://github.com/webpack-contrib/webpack-log#readme", 41 | "repository": "https://github.com/webpack-contrib/webpack-log.git", 42 | "license": "MIT" 43 | } 44 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 8 | 9 | - Operating System: 10 | - Node Version: 11 | - NPM Version: 12 | - webpack Version: 13 | - webpack-dev-server Version: 14 | 15 | 16 | 17 | - [ ] This is a **bug** 18 | - [ ] This is a **feature** request 19 | - [ ] This is a **modification** request 20 | 21 | ### Code 22 | 23 | 36 | 37 | ```js 38 | // webpack.config.js 39 | ``` 40 | 41 | ```js 42 | // additional code, remove if not needed. 43 | ``` 44 | 45 | ### Expected Behavior 46 | 47 | ### Actual Behavior 48 | 49 | ### For Bugs; How can we reproduce the behavior? 50 | 51 | ### For Features; What is the motivation and/or use-case for the feature? 52 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Welcome! 2 | 3 | :heart: Thanks for your interest and time in contributing to this project. 4 | 5 | ## What We Use 6 | 7 | - Building: [Webpack](https://webpack.js.org) 8 | - Linting: [ESLint](http://eslint.org/) 9 | - NPM: [NPM as a Build Tool](https://css-tricks.com/using-npm-build-tool/) 10 | - Testing: [Mocha](https://mochajs.org) 11 | 12 | ## Forking and Cloning 13 | 14 | You'll need to first fork this repository, and then clone it locally before you 15 | can submit a Pull Request with your proposed changes. 16 | 17 | Please see the following articles for help getting started with git: 18 | 19 | [Forking a Repository](https://help.github.com/articles/fork-a-repo/) 20 | [Cloning a Repository](https://help.github.com/articles/cloning-a-repository/) 21 | 22 | ## Pull Requests 23 | 24 | Please lint and test your changes before submitting a Pull Request. You can lint your 25 | changes by running: 26 | 27 | ```console 28 | $ npm run lint 29 | ``` 30 | 31 | You can test your changes against the test suite for this module by running: 32 | 33 | ```console 34 | $ npm run test 35 | ``` 36 | 37 | _Note: Please avoid committing `package-lock.json` files!_ 38 | 39 | Please don't change variable or parameter names to match your personal 40 | preferences, unless the change is part of a refactor or significant modification 41 | of the codebase (which is very rare). 42 | 43 | Please remember to thoroughly explain your Pull Request if it doesn't have an 44 | associated issue. If you're changing code significantly, please remember to add 45 | inline or block comments in the code as appropriate. 46 | 47 | ## Testing Your Pull Request 48 | 49 | You may have the need to test your changes in a real-world project or dependent 50 | module. Thankfully, Github provides a means to do this. Add a dependency to the 51 | `package.json` for such a project as follows: 52 | 53 | ```json 54 | "webpack-logger": "webpack-contrib/webpack-log#{id}/head" 55 | ``` 56 | 57 | Where `{id}` is the # ID of your Pull Request. 58 | 59 | ## Thanks 60 | 61 | For your interest, time, understanding, and for following this simple guide. 62 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* global window: true */ 4 | /* eslint-disable 5 | no-shadow, 6 | no-param-reassign, 7 | space-before-function-paren 8 | */ 9 | const uuid = require('uuid/v4'); 10 | const colors = require('ansi-colors'); 11 | const loglevel = require('loglevelnext'); 12 | 13 | const symbols = { 14 | trace: colors.grey('₸'), 15 | debug: colors.cyan('➤'), 16 | info: colors.blue(colors.symbols.info), 17 | warn: colors.yellow(colors.symbols.warning), 18 | error: colors.red(colors.symbols.cross), 19 | }; 20 | 21 | const defaults = { 22 | name: '', 23 | level: 'info', 24 | unique: true, 25 | color: true, 26 | }; 27 | 28 | const prefix = { 29 | level(options) { 30 | return symbols[options.level]; 31 | }, 32 | template: `{{level}} ${colors.gray('「{{name}}」')}: `, 33 | }; 34 | 35 | const noColorPrefix = { 36 | template: '「{{name}}」: ', 37 | }; 38 | 39 | function log(options) { 40 | const opts = Object.assign({}, defaults, options); 41 | const { id } = options; 42 | opts.prefix = Object.assign( 43 | {}, 44 | opts.color ? prefix : noColorPrefix, 45 | options.prefix 46 | ); 47 | delete opts.id; 48 | 49 | Object.defineProperty(opts, 'id', { 50 | get() { 51 | if (!id) { 52 | return this.name + (opts.unique ? `-${uuid()}` : ''); 53 | } 54 | 55 | return id; 56 | }, 57 | }); 58 | 59 | if (opts.timestamp) { 60 | opts.prefix.template = `[{{time}}] ${opts.prefix.template}`; 61 | } 62 | 63 | const log = loglevel.getLogger(opts); 64 | 65 | if (!Object.prototype.hasOwnProperty.call(log, 'id')) { 66 | Object.defineProperty(log, 'id', { 67 | get() { 68 | return opts.id; 69 | }, 70 | }); 71 | } 72 | 73 | return log; 74 | } 75 | 76 | module.exports = log; 77 | // NOTE: this is exported so that consumers of webpack-log can use the same 78 | // version of ansi-colors to decorate log messages without incurring additional 79 | // dependency overhead 80 | module.exports.colors = colors; 81 | // NOTE: This is an undocumented function solely for the purpose of tests. 82 | // Do not use this method in production code. Using in production code 83 | // may result in strange behavior. 84 | module.exports.delLogger = function delLogger(name) { 85 | delete loglevel.loggers[name]; 86 | }; 87 | 88 | module.exports.factories = loglevel.factories; 89 | -------------------------------------------------------------------------------- /docs/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [DEPRECATED] Plese use logger api https://github.com/webpack/webpack/pull/9436 2 | 3 | [![npm][npm]][npm-url] 4 | [![node][node]][node-url] 5 | [![deps][deps]][deps-url] 6 | [![test][test]][test-url] 7 | [![coverage][cover]][cover-url] 8 | [![chat][chat]][chat-url] 9 | 10 |
11 | 12 | 13 | 14 | 15 |

webpack Log

16 |

A common logging module for the webpack ecosystem

17 |
18 | 19 | ## Install 20 | 21 | ```bash 22 | npm i -D webpack-log 23 | ``` 24 | 25 | > ⚠️ We do not recommend installing this module globally 26 | 27 | ## Usage 28 | 29 | ```js 30 | const log = require('webpack-log'); 31 | const logger = log({ name: 'wds' }); 32 | 33 | logger.info('Server Starting'); 34 | ``` 35 | 36 | ![output](docs/output.png) 37 | 38 | > ℹ️ The logger returned is unique by default, due to the nature of the `webpack` ecosystem. Please reference the [`unique`](#unique) option below for disabling this feature and to **force caching** 39 | 40 | ## Options 41 | 42 | | Name | Type | Default | Description | 43 | | :---------------------------: | :---------: | :------------: | :---------------------- | 44 | | [**`name`**](#name) | `{String}` | `'''` | Log Name (**Required**) | 45 | | [**`level`**](#level) | `{String}` | `'info'` | Log Level | 46 | | [**`unique`**](#unique) | `{Boolean}` | `true` | Log Uniqueness | 47 | | [**`timestamp`**](#timestamp) | `{Boolean}` | `false` | Log Timestamps | 48 | 49 | ### `name` 50 | 51 | Specifies the name of the log to create. **This option is required**, and used to differentiate between loggers when `webpack-log` is used in multiple projects 52 | executing in the same process 53 | 54 | ```js 55 | const logger = log({ name: 'wds' }); 56 | ``` 57 | 58 | ### `level` 59 | 60 | Specifies the level the logger should use. A logger will not produce output for 61 | any log level _beneath_ the specified level. Available levels and order are: 62 | 63 | ```js 64 | ['info', 'warn', 'error', 'trace', 'debug', 'silent']; 65 | ``` 66 | 67 | ```js 68 | const logger = log({ level: 'error' }); 69 | 70 | logger.error(err); 71 | ``` 72 | 73 | > ℹ️ The level names shown above correspond to the available logging methods, 74 | > with the notable exception of the `silent` level 75 | 76 | ### `unique` 77 | 78 | If `false`, instructs the logger to used cached versions of a log with the same name. Due to the nature of the `webpack` ecosystem and multiple plugin/loader usage in the same process, loggers are created as unique instances by default. By passing `false` for this property, the module is instructed to cache the requested logger 79 | 80 | ```js 81 | const logger = log({ unique: true }); 82 | ``` 83 | 84 | ### `timestamp` 85 | 86 | If `true`, instructs the logger to display a timestamp for log output, preceding 87 | all other data 88 | 89 | ```js 90 | const logger = log({ timestamp: true }); 91 | ``` 92 | 93 | [npm]: https://img.shields.io/npm/v/webpack-log.svg 94 | [npm-url]: https://npmjs.com/package/webpack-log 95 | [node]: https://img.shields.io/node/v/webpack-log.svg 96 | [node-url]: https://nodejs.org 97 | [deps]: https://david-dm.org/webpack-contrib/webpack-log.svg 98 | [deps-url]: https://david-dm.org/webpack-contrib/webpack-log 99 | [test]: http://img.shields.io/travis/webpack-contrib/webpack-log.svg 100 | [test-url]: https://travis-ci.org/webpack-contrib/webpack-log 101 | [cover]: https://codecov.io/gh/webpack-contrib/webpack-log/branch/master/graph/badge.svg 102 | [cover-url]: https://codecov.io/gh/webpack-contrib/webpack-log 103 | [chat]: https://badges.gitter.im/webpack/webpack.svg 104 | [chat-url]: https://gitter.im/webpack/webpack 105 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* eslint-disable 4 | no-console, 5 | global-require, 6 | import/order, 7 | import/no-extraneous-dependencies 8 | */ 9 | const strip = require('strip-ansi'); 10 | const weblog = require('../src'); 11 | 12 | describe('log', () => { 13 | let consoleInfoMock; 14 | let consoleWarnMock; 15 | let consoleDebugMock; 16 | let consoleTraceMock; 17 | let consoleErrorMock; 18 | 19 | beforeEach(() => { 20 | consoleInfoMock = jest.spyOn(console, 'info'); 21 | consoleWarnMock = jest.spyOn(console, 'warn'); 22 | consoleDebugMock = jest.spyOn(console, 'debug'); 23 | consoleTraceMock = jest.spyOn(console, 'trace'); 24 | consoleErrorMock = jest.spyOn(console, 'error'); 25 | }); 26 | 27 | afterEach(() => { 28 | consoleInfoMock.mockRestore(); 29 | consoleWarnMock.mockRestore(); 30 | consoleDebugMock.mockRestore(); 31 | consoleTraceMock.mockRestore(); 32 | consoleErrorMock.mockRestore(); 33 | }); 34 | 35 | it('should exist', () => { 36 | expect(typeof weblog).toEqual('function'); 37 | }); 38 | 39 | it('should provide access to factories', () => { 40 | expect(typeof weblog.factories.MethodFactory).toEqual('function'); 41 | expect(typeof weblog.factories.PrefixFactory).toEqual('function'); 42 | }); 43 | 44 | it('should return a logger', () => { 45 | const log = weblog({ name: 'wds' }); 46 | 47 | expect(log.name).toEqual('wds'); 48 | }); 49 | 50 | it('should return multiple unique loggers', () => { 51 | const log = weblog({ name: 'wds' }); 52 | const log2 = weblog({ name: 'wds' }); 53 | 54 | expect(log).not.toEqual(log2); 55 | expect(log.id).not.toEqual(log2.id); 56 | 57 | expect(log.name).toEqual('wds'); 58 | expect(log2.name).toEqual('wds'); 59 | 60 | expect(/^wds/.test(log.id)).toBeTruthy(); 61 | expect(/^wds/.test(log2.id)).toBeTruthy(); 62 | }); 63 | 64 | it('should return cached loggers', () => { 65 | const log = weblog({ name: 'wds', unique: false }); 66 | const log2 = weblog({ name: 'wds', unique: false }); 67 | 68 | expect(log).toEqual(log2); 69 | 70 | expect(log.id).toEqual('wds'); 71 | expect(log2.id).toEqual('wds'); 72 | expect(log.id).toEqual(log2.id); 73 | 74 | expect(log.name).toEqual('wds'); 75 | expect(log2.name).toEqual('wds'); 76 | expect(log.name).toEqual(log2.name); 77 | }); 78 | 79 | it('should log for unique loggers', () => { 80 | const log = weblog({ name: 'wds' }); 81 | const log2 = weblog({ name: 'wdm' }); 82 | 83 | log.info('webpack-dev-server'); 84 | log2.info('webpack-dev-middleware'); 85 | 86 | const [first, last] = consoleInfoMock.mock.calls; 87 | 88 | expect(strip(first[0])).toMatchSnapshot(); 89 | expect(strip(last[0])).toMatchSnapshot(); 90 | }); 91 | 92 | it('should delete a logger (for tests environments only)', () => { 93 | const log = weblog({ name: 'wds' }); 94 | 95 | weblog.delLogger('wds'); 96 | 97 | const log2 = weblog({ name: 'wds' }); 98 | 99 | expect(log).not.toEqual(log2); 100 | }); 101 | 102 | it('cached loggers should share log levels', () => { 103 | const log = weblog({ name: 'wds', id: 'foo' }); 104 | 105 | log.level = 'silent'; 106 | 107 | const log2 = weblog({ name: 'wds', id: 'foo' }); 108 | 109 | expect(log).toEqual(log2); 110 | expect(log.level).toEqual(log2.level); 111 | }); 112 | 113 | it('should return no color string', () => { 114 | const log = weblog({ name: 'wds', color: false }); 115 | 116 | log.info('webpack-dev-server'); 117 | 118 | const [first] = consoleInfoMock.mock.calls; 119 | 120 | expect(first[0]).toMatchSnapshot(); 121 | }); 122 | 123 | it('should return logs with prefix', () => { 124 | const log = weblog({ name: 'wds', id: 'foo' }); 125 | 126 | { 127 | log.level = 'trace'; 128 | log.trace('webpack-dev-server'); 129 | 130 | const [first] = consoleTraceMock.mock.calls; 131 | 132 | expect(strip(first[0])).toMatchSnapshot(); 133 | } 134 | 135 | { 136 | log.level = 'info'; 137 | log.info('webpack-dev-server'); 138 | 139 | const [first] = consoleInfoMock.mock.calls; 140 | 141 | expect(strip(first[0])).toMatchSnapshot(); 142 | } 143 | 144 | { 145 | log.level = 'warn'; 146 | log.warn('webpack-dev-server'); 147 | 148 | const [first] = consoleWarnMock.mock.calls; 149 | 150 | expect(strip(first[0])).toMatchSnapshot(); 151 | } 152 | 153 | { 154 | log.level = 'error'; 155 | log.error('webpack-dev-server'); 156 | 157 | const [first] = consoleErrorMock.mock.calls; 158 | 159 | expect(strip(first[0].split('\n')[0])).toMatchSnapshot(); 160 | } 161 | }); 162 | 163 | it('should attach timestamp', () => { 164 | const log = weblog({ name: 'wds', timestamp: true }); 165 | 166 | log.info('webpack-dev-server'); 167 | 168 | const [first] = consoleInfoMock.mock.calls; 169 | 170 | expect(!!first[0].match(/[\d\d:\d\d:\d\d]/)).toBeTruthy(); 171 | }); 172 | }); 173 | --------------------------------------------------------------------------------