1.6.9 • Published 3 years ago

kufa v1.6.9

Weekly downloads
24
License
MIT
Repository
-
Last release
3 years ago

Kufa

Instalation

// With NPM
$ npm install kufa --save

// With Yarn
$ yarn add kufa

Changelogs

[22/06/2021]: "2 new parameters were added to the KufaConsole class, one called parser and another called depth."

[25/05/21]: "Fixed false trace"

[03/05/21]: "All npm transferred to typescript"

[27/04/2021]: "A function was implemented to avoid errors in typescript with node >= v14"

[25/04/2021]: "The KufaConsole class was modified a little, the palette was eliminated and it was possible to further customize the message that is given in log, warn and error"

[08/01/2021]: "Added 2 parameters to show ram usage"

[31/12/2020]: "The trace was fixed and it was improved, another fix in typings, The name of the Console class was modified to KufaConsole due to TypeScript incompatibility"

[30/12/2020]: "Fixed some errors in typings and added an option to trace the function from where the log / warn / error was sent"

Using in your project:

  • Javascript
const kufa = require('kufa');

console = new kufa.KufaConsole({
    timeZone: false || 'America/Argentina/Buenos_Aires', //The time zone the logs will be based on
    onlyHours: false || true, //With this you will manage if you want the day / month / year to appear in the log
    save: false || true, //If you want all the logs to be stored in a file
    traceFun: false || true, //This adds to the end of the trace the function since it was sent
    memoryFun: false || Function, //With this you can customize how the memory is obtained (if you work in another way)
    dir: false || proces.cwd() || __dirname, //Path where the folder to store the logs will be created
    format: false || `[§a%time%§r] [%prefix%§r] %message% %trace% %memory%`,
    log_prefix: false || `§2LOG`,
    warn_prefix: false || `§6WARN`,
    error_prefix: false || `§4ERROR`,
    parser: false || (ctx) => {
       //do something 
    }, // With this function kufa gives you the context of each log where you can modify the format, the time and what happens as long as it does not conflict with kufa
    depth: false || 0, // With this function you can define the depth of the trace (that is, the pathname)
    formaters: [
        kufa.formatters.chalk,
        kufa.formatters.colors
    ], // This will format the message to have colors, emotes and a lot of other things you want, you just have to leave an object with two functions (parser, cleaner)
    maxMb: 100, // Here you define the maximum size that each log file will have, once it exceeds the defined size, a zip file will be created where the log will be stored and a new one will be created where logging will continue.
    traceFilters: [
        new RegExp(),
        /a/g
    ] // Filters to avoid certain callsite
});

//All configurations are optional
//At the bottom there is an example of use with socket

console.log(`§5Hi world`);

//If you want to be aware of what is happening internally you can log everything that is emitted in the debug event

console.on('debug', (msg) => console.log(msg));

Formatter example

  • Typescript
//typings/index.d.ts

import { KufaConsole } from 'kufa';

declare global {
	
	interface Console {
		on(event: string, handler: () => void): any
	}

    namespace NodeJS {
        interface Global {
            Console: KufaConsole
        }
    }

}

//index.ts

import './typings/index.ts';

import { KufaConsole } from 'kufa';

