Öncelikle “chalk” kütüphanesini ekliyoruz.
Her sayfada tek tekte kullanılabilir ama ben bunun için bir helpers yazdım daha rahat oluyor kullanımı. Saat için “moment-timezone” kullandım siz kendinize uygun özelleştirebilirsiniz.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
const moment = require('moment-timezone'); const chalk = require('chalk'); let logPlus = function (method, url, mesaj) { if (method == "POST") { console.log(chalk.green(moment().tz('Europe/Istanbul').format('DD/MM/YYYY HH:mm:ss')), " | ", chalk.red.bgWhiteBright(" ", method, " "), " | ", chalk.yellow(url), " | ", mesaj) } if(method == "INFO") { console.log(chalk.blackBright.bgWhiteBright(moment().tz('Europe/Istanbul').format('DD/MM/YYYY HH:mm:ss')), " | ", chalk.blackBright.bgYellowBright(" ", method, " "), " | ", mesaj) } if(method == "GET") { console.log(chalk.green(moment().tz('Europe/Istanbul').format('DD/MM/YYYY HH:mm:ss')), " | ", chalk.blackBright.bgGreenBright(" ", method, " "), " | ", chalk.yellow(url), " | ", mesaj) } } module.exports = { logPlus }; |
Diğer sayfalarda helpers çağrılır
1 2 3 |
const logBas = require('./helpers/logBas/logX'); // kullanılmak istenen yerlerde çağrılabilir logBas.logPlus("METHOD", "URL", "MESAJ") |
Styles
Modifiers
reset
– Resets the current color chain.bold
– Make text bold.dim
– Emitting only a small amount of light.italic
– Make text italic. (Not widely supported)underline
– Make text underline. (Not widely supported)inverse
– Inverse background and foreground colors.hidden
– Prints the text, but makes it invisible.strikethrough
– Puts a horizontal line through the center of the text. (Not widely supported)visible
– Prints the text only when Chalk has a color level > 0. Can be useful for things that are purely cosmetic.
Colors
black
red
green
yellow
blue
magenta
cyan
white
blackBright
(alias:gray
,grey
)redBright
greenBright
yellowBright
blueBright
magentaBright
cyanBright
whiteBright
Background colors
bgBlack
bgRed
bgGreen
bgYellow
bgBlue
bgMagenta
bgCyan
bgWhite
bgBlackBright
(alias:bgGray
,bgGrey
)bgRedBright
bgGreenBright
bgYellowBright
bgBlueBright
bgMagentaBright
bgCyanBright
bgWhiteBright
İlk Yorumu Siz Yapın