I've written a remote logger for angular2 which works fine. I'd now like to publish it as its own npm library and struggle with making it available. I've oriented myself at the setup of the ngx-translate module.
The general setup of the logger I am using internally is similar to the one described in Ben Nadel's Custom Error Handler Post:
import {
LOG4NG_SERVICE_HANDLER_PROVIDERS,
LOG4NG_SERVICE_CONFIG,
LOG4NG_ERROR_HANDLER_PROVIDERS,
LOG4NG_ERROR_HANDLER_CONFIG } from './log4ng.service';
import * as message from './log4ng.service/message';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule
],
providers: [
LOG4NG_SERVICE_HANDLER_PROVIDERS,
{
provide: LOG4NG_SERVICE_CONFIG,
useValue: {
recipients: [
{
classname: 'ConsoleWriter',
params: {
name: 'Angular2 Test App::Console Logger'
}
}
],
filters: [ /** filter definition **/ ]
}
},
LOG4NG_ERROR_HANDLER_PROVIDERS,
{
provide: LOG4NG_ERROR_HANDLER_CONFIG,
useValue: {
rethrowError: false,
unwrapError: false
}
}
],
bootstrap: [AppComponent]
})
export class AppModule { }
I've tried to adapt this approach to it's own module like so:
import { NgModule, ModuleWithProviders } from '@angular/core';
import { CommonModule } from '@angular/common';
import {
Log4ngService,
ILog4ngServiceConfig,
LOG4NG_SERVICE_CONFIG,
LOG4NG_SERVICE_HANDLER_PROVIDERS,
ErrorHandlerLoggingService,
LOG4NG_ERROR_HANDLER_CONFIG,
LOG4NG_ERROR_HANDLER_PROVIDERS
} from './src';
export * from './src';
@NgModule({
imports: [
CommonModule
],
providers: [
Log4ngService,
ErrorHandlerLoggingService
]
})
export class Log4ngModule {
static forRoot(config: ILog4ngServiceConfig = LOG4NG_SERVICE_CONFIG): ModuleWithProviders {
return {
ngModule: Log4ngModule,
providers: LOG4NG_SERVICE_HANDLER_PROVIDERS
};
}
static forChild(config: ILog4ngServiceConfig = LOG4NG_SERVICE_CONFIG): ModuleWithProviders {
return {
ngModule: Log4ngModule,
providers: LOG4NG_SERVICE_HANDLER_PROVIDERS
};
}
}
I proceeded to create a demo-app to use this module and used npm link
to locally use the libary. While it builds completely, when trying to use it in the demo app, I get the runtime error:
Error: Can't resolve all parameters for Log4ngService: (?)
which I do not understand, since for my understanding, all necessary DI tokens are correctly set.
You can find the code in the dev-branch of this git-repository: https://github.com/LarsKumbier/log4ng/tree/dev
Any help and hints appreciated - thanks in advance!