preboot / angular-webpack

A complete, yet simple, starter for Angular v2+ using webpack
MIT License
1.29k stars 557 forks source link

import log4javascript as 3rd party library #231

Closed azulay7 closed 7 years ago

azulay7 commented 7 years ago

Hi, I really like your project, clean and neat. I'm trying to build a log service of my own that usses 'log4javascript'; I added this library to vendor.ts and to my service. but when I run it, I get an error: log4javascript is not defined.

Here is my code:

import { Injectable } from '@angular/core'; import {Logger} from 'log4javascript';

@Injectable() export class MyLoggerService { log:any;

constructor() {

this.log=Logger;
let ajaxAppenderInfo = new log4javascript.AjaxAppender('http://localhost:8989/api/log/info');
ajaxAppenderInfo.setThreshold(log4javascript.Level.INFO);
this.log.addAppender(ajaxAppenderInfo);
this.log.info('Init Info logger');

}

info(message){ this.log.info(message); } }

Thank you in advance :) Amit

Foxandxss commented 7 years ago

You need https://www.npmjs.com/package/@types/log4javascript

azulay7 commented 7 years ago

I've done it ofcourse. the error is at run time. when I get to the service Constructor it didn't yet upload 'log4javascript' library.

azulay7 commented 7 years ago

Ok.. this iw weird I succeed by changing the row from import {Logger} from 'log4javascript'; to import * as log from 'log4javascript';

this is suck .

thank you for the answer.

Foxandxss commented 7 years ago

The problem is that log4javascript is not ready for ES6 imports (which is what TS uses). That library is like a year and a half old, so the author would need to update it to "modern tools".