-
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.
feat: update for release 1.1.2 with the classic and the mini version
- Loading branch information
1 parent
8f62397
commit 5ba3a23
Showing
10 changed files
with
209 additions
and
30 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 |
---|---|---|
|
@@ -15,7 +15,8 @@ and improve some features | |
Basic logging out: | ||
|
||
```ts | ||
import { Dlog } from 'https://deno.land/x/[email protected]/mod.ts'; | ||
import { Dlog } from 'https://deno.land/x/[email protected]/classic.ts'; // Classic version with the classic out! | ||
import { Dlog } from 'https://deno.land/x/[email protected]/mini.ts'; // Mini version the same features of classic but with a minimalist out! | ||
|
||
const logger = new Dlog('Test Dlog'); | ||
|
||
|
@@ -28,7 +29,8 @@ logger.debug('helloooo from debug'); | |
File log support | ||
|
||
```ts | ||
import { Dlog } from 'https://deno.land/x/[email protected]/mod.ts'; | ||
import { Dlog } from 'https://deno.land/x/[email protected]/classic.ts'; // Classic version with the classic out! | ||
import { Dlog } from 'https://deno.land/x/[email protected]/mini.ts'; // Mini version the same features of classic but with a minimalist out! | ||
|
||
const logger = new Dlog('Test Dlog', true, './test'); | ||
|
||
|
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
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,23 @@ | ||
import Dlog from '../classic.ts'; | ||
|
||
// App without files | ||
const logs = new Dlog('An Example App'); | ||
// App with files | ||
const logsFile = new Dlog('An Example App With Files', true); | ||
|
||
// Without Files examples | ||
|
||
logs.info('Info example'); | ||
logs.debug('Debug Example'); | ||
logs.warn('Warn Example'); | ||
logs.error('Error Example'); | ||
// WTF DONE? Yeah new feature :p | ||
logs.done('Done Example'); | ||
|
||
// Wit Files | ||
logsFile.info('Info example'); | ||
logsFile.debug('Debug Example'); | ||
logsFile.warn('Warn Example'); | ||
logsFile.error('Error Example'); | ||
// WTF DONE? Yeah new feature :p | ||
logsFile.done('Done Example'); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
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,28 @@ | ||
import Dlog from '../mini.ts'; | ||
|
||
// What is this ? | ||
// | ||
// Well if you want a more minimalist out here are the feature you need! | ||
// The sames features of the classic but with other style! | ||
|
||
// App without files | ||
const logs = new Dlog('An Example App'); | ||
// App with files | ||
const logsFile = new Dlog('An Example App With Files', true); | ||
|
||
// Without Files examples | ||
|
||
logs.info('Info example'); | ||
logs.debug('Debug Example'); | ||
logs.warn('Warn Example'); | ||
logs.error('Error Example'); | ||
// WTF DONE? Yeah new feature :p | ||
logs.done('Done Example'); | ||
|
||
// Wit Files | ||
logsFile.info('Info example'); | ||
logsFile.debug('Debug Example'); | ||
logsFile.warn('Warn Example'); | ||
logsFile.error('Error Example'); | ||
// WTF DONE? Yeah new feature :p | ||
logsFile.done('Done Example'); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
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,129 @@ | ||
/** | ||
* Copyright © 2022 Dpm Land. All Rights Reserved. | ||
*/ | ||
|
||
import { colors, ensureDirSync, format, join } from './deps.ts'; | ||
|
||
/** | ||
* @description The constructor for the dlog module | ||
* @param {string} app_name - The application name for the logger output | ||
* @param {boolean} logToFile - Write a log file DEFAULT: true | ||
* @param {string} logFolder - The folder name to create and log | ||
*/ | ||
export default class Dlog { | ||
private _app = ''; | ||
private _logToFile: boolean; | ||
private _logFolder: string; | ||
private _date: string; | ||
|
||
constructor( | ||
app_name: string, | ||
logToFile: boolean = false, | ||
logFolder: string = 'logs', | ||
) { | ||
this._app = app_name; | ||
this._logToFile = logToFile; | ||
this._logFolder = logFolder; | ||
this._date = format(new Date(), 'yyyy|MM|dd'); | ||
} | ||
/** | ||
* @description Log with the info level | ||
* @param {string} message - The message to log | ||
*/ | ||
info(message: string): void { | ||
const noColorMsg = `[${ | ||
format(new Date(), 'yyyy/MM/dd h:mm:ss a') | ||
}] [${this._app}] [INFO] ${message}`; | ||
console.log( | ||
`${colors.italic(colors.green(`${this._app.toUpperCase()} ->`))} ${ | ||
colors.blue('[ INFO ]:') | ||
} ${message}`, | ||
); | ||
if (this._logToFile) { | ||
this.writeToFile(noColorMsg); | ||
} | ||
} | ||
/** | ||
* @description Log with the debug level | ||
* @param {string} message - The message to log | ||
*/ | ||
debug(message: string): void { | ||
const noColorMsg = `[${ | ||
format(new Date(), 'yyyy/MM/dd h:mm:ss a') | ||
}] [${this._app}] [DEBUG] ${message}`; | ||
console.log( | ||
`${colors.italic(colors.green(`${this._app.toUpperCase()} ->`))} ${ | ||
colors.magenta('[ DEBUG ]:') | ||
} ${message}`, | ||
); | ||
if (this._logToFile) { | ||
this.writeToFile(noColorMsg); | ||
} | ||
} | ||
|
||
/** | ||
* @description Log with the warn level | ||
* @param {string} message - The message to log | ||
*/ | ||
warn(message: string): void { | ||
const noColorMsg = `[${ | ||
format(new Date(), 'yyyy/MM/dd h:mm:ss a') | ||
}] [${this._app}] [WARN] ${message}`; | ||
console.log( | ||
`${colors.italic(colors.green(`${this._app.toUpperCase()} ->`))} ${ | ||
colors.brightYellow('[ WARN ]:') | ||
} ${message}`, | ||
); | ||
if (this._logToFile) { | ||
this.writeToFile(noColorMsg); | ||
} | ||
} | ||
|
||
/** | ||
* @description Log with the error level | ||
* @param {string} message - The message to log | ||
*/ | ||
|
||
error(message: string): void { | ||
const noColorMsg = `[${ | ||
format(new Date(), 'yyyy/MM/dd h:mm:ss a') | ||
}] [${this._app}] [ERROR] ${message}`; | ||
console.log( | ||
`${colors.italic(colors.green(`${this._app.toUpperCase()} ->`))} ${ | ||
colors.brightRed('[ ✗ ERROR ]:') | ||
} ${message}`, | ||
); | ||
if (this._logToFile) { | ||
this.writeToFile(noColorMsg); | ||
} | ||
} | ||
|
||
/** | ||
* @description Log with the done level | ||
* @param {string} message - The message to log | ||
*/ | ||
|
||
done(message: string): void { | ||
const noColorMsg = `[${ | ||
format(new Date(), 'yyyy/MM/dd h:mm:ss a') | ||
}] [${this._app}] [DONE] ${message}`; | ||
console.log( | ||
`${colors.italic(colors.green(`${this._app.toUpperCase()} ->`))} ${ | ||
colors.brightGreen('[ DONE ]:') | ||
} ${message}`, | ||
); | ||
if (this._logToFile) { | ||
this.writeToFile(noColorMsg); | ||
} | ||
} | ||
|
||
private writeToFile(noColorMsg: string): void { | ||
ensureDirSync(this._logFolder); | ||
const appName = this._app.replace(' ', '-'); | ||
const path = join(this._logFolder, `${appName}.log`); | ||
Deno.writeTextFileSync(path, noColorMsg + '\n', { | ||
append: true, | ||
create: true, | ||
}); | ||
} | ||
} |