console = new KufaConsole({
    timeZone: false || 'America/Argentina/Buenos_Aires', //The time zone the logs will be based on
    onlyHours: false || true, //With this you will manage if you want the day / month / year to appear in the logto send it, here is the ip of that socket
    save: false || true, //If you want all the logs to be stored in a file
    trace: false || true, //This will add to the end of each log the file from which it was sent
    traceFun: false || true, //This adds to the end of the trace the function since it was sent
    memoryFun: false || Function, //With this you can customize how the memory is obtained (if you work in another way)
    showMemory: false || true, //This adds to the end of the process memory usage
    dir: false || __dirname, //Path where the folder to store the logs will be created
    format: false || `[§a%time%§r] [%prefix%§r] %message%`,
    log_prefix: false || `§2LOG`,
    warn_prefix: false || `§6WARN`,
    error_prefix: false || `§4ERROR`,
    parser: false || (ctx) => {
       //do something 
    }, // With this function kufa gives you the context of each log where you can modify the format, the time and what happens as long as it does not conflict with kufa
    depth: false || 0, // With this function you can define the depth of the trace (that is, the pathname)
    formaters: [
        kufa.formatters.chalk,
        kufa.formatters.colors
    ], // This will format the message to have colors, emotes and a lot of other things you want, you just have to leave an object with two functions (parser, cleaner)
    maxMb: 100, // Here you define the maximum size that each log file will have, once it exceeds the defined size, a zip file will be created where the log will be stored and a new one will be created where logging will continue.
    traceFilters: [
        new RegExp(),
        /a/g
    ] // Filters to avoid certain callsite
});

//All configurations are optional
//At the bottom there is an example of use with socket

console.log(`§5Hi world`);

//If you want to be aware of what is happening internally you can log everything that is emitted in the debug event

console.on('debug', (msg: string) => console.log(msg));

Formatter example:

const emotes = {
	"check": "✔",
	"x": "❌",
	"heart": "❤",
	"clap": "👏",
	"exclamation": "❗"
}

const emote = {
	parser: (str) => {
		str = str.replace(new RegExp(`%(${Object.keys(emotes).join('|')})%`, 'igm'), (s) => {
			
			const emote = emotes[s.split('%').join('')]

			return emote ? emote : s;
		})
		return str;
	},
	cleaner: (str) => {
		str = str.replace(new RegExp(`%(${Object.keys(emotes).join('|')})%`, 'igm'), (s) => {
			
			const emote = emotes[s.split('%').join('')]

			return emote ? emote : s;
		})
		return str;
	}
}

Console Methods:

oldLog:

  • It's the old console.log
/**
 * @param {...Any}
 */ 

console.oldLog('Hi world');

oldWarn:

  • It's the old console.warn
/**
 * @param {...Any}
 */ 

console.oldWarn('Hi world');

oldError:

  • It's the old console.error
/**
 * @param {...Any}
 */ 

console.oldError('Hi world');

log:

  • The new console.log with several improvements
/**
 * @param {...Any}
 */ 

console.log('§5Hi world');

// Will send to the console something like this:
// [LOG] [12/25/2020 2:46:16] Hi world

warn:

  • The new console.warn with several improvements
/**
 * @param {...Any}
 */ 

console.warn('§5Hi world');

// Will send to the console something like this:
// [WARN] [12/25/2020 2:46:16] Hi world

error:

  • The new console.error with several improvements
/**
 * @param {...Any}
 */ 

console.error('§5Hi world');

// Will send to the console something like this:
// [ERROR] [12/25/2020 2:46:16] Hi world

Socket

  • Soon

Example:

  • Socket
Soon
  • Console
Soon
  • Context properties
import { KufaContext } from 'kufa';

new KufaContext({
    type: 'log' | 'warn' | 'error',
    str: string,
    trace: {
        path: string,
        fn?: string
    },
    format: string,
    zone: string,
    prefix: string,
    enableFN: boolean,
    memory: string,
    hours: boolean,
    time: Date,
    formatters: []
})
1.7.0

3 years ago

1.6.9

3 years ago

1.6.8

3 years ago

1.6.7

3 years ago

1.6.6

3 years ago

1.6.4

3 years ago

1.6.3

3 years ago

1.6.2

3 years ago

1.6.1

3 years ago

1.6.5

3 years ago

1.6.0

4 years ago

1.5.9

4 years ago

1.5.8

4 years ago

1.5.5

4 years ago

1.5.3

4 years ago

1.5.2

4 years ago

1.5.1

4 years ago

1.5.0

4 years ago

1.5.7

4 years ago

1.5.6

4 years ago

1.4.3

4 years ago

1.4.2

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.5

5 years ago

1.2.0

5 years ago

1.1.9

5 years ago

1.1.8

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.0.0

5 years ago