Skip to content

Commit

Permalink
remove kaltura-ng/kaltura-logger dependency from kaltura-ng/kaltura-c…
Browse files Browse the repository at this point in the history
…ommon
  • Loading branch information
eransakal committed May 31, 2018
1 parent ab50ce4 commit 0ce837d
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 180 deletions.
7 changes: 1 addition & 6 deletions kaltura-common/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion kaltura-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
"@angular/core": "^5.2.0",
"@angular/http": "^5.2.0",
"@angular/router": "^5.2.0",
"@kaltura-ng/kaltura-logger": "^2.2.0",
"rxjs": "^5.5.6"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions kaltura-common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from './upload-management';
export * from './xml-parser';
export * from './operation-tag';
export * from './server-polls'
export { KalturaLoggerInjectionToken } from './kaltura-logger';
4 changes: 3 additions & 1 deletion kaltura-common/src/kaltura-common.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { NgModule, ModuleWithProviders } from '@angular/core';
import { CommonModule } from '@angular/common';
import { KalturaUtils } from './utils/kaltura-utils';
import { APP_STORAGE_TOKEN, AppStorage } from './app-storage.service';
import { EmptyLogger, KalturaLoggerInjectionToken } from './kaltura-logger';


@NgModule({
Expand All @@ -28,7 +29,8 @@ export class KalturaCommonModule {
ngModule: KalturaCommonModule,
providers: [
{ provide: APP_STORAGE_TOKEN, useClass: AppStorage },
KalturaUtils
KalturaUtils,
{ provide: KalturaLoggerInjectionToken, useClass: EmptyLogger}
]
};
}
Expand Down
89 changes: 89 additions & 0 deletions kaltura-common/src/kaltura-logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { InjectionToken } from '@angular/core';

export type Context = { [key: string]: any };
export type DefferedContext = () => Context;

export const KalturaLoggerInjectionToken = new InjectionToken<KalturaLogger>('kaltura-logger');

export interface KalturaLogger {
trace(message: string, context?: Context): void;

trace(message: string, context?: DefferedContext): void;

trace(message: string, context?: Context | DefferedContext): void;

debug(message: string, context?: Context): void;

debug(message: string, context?: DefferedContext): void;

debug(message: string, context?: Context | DefferedContext): void;

info(message: string, context?: Context): void;

info(message: string, context?: DefferedContext): void;

info(message: string, context?: Context | DefferedContext): void;

warn(message: string, context?: Context): void;

warn(message: string, context?: DefferedContext): void;

warn(message: string, context?: Context | DefferedContext): void;

error(message: string, context?: Context): void;

error(message: string, error?: Error): void;

error(message: string, context?: Error | Context): void;

fatal(message: string, context?: Context): void;

fatal(message: string, error?: Error): void;

fatal(message: string, context?: Error | Context): void;

subLogger(name: string): KalturaLogger;
}

export class EmptyLogger implements KalturaLogger {
trace(message: string, context?: Context): void;
trace(message: string, context?: DefferedContext): void;
trace(message: string, context?: Context | DefferedContext): void;
trace(message: string, context?): void {
}

debug(message: string, context?: Context): void;
debug(message: string, context?: DefferedContext): void;
debug(message: string, context?: Context | DefferedContext): void;
debug(message: string, context?): void {
}

info(message: string, context?: Context): void;
info(message: string, context?: DefferedContext): void;
info(message: string, context?: Context | DefferedContext): void;
info(message: string, context?): void {
}

warn(message: string, context?: Context): void;
warn(message: string, context?: DefferedContext): void;
warn(message: string, context?: Context | DefferedContext): void;
warn(message: string, context?): void {
}

error(message: string, context?: Context): void;
error(message: string, error?: Error): void;
error(message: string, context?: Error | Context): void;
error(message: string, context?): void {
}

fatal(message: string, context?: Context): void;
fatal(message: string, error?: Error): void;
fatal(message: string, context?: Error | Context): void;
fatal(message: string, context?): void {
}

subLogger(name: string): KalturaLogger {
return new EmptyLogger();
}
}

5 changes: 0 additions & 5 deletions kaltura-common/src/rxjs/add/operators.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import { Observable } from 'rxjs/Observable';
import { _cancelOnDestroy as cancelOnDestroy } from '../operator/cancel-on-destroy/cancel-on-destroy';
import { _monitor as monitor } from '../operator/monitor/monitor';
import { _tag as tag } from '../operator/tag/tag';

Observable.prototype.cancelOnDestroy = cancelOnDestroy;
Observable.prototype.monitor = monitor;
Observable.prototype.tag = tag;

declare module 'rxjs/Observable' {
interface Observable<T> {
monitor: typeof monitor;
}
interface Observable<T> {
cancelOnDestroy: typeof cancelOnDestroy;
}
Expand Down
75 changes: 0 additions & 75 deletions kaltura-common/src/rxjs/operator/monitor/monitor.ts

This file was deleted.

40 changes: 19 additions & 21 deletions kaltura-common/src/server-polls/server-polls.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Subscriber } from 'rxjs/Subscriber';
import { FriendlyHashId } from '../friendly-hash-id';
import { ISubscription } from 'rxjs/Subscription';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { KalturaLogger } from '@kaltura-ng/kaltura-logger';
import { EmptyLogger, KalturaLogger } from '../kaltura-logger';
import { Optional } from '@angular/core';

export type PollInterval = 10 | 30 | 60 | 300;
Expand Down Expand Up @@ -31,25 +31,23 @@ export abstract class ServerPolls<TRequest, TError> {
private _logger: KalturaLogger;
public state$ = this._state.asObservable();
private _queueInterval: number = null;

protected abstract _executeRequests(requests: TRequest[]): Observable<{ error: TError, result: any }[]>;

protected abstract _createGlobalError(error?: Error): TError;

protected abstract _getOnDestroy$(): Observable<void>;

protected abstract _canExecute(): boolean;

constructor(@Optional() kalturaLogger: KalturaLogger) {

if (kalturaLogger)
{
this._logger = kalturaLogger.subLogger('ServerPolls');
}else
{
this._logger = new KalturaLogger('ServerPolls',null, null);
}
this._initialize();

constructor(kalturaLogger: KalturaLogger) {

if (kalturaLogger) {
this._logger = kalturaLogger;
} else {
this._logger = new EmptyLogger();
}
this._initialize();
}

private _warnAboutMissingDestory(): void {
Expand Down Expand Up @@ -78,11 +76,11 @@ export abstract class ServerPolls<TRequest, TError> {
}
});
}

private _cancelQueueInterval(): void {
clearTimeout(this._queueTimeout);
}

private _getPollQueueList(): PollItem<TError>[] {
return Object.keys(this._pollQueue).map(key => this._pollQueue[key]);
}
Expand Down Expand Up @@ -273,7 +271,7 @@ export abstract class ServerPolls<TRequest, TError> {
public isBusy(): boolean {
return this._state.getValue().busy;
}

public register<TResponse>(intervalInSeconds: PollInterval, requestFactory: RequestFactory<TRequest, TResponse>): Observable<{ error: TError, result: TResponse }> {
return Observable.create(observer => {
const newPollId = this._tokenGenerator.generateUnique(Object.keys(this._pollQueue));
Expand Down Expand Up @@ -303,7 +301,7 @@ export abstract class ServerPolls<TRequest, TError> {
this._setupQueueTimer();
}
);

return () => {
this._logger.info(`stop polling for ${newPollId}`);
if (initialRequest) {
Expand All @@ -313,4 +311,4 @@ export abstract class ServerPolls<TRequest, TError> {
}
});
}
}
}
29 changes: 6 additions & 23 deletions kaltura-logger/src/kaltura-logger.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NgModule, ModuleWithProviders, Optional, SkipSelf } from '@angular/core';
import { CommonModule } from '@angular/common';
import { KalturaLogger, KalturaDefaultLogger } from './kaltura-logger.service';
import { KalturaLogger, KalturaLoggerName } from './kaltura-logger.service';
import { JL } from 'jsnlog';
import { KalturaLoggerRecordService } from './kaltura-logger-record.service';

Expand All @@ -25,31 +25,14 @@ if (window && window.onerror) {
]
})
export class KalturaLoggerModule {

// TODO check why this doesn't work with AOT
// static forRoot(name: string): ModuleWithProviders {
// return {
// ngModule: KalturaLoggerModule,
// providers: [
// {
// provide: KalturaLogger,
// useFactory(parentLogger)
// {
// const logger = new KalturaLogger(name, parentLogger);
//
// KalturaDefaultLogger.set(logger.subLogger('general'));
//
// return logger;
// },
// deps: [[new Optional(), new SkipSelf(), KalturaLogger]]
// }
// ]
// };
// }
static forRoot(): ModuleWithProviders {
static forRoot(name: string): ModuleWithProviders {
return {
ngModule: KalturaLoggerModule,
providers: [
KalturaLogger,
{
provide: KalturaLoggerName, useValue: name
},
KalturaLoggerRecordService
]
}
Expand Down
Loading

0 comments on commit 0ce837d

Please sign in to comment.