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
35 changes: 0 additions & 35 deletions helpers/mock-logger.component.ts

This file was deleted.

6 changes: 3 additions & 3 deletions projects/logger/src/lib/decorators/timer.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { LoggerLevel } from '../logger.config';
import { TimerInfo, TimerLevels } from '../logger.interfaces';
import { Fn, TimerInfo, TimerLevels } from '../logger.interfaces';
import { LoggerModule } from '../logger.module';

export function Timer(title: string, level: TimerLevels = LoggerLevel.DEBUG, isMillisecond: boolean = true): any {
return (_target: any, _key: string, descriptor: PropertyDescriptor): PropertyDescriptor => {
let result: any;
const method: any = descriptor.value;
descriptor.value = function(...args: any[]): any {
const method: Fn = descriptor.value;
descriptor.value = function(...args: any[]): PropertyDescriptor {
const info: TimerInfo | null = LoggerModule.logger.startTime(title, level);
result = method.apply(this, args);
LoggerModule.logger.endTime(info, level, isMillisecond);
Expand Down
2 changes: 2 additions & 0 deletions projects/logger/src/lib/logger.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { InjectionToken } from '@angular/core';

export type Pipeline<T = any> = (logger: LoggerService) => T;

export type Fn<T = any, U = any> = (...args: T[]) => U;

export interface GroupMethods extends Function {
group(label: string, pipeline?: Pipeline): LoggerService;

Expand Down
6 changes: 4 additions & 2 deletions projects/logger/src/lib/services/timer-factory.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { LoggerService } from '../../lib/logger.service';

@Injectable()
export class TimerFactory {
private readonly DIGITS_TO_FIX: number = 4;
private readonly SECOND: number = 1000;
constructor(private readonly console: ConsoleService) {}

public startTime(title: string, level: LoggerLevel): TimerInfo | null {
Expand All @@ -21,8 +23,8 @@ export class TimerFactory {
const canExecute: boolean = !(this.console.minLevel > level);

if (canExecute) {
const msTime: number = parseFloat((performance.now() - info.startTime).toFixed(4));
const time: string = isMillisecond ? `${msTime}ms` : `${Math.floor(msTime / 1000)}s`;
const msTime: number = parseFloat((performance.now() - info.startTime).toFixed(this.DIGITS_TO_FIX));
const time: string = isMillisecond ? `${msTime}ms` : `${Math.floor(msTime / this.SECOND)}s`;
const methodName: string = DEFAULT_METHODS[level];
const logMethod: (...args: string[]) => void = logger[methodName];
logMethod(`Timer: ${info.title}`, `took ${time} to execute`);
Expand Down