Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: justinkames/vuejs-logger
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: MarcSchaetz/vuejs3-logger
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 8 commits
  • 11 files changed
  • 1 contributor

Commits on Oct 27, 2020

  1. Add changes for vue.js 3

    MarcSchaetz committed Oct 27, 2020
    Copy the full SHA
    9238d7b View commit details
  2. Fix Import

    MarcSchaetz committed Oct 27, 2020
    Copy the full SHA
    cedcc0b View commit details
  3. Provide key for inject()

    MarcSchaetz committed Oct 27, 2020
    Copy the full SHA
    67bcf27 View commit details
  4. Copy the full SHA
    319f7a7 View commit details
  5. Copy the full SHA
    c55c8a5 View commit details
  6. 1.0.0

    MarcSchaetz committed Oct 27, 2020
    Copy the full SHA
    2b33fe4 View commit details
  7. Remove Demo from ToC

    MarcSchaetz committed Oct 27, 2020
    Copy the full SHA
    46ae515 View commit details
  8. Merge branch 'develop'

    MarcSchaetz committed Oct 27, 2020
    Copy the full SHA
    8a62ecb View commit details
Showing with 90 additions and 70 deletions.
  1. +25 −0 .eslintrc.json
  2. +19 −22 README.md
  3. +12 −10 package.json
  4. +1 −1 src/index.ts
  5. +5 −5 src/lib/types/index.d.ts
  6. +2 −1 src/{vue-logger.ts → vue3-logger.ts}
  7. +1 −1 tests/config.test.ts
  8. +11 −6 tests/install.test.ts
  9. +13 −6 tests/output.test.ts
  10. +1 −0 tsconfig.json
  11. +0 −18 tslint.json
25 changes: 25 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"extends": "plugin:vue/essential",
"parserOptions": {
"ecmaVersion": 12,
"parser": "@typescript-eslint/parser",
"sourceType": "module"
},
"plugins": [
"vue",
"@typescript-eslint"
],
"rules": {
"prefer-arrow-callback": [
"warn",
{
"allowNamedFunctions": true
}
],
"quotes": [
"warn",
"single",
{ "allowTemplateLiterals": true }
]
}
}
41 changes: 19 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
# vuejs-logger
# vuejs3-logger

