Skip to content

Commit fad08dd

Browse files
committed
Make $log available on Vue.$log.
1 parent 4b97ed9 commit fad08dd

File tree

3 files changed

+73
-60
lines changed

3 files changed

+73
-60
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vuejs-logger",
33
"author": "Justin Kames",
4-
"version": "1.0.4",
4+
"version": "1.10.0",
55
"description": "Vuejs-logger, provides customizable logging functionality for Vue.js.",
66
"main": "dist/index.js",
77
"repository": {
@@ -28,6 +28,7 @@
2828
"codecov": "2.2.0",
2929
"istanbul": "0.4.5",
3030
"mocha": "3.4.2",
31-
"uglify": "0.1.5"
31+
"uglify": "0.1.5",
32+
"vue": "2.4.1"
3233
}
3334
}

src/logger.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ export default function () {
4141

4242
function install (Vue, options) {
4343
if (validateOptions(options, logLevels)) {
44-
Vue.prototype.$log = initLoggerInstance(options, logLevels)
44+
Vue.$log = initLoggerInstance(options, logLevels)
45+
Vue.prototype.$log = Vue.$log
4546
} else {
4647
throw new Error('Provided options for vuejs-logger are not valid.')
4748
}

test/logger.js

Lines changed: 68 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,78 @@
11
import chai from 'chai'
22
const expect = chai.expect
3+
import Vue from 'vue'
34
import VueLogger from '../src/logger'
45
const {print, validateOptions, initLoggerInstance, logLevels, install} = VueLogger()
56

67
describe('Logger.js', () => {
78

9+
describe('install()', () => {
10+
11+
it('install() should work with the correct params.', () => {
12+
const options = {
13+
logLevel: 'debug',
14+
stringifyByDefault: false,
15+
showLogLevel: false,
16+
}
17+
18+
Vue.use({install}, options)
19+
20+
new Vue({
21+
created() {
22+
expect(this.$log).to.be.a('object')
23+
expect(this.$log.debug).to.be.a('function')
24+
expect(this.$log.info).to.be.a('function')
25+
expect(this.$log.warn).to.be.a('function')
26+
expect(this.$log.error).to.be.a('function')
27+
expect(this.$log.fatal).to.be.a('function')
28+
}
29+
})
30+
31+
expect(Vue.$log).to.be.a('object')
32+
expect(Vue.$log.debug).to.be.a('function')
33+
expect(Vue.$log.info).to.be.a('function')
34+
expect(Vue.$log.warn).to.be.a('function')
35+
expect(Vue.$log.error).to.be.a('function')
36+
expect(Vue.$log.fatal).to.be.a('function')
37+
})
38+
39+
it('install() should throw an error with the an incorrect log level.', () => {
40+
const options = {
41+
logLevel: 'foo'
42+
}
43+
expect(() => { install(() => {}, options) })
44+
.to
45+
.throw(Error, 'Provided options for vuejs-logger are not valid.')
46+
})
47+
48+
it('install() should throw an error with the an incorrect log level.', () => {
49+
const options = {
50+
logLevel: false
51+
}
52+
expect(() => { install(() => {}, options) })
53+
.to
54+
.throw(Error, 'Provided options for vuejs-logger are not valid.')
55+
})
56+
57+
it('install() should throw an error with the an incorrect log level.', () => {
58+
const options = {
59+
logLevel: undefined
60+
}
61+
expect(() => { install(() => {}, options) })
62+
.to
63+
.throw(Error, 'Provided options for vuejs-logger are not valid.')
64+
})
65+
66+
it('install() should throw an error with the an incorrect log level.', () => {
67+
const options = {
68+
logLevel: null
69+
}
70+
expect(() => { install(() => {}, options) })
71+
.to
72+
.throw(Error, 'Provided options for vuejs-logger are not valid.')
73+
})
74+
})
75+
876
describe('initLoggerInstance()', () => {
977

1078
it('initLoggerInstance() should ignore logLevels that are more restrictive than set logLevel.', () => {
@@ -71,61 +139,4 @@ describe('Logger.js', () => {
71139
print('debug', 'debug |', ['test'])
72140
})
73141
})
74-
75-
describe('install()', () => {
76-
77-
it('install() should work with the correct params.', () => {
78-
const Vue = () => {}
79-
const options = {
80-
logLevel: 'debug',
81-
stringifyByDefault: false,
82-
showLogLevel: false,
83-
}
84-
install(Vue, options)
85-
Vue()
86-
87-
expect(Vue.prototype.$log).to.be.a('object')
88-
expect(Vue.prototype.$log.debug).to.be.a('function')
89-
expect(Vue.prototype.$log.info).to.be.a('function')
90-
expect(Vue.prototype.$log.warn).to.be.a('function')
91-
expect(Vue.prototype.$log.error).to.be.a('function')
92-
expect(Vue.prototype.$log.fatal).to.be.a('function')
93-
})
94-
95-
it('install() should throw an error with the an incorrect log level.', () => {
96-
const options = {
97-
logLevel: 'foo'
98-
}
99-
expect(() => { install(() => {}, options) })
100-
.to
101-
.throw(Error, 'Provided options for vuejs-logger are not valid.')
102-
})
103-
104-
it('install() should throw an error with the an incorrect log level.', () => {
105-
const options = {
106-
logLevel: false
107-
}
108-
expect(() => { install(() => {}, options) })
109-
.to
110-
.throw(Error, 'Provided options for vuejs-logger are not valid.')
111-
})
112-
113-
it('install() should throw an error with the an incorrect log level.', () => {
114-
const options = {
115-
logLevel: undefined
116-
}
117-
expect(() => { install(() => {}, options) })
118-
.to
119-
.throw(Error, 'Provided options for vuejs-logger are not valid.')
120-
})
121-
122-
it('install() should throw an error with the an incorrect log level.', () => {
123-
const options = {
124-
logLevel: null
125-
}
126-
expect(() => { install(() => {}, options) })
127-
.to
128-
.throw(Error, 'Provided options for vuejs-logger are not valid.')
129-
})
130-
})
131142
})

0 commit comments

Comments
 (0)