1.0.9 • Published 2 years ago
@horizoncode/eazylog v1.0.9
eazylog
a easy to use logging library
Preview Image
How to use it
Import package from npm
npm i @horizoncode/eazylog
Create a logger
const Logger = require('@horizoncode/eazylog')
const logger = new Logger("My Project") // the String equals your Project name etc.
Change color
You can easily change the color
logger.log("[red]i am red! [blue]now i am blue daba di daba die")
Available text colors are:
- black
- red
- green
- yellow
- blue
- cyan
- magenta
- white
- gray
- grey
- blackBright
- redBright
- greenBright
- yellowBright
- blueBright
- cyanBright
- magentaBright
- whiteBright
Available background colors are:
- bgBlack
- bgRed
- bgGreen
- bgYellow
- bgBlue
- bgCyan
- bgMagenta
- bgWhite
- bgGray
- bgGrey
- bgBlackBright
- bgRedBright
- bgGreenBright
- bgYellowBright
- bgBlueBright
- bgCyanBright
- bgMagentaBright
- bgWhiteBright
Available font styles are:
- bold
- dim
- italic
- underline
- overline
- inverse
- hidden
- strikethrough
To reset everything use:
- reset
set Timestamp format
Update the default timestamp(yyyy-MM-dd HH:mm:ss) to your own format
logget.setDateTimeFormat("HH:mm:ss");
Debug
You can toggle the Debug mode by a simple function
logger.setDebug(true/false);
logger.log("[purple][italic]This is a Debug message", 'DEBUG') // This will only print if debug mode is acitve
Traces
You don't know where the log comes from? add a stack trace!
logger.logTraced("This text got sent with a trace") // => This text got sent with a trace |-> /home/eazylog/project/index.js:10:12
File Logging
It's very easy to log to a file
const path = require('path');
log.startFileLogging(path.join(__dirname, 'logfile.txt'));
The logger will write into that defined logfile until the stopFileLogging()
function is called
log.stopFileLogging();
Example
You want to print different states of logs.
const Logger = require('@horizoncode/eazylog')
const logger = new Logger("Example")
logger.log("This is a Info message", 'INFO')
logger.log("This is a Warning message", 'WARNING')
logger.log("This is a Error message", 'ERROR')
logger.log("This is a Debug message", 'DEBUG')
//You can even define custom LogTypes, and use colors here.
logger.log("This is a help message", 'HELP')
logger.log("the logtype of this help message is yellow :o", '[yellow]YELLOW_HELP')