Skip to content
This repository was archived by the owner on Jun 18, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions helpers/console-fake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export enum TestLoggerGroupType {
}

export class ConsoleFake implements Console {
// tslint:disable-next-line:no-any
public Console: any;
private _stack: ObjectKeyMap[] = [];

Expand All @@ -40,7 +41,7 @@ export class ConsoleFake implements Console {
}
}

public table(data: any): void {
public table(data: unknown): void {
this._stack.push({ [TestLoggerLineType.TABLE]: [data] });
}

Expand Down Expand Up @@ -100,7 +101,7 @@ export class ConsoleFake implements Console {
const stackList: string[] = this.stackList(this.stack(0));
const stackOptionsList: ObjectKeyMap = [];

stackList.forEach((line: any) => {
stackList.forEach((line: string) => {
stackOptionsList.push({
label: String(line[0]).replace('%c', ''),
styles: this.parseCssString(line[usageNext ? 2 : 1])
Expand Down
8 changes: 4 additions & 4 deletions helpers/test.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Log } from '../projects/logger/src/lib/decorators/log.decorator';
import { Group } from '../projects/logger/src/lib/decorators/groups/group.decorator';
import { GroupCollapsed } from '../projects/logger/src/lib/decorators/groups/group-collapsed.decorator';
import { LoggerLevel } from '../projects/logger/src/lib/logger.config';
import { LogFn, TimerInfo } from '../projects/logger/src/lib/logger.interfaces';
import { Fn, LogFn, TimerInfo } from '../projects/logger/src/lib/logger.interfaces';
import { TimerLog } from '../projects/logger/src/lib/decorators/timer.decorator';

// noinspection AngularMissingOrInvalidDeclarationInModule
Expand Down Expand Up @@ -76,11 +76,11 @@ export class MyTestComponent implements OnInit {
}

@TimerLog('longQueryBySecond', LoggerLevel.INFO, false)
public longQueryBySecond(seconds: number, done: any): void {
public longQueryBySecond(seconds: number, done: Fn): void {
this.extracted(seconds, done);
}

public longQueryBySecondMs(seconds: number, done: any): void {
public longQueryBySecondMs(seconds: number, done: Fn): void {
const info: TimerInfo = this.logger.startTime('longQueryBySecondMs');
this.extracted(seconds, done);
this.logger.endTime(info);
Expand All @@ -91,7 +91,7 @@ export class MyTestComponent implements OnInit {
throw new Error('error');
}

private extracted(seconds: number, done: any): void {
private extracted(seconds: number, done: Fn): void {
const e: number = new Date().getTime() + seconds * 1000;
while (new Date().getTime() <= e) {
this.doneHeavy = true;
Expand Down
5 changes: 3 additions & 2 deletions projects/logger/src/lib/decorators/debug.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Type } from '@angular/core';

import { LogFn } from './../logger.interfaces';
import { LoggerModule } from './../logger.module';
import { Type } from '@angular/core';

export function DebugLog(): PropertyDecorator {
return (target: Type<unknown>, propertyName: string): void => {
Object.defineProperty(target, propertyName, {
configurable: false,
get(): LogFn {
return LoggerModule.logger.debug;
return LoggerModule.logger().debug;
}
});
};
Expand Down
2 changes: 1 addition & 1 deletion projects/logger/src/lib/decorators/error.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function ErrorLog(): PropertyDecorator {
Object.defineProperty(target, propertyName, {
configurable: false,
get(): LogFn {
return LoggerModule.logger.error;
return LoggerModule.logger().error;
}
});
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Type } from '@angular/core';

import { GroupLevel, LoggerLevel } from '../../logger.config';
import { groupDecoratorFactory } from './group.common';
import { Any, Callback, DecoratorMethod } from '../../logger.interfaces';
import { Type } from '@angular/core';

export function GroupCollapsed(
title: string | Callback<string>,
Expand Down
8 changes: 4 additions & 4 deletions projects/logger/src/lib/decorators/groups/group.common.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Type } from '@angular/core';

import { LoggerModule } from '../../logger.module';
import { LoggerService } from '../../logger.service';
import { LoggerLevel, GroupLevel } from '../../logger.config';
import { Any, Callback, Fn, GroupMethod } from '../../logger.interfaces';

import { GroupFactory } from '../../services/group-factory.service';
import { Type } from '@angular/core';

export function groupDecoratorFactory(
level: LoggerLevel,
Expand All @@ -15,8 +15,8 @@ export function groupDecoratorFactory(
target: Type<unknown>
): unknown {
let result: unknown;
const logger: LoggerService = LoggerModule.logger;
const groupFactory: GroupFactory = LoggerModule.groupFactory;
const logger: LoggerService = LoggerModule.logger();
const groupFactory: GroupFactory = LoggerModule.groupFactory();
const groupMethod: GroupMethod = groupFactory[groupType].bind(groupFactory);
const label: string = typeof title === 'string' ? title : title(...args);

Expand Down
3 changes: 2 additions & 1 deletion projects/logger/src/lib/decorators/groups/group.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Type } from '@angular/core';

import { GroupLevel, LoggerLevel } from '../../logger.config';
import { groupDecoratorFactory } from './group.common';
import { Any, Callback, DecoratorMethod } from '../../logger.interfaces';
import { Type } from '@angular/core';

export function Group(title: string | Callback<string>, level: LoggerLevel = LoggerLevel.INFO): DecoratorMethod {
return (_target: Type<unknown>, _key: string, descriptor: PropertyDescriptor): PropertyDescriptor => {
Expand Down
5 changes: 3 additions & 2 deletions projects/logger/src/lib/decorators/info.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Type } from '@angular/core';

import { LogFn } from './../logger.interfaces';
import { LoggerModule } from './../logger.module';
import { Type } from '@angular/core';

export function InfoLog(): PropertyDecorator {
return (target: Type<unknown>, propertyName: string): void => {
Object.defineProperty(target, propertyName, {
configurable: false,
get(): LogFn {
return LoggerModule.logger.info;
return LoggerModule.logger().info;
}
});
};
Expand Down
5 changes: 3 additions & 2 deletions projects/logger/src/lib/decorators/log.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Type } from '@angular/core';

import { LogFn } from './../logger.interfaces';
import { LoggerModule } from './../logger.module';
import { Type } from '@angular/core';

export function Log(): PropertyDecorator {
return (target: Type<unknown>, propertyName: string): void => {
Object.defineProperty(target, propertyName, {
configurable: false,
get(): LogFn {
return LoggerModule.logger.log;
return LoggerModule.logger().log;
}
});
};
Expand Down
5 changes: 3 additions & 2 deletions projects/logger/src/lib/decorators/logger.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Type } from '@angular/core';

import { LoggerModule } from '../logger.module';
import { LoggerService } from '../logger.service';
import { Type } from '@angular/core';

export function Logger(): PropertyDecorator {
return (target: Type<unknown>, propertyName: string): void => {
Object.defineProperty(target, propertyName, {
configurable: false,
get(): LoggerService {
return LoggerModule.logger;
return LoggerModule.logger();
}
});
};
Expand Down
7 changes: 4 additions & 3 deletions projects/logger/src/lib/decorators/timer.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Type } from '@angular/core';

import { LoggerLevel } from '../logger.config';
import { Any, DecoratorMethod, Fn, TimerInfo, TimerLevels } from '../logger.interfaces';
import { LoggerModule } from '../logger.module';
import { Type } from '@angular/core';

export function TimerLog(
title: string,
Expand All @@ -12,9 +13,9 @@ export function TimerLog(
let result: PropertyDescriptor;
const method: Fn = descriptor.value;
descriptor.value = function(...args: Any[]): PropertyDescriptor {
const info: TimerInfo | null = LoggerModule.logger.startTime(title, level);
const info: TimerInfo | null = LoggerModule.logger().startTime(title, level);
result = method.apply(this, args);
LoggerModule.logger.endTime(info, level, isMillisecond);
LoggerModule.logger().endTime(info, level, isMillisecond);
return result;
};
return descriptor;
Expand Down
5 changes: 3 additions & 2 deletions projects/logger/src/lib/decorators/trace.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Type } from '@angular/core';

import { LogFn } from './../logger.interfaces';
import { LoggerModule } from './../logger.module';
import { Type } from '@angular/core';

export function TraceLog(): PropertyDecorator {
return (target: Type<unknown>, propertyName: string): void => {
Object.defineProperty(target, propertyName, {
configurable: false,
get(): LogFn {
return LoggerModule.logger.trace;
return LoggerModule.logger().trace;
}
});
};
Expand Down
5 changes: 3 additions & 2 deletions projects/logger/src/lib/decorators/warn.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Type } from '@angular/core';

import { LogFn } from './../logger.interfaces';
import { LoggerModule } from './../logger.module';
import { Type } from '@angular/core';

export function WarnLog(): PropertyDecorator {
return (target: Type<unknown>, propertyName: string): void => {
Object.defineProperty(target, propertyName, {
configurable: false,
get(): LogFn {
return LoggerModule.logger.warn;
return LoggerModule.logger().warn;
}
});
};
Expand Down
1 change: 1 addition & 0 deletions projects/logger/src/lib/logger.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface ObjectKeyMap<T = Any> {
[key: string]: T;
}

// tslint:disable-next-line:no-any
export type Any = any; // NOSONAR

export type DecoratorMethod = (target: Any, key: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
Expand Down
9 changes: 6 additions & 3 deletions projects/logger/src/lib/logger.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Injector, ModuleWithProviders, NgModule } from '@angular/core';

import { LoggerService } from './logger.service';
import { LoggerFactory } from './services/factory.service';
import { ConsoleService } from './services/console.service';
Expand Down Expand Up @@ -31,18 +32,20 @@ import { TimerFactory } from './services/timer-factory.service';
TimerFactory
]
})

// @dynamic
export class LoggerModule {
private static injector: Injector;
private static injector: Injector = undefined;

constructor(injector: Injector) {
LoggerModule.injector = injector;
}

public static get logger(): LoggerService {
public static logger(): LoggerService {
return LoggerModule.injector.get(LoggerService);
}

public static get groupFactory(): GroupFactory {
public static groupFactory(): GroupFactory {
return LoggerModule.injector.get(GroupFactory);
}

Expand Down
4 changes: 2 additions & 2 deletions projects/logger/tests/clipboard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('[TEST]: Check clipboard', () => {
const fakeConsole: Console & ConsoleFake = new ConsoleFake();
const textarea: Partial<HTMLTextAreaElement> = {
textContent: null,
style: {} as any,
style: {} as CSSStyleDeclaration,
select: (): void => {}
};

Expand All @@ -28,7 +28,7 @@ describe('[TEST]: Check clipboard', () => {

beforeEach(() => {
buffer = null;
(window as any).clipboardData = null;
window.clipboardData = null;
document.queryCommandSupported = null;
textarea.textContent = null;
document.execCommand = null;
Expand Down
5 changes: 3 additions & 2 deletions projects/logger/tests/decorators.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { LoggerService } from '../src/lib/logger.service';
import { MyTestComponent } from '../../../helpers/test.component';
import { LoggerLevel } from '../src/lib/logger.config';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { Fn } from '@angular-ru/logger';

describe('[TEST]: Decorator API', () => {
let logger: LoggerService;
Expand Down Expand Up @@ -132,14 +133,14 @@ describe('[TEST]: Decorator API', () => {
expect(fakeConsole.stack()).toEqual(fakeConsole.createStack());
});

it('query by second timer', (done: any) => {
it('query by second timer', (done: Fn) => {
component.longQueryBySecond(3, done);
expect(fakeConsole.stack()).toEqual(
fakeConsole.createStack({ info: ['TimerLog: longQueryBySecond', 'took 3s to execute'] })
);
});

it('query by ms timer', (done: any) => {
it('query by ms timer', (done: Fn) => {
component.longQueryBySecondMs(3, done);
expect(fakeConsole.stack().includes('TimerLog: longQueryBySecondMs')).toEqual(true);
});
Expand Down
8 changes: 4 additions & 4 deletions projects/logger/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
"lib": ["dom", "es2018"]
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": false,
"annotateForClosureCompiler": true,
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true,
"skipTemplateCodegen": false,
"preserveWhitespaces": true,
"skipMetadataEmit": false
"enableResourceInlining": true
},
"exclude": ["**/*.spec.ts"]
}
4 changes: 2 additions & 2 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export class AppComponent implements OnInit {
this.logger.log(...this.logger.prettyJSON(jsonExample));
}

public showExample7(): any {
public showExample7(): void {
this.logger.clear();

const example: string = 'test string';
Expand All @@ -181,7 +181,7 @@ export class AppComponent implements OnInit {
this.logger.copy(example);
}

public showExample8(): any {
public showExample8(): void {
this.logger.clear();
this.logger.level = LoggerLevel.INFO;

Expand Down
1 change: 1 addition & 0 deletions src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// tslint:disable-next-line:no-any
export const environment: any = {
production: true,
useConfig: true
Expand Down
1 change: 1 addition & 0 deletions src/environments/environment.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// tslint:disable-next-line:no-any
export const environment: any = {
production: false,
useConfig: true
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ if (environment.production) {

platformBrowserDynamic()
.bootstrapModule(AppModule)
.catch((err: any) => console.error(err));
.catch((err: Error) => console.error(err));
1 change: 1 addition & 0 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
}
],
"no-arg": true,
"no-any": true,
"no-console": [true, "log", "debug", "info", "time", "timeEnd", "trace"],
"no-construct": true,
"no-debugger": true,
Expand Down