Skip to content

Commit ad95ac1

Browse files
committed
Added jest.config.js.
Updated tsconfig.json. Updated package.json.
1 parent 0a35084 commit ad95ac1

File tree

6 files changed

+89
-52
lines changed

6 files changed

+89
-52
lines changed

Diff for: LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2017 Justin Kames
3+
Copyright (c) 2018 Justin Kames
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Diff for: README.md

+49-24
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
- [Introduction](#introduction)
1515
- [Install](#install)
1616
- [Usage](#usage)
17+
- [Properties](#properties)
18+
- [Code example](#code)
19+
- [Production tips](#Production tips)
1720
- [Maintainers](#maintainers)
1821
- [Contribute](#contribute)
1922
- [License](#license)
@@ -24,26 +27,21 @@
2427

2528
## Introduction
2629

27-
vuejs-logger is a logging library that enables logging for Vue applications. It restricts log messages that are higher than the specified log level. Features include :
30+
vuejs-logger is a tool that enables configurable logging for Vue applications. Features include :
2831

32+
- Output restriction based on selected loglevel.
33+
- Automatically JSON.stringify() the (reactive) properties passed to the logger.
34+
- Configurable options to customize output for a log messages.
2935
- Colored console messages for $log.warning, $log.error and $log.fatal.
30-
- Possibility to automatically JSON.stringify() the (reactive) properties passed to the logger.
31-
- Possibility to display the log level in the console.
3236

3337
```js
3438
logLevels : ['debug', 'info', 'warn', 'error', 'fatal']
3539
```
3640

37-
Option to disable the logger (for using it on PRODUCTION)
38-
39-
```js
40-
isEnabled : false
41-
```
42-
4341

4442
## Install
4543

46-
This project uses [node](http://nodejs.org) and [npm](https://npmjs.com). Go check them out if you don't have them locally installed!
44+
This project uses [node](http://nodejs.org) and [npm](https://npmjs.com).
4745

4846
https://www.npmjs.com/package/vuejs-logger
4947

@@ -55,27 +53,35 @@ $ npm install vuejs-logger --save-exact
5553

5654
Below you can find an example of how to use vuejs-logger :
5755

58-
```js
59-
import VueLogger from 'vuejs-logger'
56+
#### Properties
6057

58+
| Name | Required | Type | Default | Description |
59+
| --- | --- | --- | --- | --- |
60+
| isEnabled | false | Boolean | true | Enables the vuejs-logger plugin, useful toggle for production/development. |
61+
| logLevel | false | String | 'debug' | Choose between ['debug', 'info', 'warn', 'error', 'fatal']. Read [production tips](#Production tips). |
62+
| stringifyArguments | false | Boolean | false | If true, all input will go through JSON.stringify(). Useful when printing reactive properties.|
63+
| showLogLevel | false | Boolean | false | If true, the loglevel will be shown. |
64+
| showMethodName | false | Boolean | false | If true, the method name of the parent function will be shown in the console. |
65+
| separator | false | String | ' l ' | The seperator between parts of the output ( see [screenshot](#Screenshot). |
66+
| showConsoleColors | false | Boolean | false | If true, enables console.warn, console.fatal, console.error for corresponding loglevels. |
67+
68+
#### Code example
69+
70+
```js
71+
import VueLogger from 'vuejs-logger';
72+
const isProduction = process.env.NODE_ENV !=== 'production';
73+
6174
const options = {
62-
// optional : defaults to true if not specified
6375
isEnabled: true,
64-
// required ['debug', 'info', 'warn', 'error', 'fatal']
65-
logLevel : 'debug',
66-
// optional : defaults to false if not specified
76+
logLevel : isProduction ? 'error' : 'debug',
6777
stringifyArguments : false,
68-
// optional : defaults to false if not specified
6978
showLogLevel : false,
70-
// optional : defaults to false if not specified
7179
showMethodName : false,
72-
// optional : defaults to '|' if not specified
7380
separator: '|',
74-
// optional : defaults to false if not specified
7581
showConsoleColors: false
76-
}
82+
};
7783

78-
Vue.use(VueLogger, options)
84+
Vue.use(VueLogger, options);
7985
```
8086

8187
```js
@@ -94,16 +100,35 @@ new Vue({
94100
this.$log.fatal('test')
95101
externalFunction()
96102
}
97-
})
103+
});
98104

99105
function externalFunction() {
100106
// log from external function
101-
Vue.$log.debug('log from function outside component.')
107+
Vue.$log.debug('log from function outside component.');
102108
}
103109
```
104110

111+
112+
#### Screenshot
113+
105114
![screen shot 2017-10-17 at 10 54 05](https://user-images.githubusercontent.com/3469323/31655570-910fcbbe-b329-11e7-9738-bece4be4d1a8.png)
106115

116+
## Production tips
117+
The plugin can be disabled for production or a lower logLevel can be set to minimize output (as shown in [usage](#usage) ). If the logLevel is set to 'fatal' the plugin will
118+
ignore all calls with less important loglevels in the code.
119+
120+
```js
121+
function foo() {
122+
// these statements will print nothing if the logLevel is set to 'fatal'. But they will compile just fine.
123+
this.$log.debug('test', 'bar')
124+
this.$log.info('test')
125+
this.$log.warn('test')
126+
this.$log.error('test', 'foo')
127+
// this statement will print if the logLevel is set to 'fatal'
128+
this.$log.fatal('test', 'bar', 123)
129+
}
130+
```
131+
107132
## Maintainers
108133

109134
[@justinkames](https://github.com/justinkames).

Diff for: jest.config.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?|ts?)$",
3+
transform: {
4+
"^.+\\.tsx?$": "ts-jest"
5+
},
6+
moduleFileExtensions: [
7+
"ts",
8+
"tsx",
9+
"js",
10+
"jsx"
11+
],
12+
testURL: "http://localhost/",
13+
collectCoverage: true,
14+
collectCoverageFrom: [
15+
"src/**/*.{ts,tsx,js,jsx}"
16+
]
17+
}

Diff for: package.json

+9-23
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,24 @@
11
{
2-
"name": "mean-poc",
3-
"version": "0.0.0",
4-
"private": true,
2+
"name": "vuejs-logger",
3+
"author": "Justin Kames",
4+
"description": "vuejs-logger, provides customizable logging functionality for Vue.js.",
5+
"version": "1.5.0",
56
"main": "index.js",
67
"scripts": {
78
"build": "tsc",
8-
"tsc": "tsc",
9-
"test": "tsc && jest"
9+
"tsc": "tsc --watch",
10+
"test": "tsc && jest",
11+
"upload-coverage": "codecov -t $CODECOV_TOKEN"
1012
},
1113
"devDependencies": {
1214
"@types/jest": "23.3.1",
1315
"@types/node": "10.5.3",
14-
"eslint": "5.2.0",
1516
"jest": "23.4.1",
1617
"ts-jest": "23.0.1",
1718
"tsc": "1.20150623.0",
1819
"typescript": "2.9.2",
1920
"chai": "4.1.2",
20-
"vue": "2.5.16"
21-
},
22-
"jest": {
23-
"verbose": true,
24-
"testURL": "http://localhost/",
25-
"transform": {
26-
"^.+\\.tsx?$": "ts-jest"
27-
},
28-
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
29-
"moduleFileExtensions": [
30-
"ts",
31-
"tsx",
32-
"js",
33-
"jsx",
34-
"json",
35-
"node"
36-
]
21+
"vue": "2.5.16",
22+
"es6-object-assign": "1.1.0"
3723
}
3824
}

Diff for: src/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
import VueLogger from "./vue-logger";
2-
1+
import ObjectAssign from "es6-object-assign";
2+
ObjectAssign.polyfill();
3+
import VueLogger from "./vue-logger/vue-logger";
34
export default VueLogger;

Diff for: tsconfig.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{
22
"compilerOptions": {
3-
"target": "es6",
3+
"target": "es5",
4+
"lib": [
5+
"es2015",
6+
"es2017",
7+
"dom"
8+
],
49
"module": "commonjs",
510
"outDir": "dist",
611
"sourceMap": true,
@@ -17,5 +22,8 @@
1722
],
1823
"exclude": [
1924
"node_modules"
20-
]
25+
],
26+
"rules": {
27+
"no-console": false
28+
}
2129
}

0 commit comments

Comments
 (0)