Skip to content

Commit

Permalink
feat: add instance name option
Browse files Browse the repository at this point in the history
  • Loading branch information
onurravli committed Nov 28, 2023
1 parent 92c92dc commit ac492a0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions dist/guvercin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface Settings {
showErrorsOnly?: boolean;
remoteLogging?: boolean;
remoteLogEndpoint?: string;
name?: string;
}
export declare enum LogLevels {
DEBUG = "DEBUG",
Expand Down
6 changes: 4 additions & 2 deletions dist/guvercin.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const defaultSettings = {
showErrorsOnly: false,
remoteLogging: false,
remoteLogEndpoint: '',
name: undefined,
};
class Guvercin {
loadSettings() {
Expand Down Expand Up @@ -77,8 +78,9 @@ class Guvercin {
const level = logLevel;
const textColor = LogColors[logLevel];
const separator = this.settings.separator;
const textColored = `${time} ${separator} ${textColor(`[${chalk_1.default.bold(level)}]`)} ${separator} ${message}`;
const textNotColored = `${time} ${separator} [${level}] ${separator} ${message}`;
const name = this.settings.name;
const textColored = `${name ? `(${name})` : ''} ${time} ${separator} ${textColor(`[${chalk_1.default.bold(level)}]`)} ${separator} ${message}`;
const textNotColored = `${name ? `(${name})` : ''} ${time} ${separator} [${level}] ${separator} ${message}`;
// TODO: Add remote logging option
// fetch('http://localhost:3000/log', { method: 'POST', body: JSON.stringify({ time, level, message }) })
// .then(() => {
Expand Down
9 changes: 7 additions & 2 deletions src/guvercin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface Settings {
showErrorsOnly?: boolean
remoteLogging?: boolean
remoteLogEndpoint?: string
name?: string
}

export enum LogLevels {
Expand Down Expand Up @@ -50,6 +51,7 @@ const defaultSettings: Settings = {
showErrorsOnly: false,
remoteLogging: false,
remoteLogEndpoint: '',
name: undefined,
}

export class Guvercin {
Expand Down Expand Up @@ -87,8 +89,11 @@ export class Guvercin {
const level = logLevel
const textColor = LogColors[logLevel]
const separator = this.settings.separator
const textColored = `${time} ${separator} ${textColor(`[${chalk.bold(level)}]`)} ${separator} ${message}`
const textNotColored = `${time} ${separator} [${level}] ${separator} ${message}`
const name = this.settings.name
const textColored = `${name ? `(${name})` : ''} ${time} ${separator} ${textColor(
`[${chalk.bold(level)}]`
)} ${separator} ${message}`
const textNotColored = `${name ? `(${name})` : ''} ${time} ${separator} [${level}] ${separator} ${message}`

// TODO: Add remote logging option
// fetch('http://localhost:3000/log', { method: 'POST', body: JSON.stringify({ time, level, message }) })
Expand Down

0 comments on commit ac492a0

Please sign in to comment.