Skip to content

Commit

Permalink
feat: update for release 1.1.2 with the classic and the mini version
Browse files Browse the repository at this point in the history
  • Loading branch information
TeoDev1611 committed Mar 19, 2022
1 parent 8f62397 commit 5ba3a23
Show file tree
Hide file tree
Showing 10 changed files with 209 additions and 30 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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');

Expand Down
25 changes: 25 additions & 0 deletions mod.ts → classic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,31 @@ export default class Dlog {
}
}

/**
* @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.brightGreen(
colors.bold(
'[' + format(new Date(), 'yyyy/MM/dd h:mm:ss a') + ']',
),
)
} ${colors.italic(colors.green('[' + this._app + ']'))} ${
colors.brightGreen('[  DONE ]:')
} ${message}`,
);
if (this._logToFile) {
this.writeToFile(noColorMsg);
}
}

private writeToFile(noColorMsg: string): void {
ensureDirSync(this._logFolder);
const appName = this._app.replace(' ', '-');
Expand Down
23 changes: 23 additions & 0 deletions examples/classic.ts
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');
5 changes: 0 additions & 5 deletions examples/debug.ts

This file was deleted.

5 changes: 0 additions & 5 deletions examples/error.ts

This file was deleted.

5 changes: 0 additions & 5 deletions examples/info.ts

This file was deleted.

28 changes: 28 additions & 0 deletions examples/mini.ts
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');
5 changes: 0 additions & 5 deletions examples/warn.ts

This file was deleted.

8 changes: 0 additions & 8 deletions examples/writeFile.ts

This file was deleted.

129 changes: 129 additions & 0 deletions mini.ts
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,
});
}
}

0 comments on commit 5ba3a23

Please sign in to comment.