src/utils/logs/index.coffee |
|
|---|---|
This file contains the logging utilities used accross Neat.
Use this methods rather than Table Of Content |
Logger = require './logger' |
In case the |
try colors = require 'colors' catch e console.log """Can't find colors module Run cake install to install the dependencies.""" |
A logger instance is created at startup. |
logger = new Logger |
Logging Utilities |
|
Colorization |
|
color |
|
The color function is used to prevent the colorization of a string
to fail when the |
color = (str, color) -> if str[color]? then str[color] else str |
blue |
|
Returns the passed-in string colorized in blue, if the |
blue = (str) -> color str, 'blue' |
cyan |
|
Returns the passed-in string colorized in cyan, if the |
cyan = (str) -> color str, 'cyan' |
green |
|
Returns the passed-in string colorized in green, if the |
green = (str) -> color str, 'green' |
inverse |
|
Returns the passed-in string colorized in inverse, if the |
inverse = (str) -> color str, 'inverse' |
magenta |
|
Returns the passed-in string colorized in magenta, if the |
magenta = (str) -> color str, 'magenta' |
red |
|
Returns the passed-in string colorized in red, if the |
red = (str) -> color str, 'red' |
yellow |
|
Returns the passed-in string colorized in yellow, if the |
yellow = (str) -> color str, 'yellow' |
Logging |
|
puts |
|
Log a message that automatically end with a new line character. |
puts = (str, level=0) -> logger.log "#{str}\n", level |
Log a message without automatic new line character at the end. |
print = (str, level=0) -> logger.log str, level |
prefix |
|
Prefix the passed-in string with the passed-in prefix. |
prefix = (string, prefix) -> "#{prefix} #{string}" |
fatal |
|
Log a message using the |
fatal = (string) -> puts prefix(string, inverse red " FATAL "), Logger.FATAL |
error |
|
Log a message using the |
error = (string) -> puts prefix(string, inverse red " ERROR "), Logger.ERROR |
warn |
|
Log a message using the |
warn = (string) -> puts prefix(string, inverse yellow " WARN "), Logger.WARN |
info |
|
Log a message using the |
info = (string) -> puts prefix(string, inverse green " INFO "), Logger.INFO |
debug |
|
Log a message using the |
debug = (string) -> puts prefix(string, inverse blue " DEBUG "), Logger.DEBUG |
Other Utilities |
|
missing |
|
Generates a message for a missing resources. |
missing = (path) -> _ = require('../../neat').i18n.getHelper() red _('neat.errors.missing', missing: path) |
notOutsideNeat |
|
Generates a messages for a neat command that can't run outside of a Neat project. |
notOutsideNeat = (s) -> _ = require('../../neat').i18n.getHelper() red _('neat.errors.outside_neat', expression: s) module.exports = { blue, cyan, debug, error, green, info, inverse, logger, magenta, missing, notOutsideNeat, prefix, print, puts, red, warn, yellow, } |