-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit dc81dc1
Showing
7 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# compiled output | ||
/dist | ||
/node_modules | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# OS | ||
.DS_Store | ||
|
||
# Tests | ||
/coverage | ||
/.nyc_output | ||
|
||
# IDEs and editors | ||
/.idea | ||
.project | ||
.classpath | ||
.c9/ | ||
*.launch | ||
.settings/ | ||
*.sublime-workspace | ||
*.iml | ||
# IDE - VSCode | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "@uspasojevic/logger", | ||
"version": "1.0.0", | ||
"description": "Basic logger", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"scripts": { | ||
"build": "tsc", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/uspasojevic96/logger.git" | ||
}, | ||
"keywords": [ | ||
"logger", | ||
"logging" | ||
], | ||
"author": "Uros Spasojevic", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/uspasojevic96/logger/issues" | ||
}, | ||
"homepage": "https://github.com/uspasojevic96/logger#readme", | ||
"devDependencies": { | ||
"typescript": "^4.1.3" | ||
}, | ||
"dependencies": { | ||
"kleur": "^4.1.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './logger'; | ||
export * from './log-level'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export enum LogLevel { | ||
WARNING = 1, | ||
ERROR = 2, | ||
INFO = 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import {LogLevel} from "./log-level"; | ||
import {cyan, red, white, yellow} from "kleur"; | ||
|
||
export class Logger { | ||
private logLevel: LogLevel = LogLevel.ERROR; | ||
|
||
public log(level: LogLevel, tag: string, message: string): void { | ||
switch(level) { | ||
case LogLevel.ERROR: | ||
this.logError(tag, message); | ||
break; | ||
case LogLevel.INFO: | ||
this.logInfo(tag, message); | ||
break; | ||
case LogLevel.WARNING: | ||
this.logWarning(tag, message); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
private generatePrefix(tag: string): string { | ||
let date: any = new Date().toISOString().split('T'); | ||
date = `${date[0]} ${date[1].substring(0, date[1].length - 5)}`; | ||
|
||
return `${cyan(tag)} : ${date} : `; | ||
} | ||
|
||
private logError(tag: string, message: string): void { | ||
if (this.logLevel >= LogLevel.ERROR) { | ||
const str = `${this.generatePrefix(tag)}${red('[ERROR]')} ${message}`; | ||
console.log(str); | ||
} | ||
} | ||
|
||
private logInfo(tag: string, message: string): void { | ||
if (this.logLevel >= LogLevel.INFO) { | ||
const str = `${this.generatePrefix(tag)}${white('[INFO]')} ${message}`; | ||
console.log(str); | ||
} | ||
} | ||
|
||
private logWarning(tag: string, message: string): void { | ||
if (this.logLevel >= LogLevel.WARNING) { | ||
const str = `${this.generatePrefix(tag)}${yellow('[WARNING]')} ${message}`; | ||
console.log(str); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ | ||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ | ||
"strict": true, /* Enable all strict type-checking options. */ | ||
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ | ||
"skipLibCheck": true, /* Skip type checking of declaration files. */ | ||
"rootDir": "src", | ||
"outDir": "dist", | ||
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */, | ||
"sourceMap": true, | ||
"declaration": true | ||
}, | ||
} |