A simple logging utility designed for rew
With pimmy:
pimmy -Sa rewpkgs/rew.loggerWith rewpkgs:
rew install -yu rewpkgs/rew.loggerWith native:
rew install -yu github:kevinJ045/rew.loggerimport { Logger } from "rew.logger"
logger = new Logger
logger.log 'hi'
logger.log 'hi', '%c1;32' # custom colorCreate a logger instance and log messages:
logger = new Logger
logger.log 'This is a log message'
logger.warn 'This is a warning message'
logger.error 'This is an error message'Customizing the options:
options =
file:
path: './logs/app.log'
style: true
writeOptions: 'sf' # 's' for console, 'f' for file, 'sf' for both
formats:
date: '[YYYY-MM-DD hh:mm:ss]'
prefix: '[CustomPrefix]'
suffix: '[CustomSuffix]'
style:
color: 'type' # use type-specific colors
type: true # keep the type prefix like [LOG] and [ERROR]
logger = new Logger options
logger.log 'This is a customized log message'Disable or enable console output dynamically:
logger.disableConsoleOutput()
logger.log 'This will not appear in console'
logger.enableConsoleOutput()
logger.log 'This will appear in console'Set a log file and optionally apply styles:
logger.setFile './logs/newfile.log', true # Putting `true` will make it so it also includes the ansi encoding and such
logger.log 'This will be logged in newfile.log'Clean the log file content:
logger.cleanFile()Set custom colors for different log types:
logger.setStyleColor('1;36') # Set general style color
logger.setTypeColor('log', '1;32') # Set log color to green
logger.setTypeColor('error', '1;35') # Set error color to magenta
logger.setTypeColor('warning', '1;33') # Set warning color to yellowA default instance that you can config.
import Logger from "rew.logger/default"
Logger.log 'hi'There's a Usage for the logger.
import Console from "rew.logger/usage"
using Console, { style: { logColor: '1;32' } }, (console) ->
console.log 'hi'Or
import Console from "rew.logger/usage"
using Console, (console) ->
console.log 'hi'new Logger(options)Parameters:
options: An object to configure the logger.
log(...text): Logs a message with 'log' type.warn(...text): Logs a message with 'warning' type.error(...text): Logs a message with 'error' type.cleanFile(): Cleans the content of the log file.disableConsoleOutput(): Disables console output.enableConsoleOutput(): Enables console output.setFile(file, useStyle): Sets the log file path and style.setDateFormat(format): Sets the date format.setSeparatorFormat(format): Sets the separator format.setPrefix(format): Sets a custom prefix.setSuffix(format): Sets a custom suffix.setStyleColor(color): Sets the general log color.setTypeColor(type, color): Sets the log color for a specific type.disableType(): Disables type labels in log messages.enableType(): Enables type labels in log messages.