This commit is contained in:
crusader 2018-03-25 19:35:34 +09:00
parent 520470fd93
commit 8158c9bbc3
7 changed files with 0 additions and 191 deletions

View File

@ -1,6 +0,0 @@
import { LoggerLevel } from './type';
export class LoggerConfig {
level: LoggerLevel;
serverLogLevel: LoggerLevel;
}

View File

@ -1,3 +0,0 @@
export * from './config';
export * from './token';
export * from './type';

View File

@ -1,4 +0,0 @@
import { Inject, Injectable, InjectionToken } from '@angular/core';
import { LoggerLevel } from './type';
export const LOGGER_LEVEL = new InjectionToken<LoggerLevel>('LoggerLevel');

View File

@ -1,26 +0,0 @@
export enum LoggerLevel {
TRACE = 0,
DEBUG,
INFO,
LOG,
WARN,
ERROR,
OFF,
}
export const LoggerLevelName = [
'TRACE',
'DEBUG',
'INFO',
'LOG',
'WARN',
'ERROR',
'OFF'
];
export interface ServerLoggingParameter {
level: string;
message: string;
addtional?: string;
timestamp: Date;
}

View File

@ -1,39 +0,0 @@
import {
NgModule,
ModuleWithProviders,
} from '@angular/core';
import { CommonModule } from '@angular/common';
@NgModule({
})
export class LoggerRootModule { }
@NgModule({
})
export class LoggerFeatureModule { }
@NgModule({
})
export class LoggerModule {
static forRoot(reducers: any): ModuleWithProviders {
return {
ngModule: LoggerRootModule,
providers: [
],
};
}
static forFeature(featureName: string, reducers?: any): ModuleWithProviders {
return {
ngModule: LoggerFeatureModule,
providers: [
],
};
}
}

View File

@ -1,93 +0,0 @@
import {
LoggerConfig,
LoggerLevel,
} from '../core';
export abstract class LoggerService {
public constructor(
private readonly config: LoggerConfig
) {
}
public trace(message, ...additional: any[]): void {
this._log(LoggerLevel.TRACE, message, additional);
}
public debug(message, ...additional: any[]): void {
this._log(LoggerLevel.DEBUG, message, additional);
}
public info(message, ...additional: any[]): void {
this._log(LoggerLevel.INFO, message, additional);
}
public log(message, ...additional: any[]): void {
this._log(LoggerLevel.LOG, message, additional);
}
public warn(message, ...additional: any[]): void {
this._log(LoggerLevel.WARN, message, additional);
}
public error(message, ...additional: any[]): void {
this._log(LoggerLevel.ERROR, message, additional);
}
private _timestamp(): string {
return new Date().toISOString();
}
private _log(level: LoggerLevel, logOnServer: boolean, message, additional: any[] = []): void {
if (!message) {
return;
}
// Allow logging on server even if client log level is off
// if (logOnServer) {
// this._logOnServer(level, message, additional);
// }
// if no message or the log level is less than the environ
if (level < this.config.level) {
return;
}
try {
message = typeof message === 'string' ? message
: JSON.stringify(message, null, 2);
} catch (e) {
additional = [message, ...additional];
message = 'The provided "message" value could not be parsed with JSON.stringify().';
}
// Coloring doesn't work in IE
// if (this._isIE) {
// return this._logIE(level, message, additional);
// }
// const color = this._getColor(level);
// console.log(`%c${this._timestamp()} [${Levels[level]}]`, `color:${color}`, message, ...additional);
}
private _getColor(level: LoggerLevel): 'blue' | 'teal' | 'gray' | 'red' | undefined {
switch (level) {
case LoggerLevel.TRACE:
return 'blue';
case LoggerLevel.DEBUG:
return 'teal';
case LoggerLevel.INFO:
case LoggerLevel.LOG:
return 'gray';
case LoggerLevel.WARN:
case LoggerLevel.ERROR:
return 'red';
case LoggerLevel.OFF:
default:
return;
}
}
}

View File

@ -1,20 +0,0 @@
import { Action } from '@ngrx/store';
import {
LoggerLevel,
ServerLoggingParameter,
} from '../core';
export enum ActionType {
ServerLogging = '[@@LOGGER] ServerLogging',
}
export class ServerLogging implements Action {
readonly type = ActionType.ServerLogging;
constructor(public payload: ServerLoggingParameter) {}
}
export type Actions =
| ServerLogging
;