Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamRagstad committed Mar 9, 2022
1 parent 76887e4 commit 316e32d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion example/controller/UserController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {
Context,
Controller,
created,
internalServerError,
Endpoint,
IController,
internalServerError,
Logger,
ok,
Params,
Expand Down
21 changes: 12 additions & 9 deletions src/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ export function Optional() {
*/

export function Service<T>(target: Constructor<T>) {
const singletonTarget = target as unknown as Constructor<T> & { instance: () => T, _instance: T };
singletonTarget.instance = () => {
if (!singletonTarget._instance) {
singletonTarget._instance = new target();
}
return singletonTarget._instance;
};
return singletonTarget;
};
const singletonTarget = target as unknown as Constructor<T> & {
instance: () => T;
_instance: T;
};
singletonTarget.instance = () => {
if (!singletonTarget._instance) {
singletonTarget._instance = new target();
}
return singletonTarget._instance;
};
return singletonTarget;
}
8 changes: 6 additions & 2 deletions src/logger/ConsoleSink.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Sink } from "./Sink.ts";
import { ColorOptions, LoggingFormatter, LoggingLevel } from "../types.ts";
import { defaultColorOptions, defaultTimestamp, textFormatter } from "./defaults.ts";
import {
defaultColorOptions,
defaultTimestamp,
textFormatter,
} from "./defaults.ts";

/**
* A console sink that writes to the terminal using a set of colors.
Expand Down Expand Up @@ -33,7 +37,7 @@ export class ConsoleSink extends Sink {
level: level,
timestamp: defaultTimestamp(),
levelColorFunction: colorFunction,
colorsEnabled: this._enableColors
colorsEnabled: this._enableColors,
});
switch (level) {
case LoggingLevel.Log:
Expand Down
2 changes: 1 addition & 1 deletion src/logger/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class Logger {
* Logs a message at the `Debug` level.
* @param data Values to log.
*/
public success(...data: any[]): void {
public success(...data: any[]): void {
this._log(data, LoggingLevel.Success);
}

Expand Down
11 changes: 5 additions & 6 deletions src/logger/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,14 @@ export const identityColorFunction: ColorFunction = (s) => s;
export const isoTimestamp = (): string => new Date().toISOString();

/**
*
* @returns
*/
export const defaultTimestamp = (): string => {
const full = isoTimestamp();
const date = full.substring(0, full.indexOf("T"));
const time = full.substring(full.indexOf("T") + 1, full.indexOf("."));
return `${date} ${time}`;
}
const full = isoTimestamp();
const date = full.substring(0, full.indexOf("T"));
const time = full.substring(full.indexOf("T") + 1, full.indexOf("."));
return `${date} ${time}`;
};

/**
* Format a message as human readable text of the form `TIME [LEVEL] MESSAGE`.
Expand Down

0 comments on commit 316e32d

Please sign in to comment.