> ![](https://travis-ci.org/justinkames/vuejs-logger.svg?branch=master)
[![codecov](https://codecov.io/gh/justinkames/vuejs-logger/branch/master/graph/badge.svg)](https://codecov.io/gh/justinkames/vuejs-logger)
[![npm](https://img.shields.io/npm/dt/vuejs-logger.svg)](https://www.npmjs.com/package/vuejs-logger)
[![npm](https://img.shields.io/npm/dw/vuejs-logger.svg)](https://www.npmjs.com/package/vuejs-logger)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/justinkames/vuejs-logger/master/LICENSE)
> [![npm](https://img.shields.io/npm/dt/vuejs3-logger.svg)](https://www.npmjs.com/package/vuejs3-logger)
[![npm](https://img.shields.io/npm/dw/vuejs3-logger.svg)](https://www.npmjs.com/package/vuejs3-logger)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/MarcSchaetz/vuejs3-logger/master/LICENSE)

> Provides customizable logging functionality for Vue.js. Compatible with Vue2.
> Provides customizable logging functionality for Vue.js. Compatible with Vue3.
## Table of Contents

- [Demo](#demo)
- [Introduction](#introduction)
- [Install](#install)
- [Usage](#usage)
@@ -21,13 +18,11 @@
- [Contribute](#contribute)
- [License](#license)

## Demo

@ [https://codepen.io/justinkames/pen/BwGOVQ](https://codepen.io/justinkames/pen/BwGOVQ)

## Introduction

vuejs-logger is a tool that enables configurable logging for Vue applications. Features include :
vuejs3-logger is a fork of the great [vuejs-logger](https://github.com/justinkames/vuejs-logger) which is availabe for Vue.js 2. However vuejs-logger currently lacks support for Vue.js 3. The features of this library are exactly the same as the current vuejs-logger version 1.5.4.

Features include :

- Output restriction based on selected loglevel.
- Automatically JSON.stringify() the (reactive) properties passed to the logger.
@@ -43,10 +38,10 @@ logLevels : ['debug', 'info', 'warn', 'error', 'fatal']

This project uses [node](http://nodejs.org) and [npm](https://npmjs.com).

https://www.npmjs.com/package/vuejs-logger
https://www.npmjs.com/package/vuejs3-logger

```sh
$ npm install vuejs-logger --save-exact
$ npm install vuejs3-logger --save-exact
```

## Usage
@@ -68,7 +63,9 @@ Below you can find an example of how to use vuejs-logger :
#### Code example

```js
import VueLogger from 'vuejs-logger';
import VueLogger from 'vuejs3-logger';
import { createApp } from 'vue';

const isProduction = process.env.NODE_ENV === 'production';

const options = {
@@ -81,11 +78,11 @@ const options = {
showConsoleColors: true
};

Vue.use(VueLogger, options);
createApp({}).use(VueLogger, options);
```

```js
new Vue({
defineComponent({
data() {
return {
a : 'a',
@@ -104,7 +101,8 @@ new Vue({

function externalFunction() {
// log from external function
Vue.$log.debug('log from function outside component.');
const logger = inject('vuejs3-logger');
logger.debug('log from function outside component.');
}
```

@@ -131,14 +129,13 @@ ignore all calls with less important loglevels in the code.

## Maintainers

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

## Contribute

Feel free to dive in! [Open an issue](https://github.com/justinkames/vuejs-logger/issues/new) or submit PRs.

vuejs-logger follows the [Contributor Covenant](http://contributor-covenant.org/version/1/3/0/) Code of Conduct.

## License

[MIT](LICENSE) © Justin Kames
[MIT](LICENSE) © Marc Schätz
22 changes: 12 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"name": "vuejs-logger",
"name": "vuejs3-logger",
"license": "MIT",
"author": "Justin Kames",
"description": "vuejs-logger, provides customizable logging functionality for Vue.js.",
"version": "1.5.4",
"author": "Marc Schätz",
"description": "vuejs3-logger, provides customizable logging functionality for Vue.js3. Forked from the great vuejs-logger library (https://github.com/justinkames/vuejs-logger)",
"version": "1.0.0",
"repository": {
"type": "git",
"url": "https://github.com/justinkames/vuejs-logger.git"
"url": "https://github.com/MarcSchaetz/vuejs3-logger.git"
},
"main": "dist/index.js",
"scripts": {
"build": "tsc && npm test && mkdir -p ./dist/lib/types && cp src/lib/types/index.d.ts ./dist/lib/types/index.d.ts",
"build:save": "tsc && npm test && mkdir -p ./dist/lib/types && cp src/lib/types/index.d.ts ./dist/lib/types/index.d.ts",
"build": "tsc && mkdir -p ./dist/lib/types && cp src/lib/types/index.d.ts ./dist/lib/types/index.d.ts",
"tsc": "tsc --watch",
"test": "tsc && jest",
"upload-coverage": "codecov -t $CODECOV_TOKEN",
@@ -19,14 +20,15 @@
"devDependencies": {
"@types/jest": "25.1.1",
"@types/node": "13.5.3",
"chai": "4.2.0",
"codecov": "3.6.2",
"eslint": "^7.12.1",
"jest": "25.1.0",
"ts-jest": "25.1.0",
"typescript": "3.7.5",
"chai": "4.2.0",
"codecov": "3.6.2"
"typescript": "3.7.5"
},
"dependencies": {
"vue": "2.6.11",
"vue": "^3.0.0",
"es6-object-assign": "1.1.0"
},
"typings": "dist/lib/types/index.d.ts"
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ObjectAssign from "es6-object-assign";
ObjectAssign.polyfill();
import VueLogger from "./vue-logger";
import VueLogger from "./vue3-logger";
export default VueLogger;
10 changes: 5 additions & 5 deletions src/lib/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/**
* Augment the typings of Vue.js
*/
import Vue = require('vue');

import * as VueLogger from '../../index';
import vue from '@vue/runtime-core';
import VueLogger from '../../index';

export interface Log {
debug(...args: any[]): void;
@@ -17,8 +16,9 @@ export interface Log {
fatal(...args: any[]): void;
}

declare module 'vue/types/vue' {
interface Vue {

declare module '@vue/runtime-core' {
export interface ComponentCustomProperties {
$log: Log;
}
}
3 changes: 2 additions & 1 deletion src/vue-logger.ts → src/vue3-logger.ts
Original file line number Diff line number Diff line change
@@ -12,7 +12,8 @@ class VueLogger implements ILogger {

if (this.isValidOptions(options, this.logLevels)) {
Vue.$log = this.initLoggerInstance(options, this.logLevels);
Vue.prototype.$log = Vue.$log;
Vue.provide('vuejs3-logger', Vue.$log);
Vue.config.globalProperties.$log = Vue.$log;
} else {
throw new Error(this.errorMessage);
}
2 changes: 1 addition & 1 deletion tests/config.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {strict, strictEqual} from "assert";
import {strictEqual} from "assert";
import VueLogger from "../src/index";
import {LogLevels} from "../src/enum/log-levels";

17 changes: 11 additions & 6 deletions tests/install.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import {notStrictEqual, strictEqual} from "assert";
import { strictEqual } from "assert";
import chai from "chai";
import Vue from "vue/dist/vue.min";
import { createApp } from "vue";
import VueLogger from "../src/index";
import {LogLevels} from "../src/enum/log-levels";
import {ILoggerOptions} from "../src/interfaces/logger-options";
import { LogLevels } from "../src/enum/log-levels";
import { ILoggerOptions } from "../src/interfaces/logger-options";
const expect = chai.expect;

describe("vue-logger.ts", () => {

let app;

beforeAll(() => {
app = createApp({});
})
test("install() should work as expected with the correct params.", () => {
const options: ILoggerOptions = {
isEnabled: true,
@@ -18,7 +23,7 @@ describe("vue-logger.ts", () => {
showLogLevel: false,
showMethodName: false,
};
Vue.use(VueLogger, options);
const Vue = app.use(VueLogger, options).config.globalProperties;
expect(Vue.$log).to.be.a("object");
strictEqual(Vue.$log.debug("debug"), undefined);
strictEqual(Vue.$log.info("info"), undefined);
@@ -38,7 +43,7 @@ describe("vue-logger.ts", () => {
showMethodName: "wrong value for test.",
};
expect(() => {
VueLogger.install(Vue, options);
VueLogger.install(app, options);
})
.to
.throw(Error, "Provided options for vuejs-logger are not valid.");
19 changes: 13 additions & 6 deletions tests/output.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import chai from "chai";
import Vue from "vue/dist/vue.min";
import { createApp, defineComponent } from "vue";
import { LogLevels } from "../src/enum/log-levels";
import VueLogger from "../src/index";
import {LogLevels} from "../src/enum/log-levels";
import {ILoggerOptions} from "../src/interfaces/logger-options";
import { ILoggerOptions } from "../src/interfaces/logger-options";

const expect = chai.expect;

describe("output", () => {

// TODO(MarcSchaetz): Test failes because mount failes. Must be evaluated, how to correctly mount.
test("Should instantiate log functions and be reachable from external functions.", (done) => {
const options = {
isEnabled: true,
@@ -18,9 +20,10 @@ describe("output", () => {
showConsoleColors: false,
} as ILoggerOptions;

Vue.use(VueLogger, options);
const App = new Vue({
created() {

const root = defineComponent({
template: '<div id="app"></div>',
mounted() {
this.foo();
done();
},
@@ -36,6 +39,10 @@ describe("output", () => {
},
});

const app = createApp(root);
const Vue = app.use(VueLogger, options).config.globalProperties;
app.mount('#app');

function externalFunction(): void {
expect(Vue.$log.fatal("test")).to.exist;
expect(Vue.$log.fatal("test")).to.contains("externalFunction");
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
"target": "es5",
"lib": [
"es2015",
"ES2020.Symbol.WellKnown",
"es2017",
"dom"
],
18 changes: 0 additions & 18 deletions tslint.json

This file was deleted.