smartlog-destination-local/ts/beautylog.log.ts

89 lines
1.8 KiB
TypeScript
Raw Normal View History

2016-10-16 00:26:43 +00:00
import 'typings-global'
2016-02-23 13:34:40 +00:00
2016-10-16 00:26:43 +00:00
import {internalLog} from './beautylog.log.helpers'
2016-02-23 13:34:40 +00:00
/**
* logs an info to console
* @param logText
* @returns {boolean}
*/
2016-07-23 23:17:38 +00:00
export let log = (logText) => {
2016-10-16 00:26:43 +00:00
return internalLog('log',logText)
2016-07-23 23:17:38 +00:00
}
2016-06-16 00:17:28 +00:00
export let info = (logText) => {
2016-10-16 00:26:43 +00:00
return internalLog('info',logText)
}
2016-02-23 13:34:40 +00:00
/**
* logs an 'OK!' message to console
* @param logText
* @returns {boolean}
*/
2016-06-16 00:17:28 +00:00
export let ok = (logText) => {
2016-10-16 00:26:43 +00:00
return internalLog('ok',logText)
}
2016-02-23 13:34:40 +00:00
/**
* logs a success to console
* @param logText string to log as error
* @returns {boolean}
*/
2016-06-16 00:17:28 +00:00
export let success = (logText) => {
2016-10-16 00:26:43 +00:00
return internalLog('success',logText)
}
2016-02-23 13:34:40 +00:00
/**
* logs a 'warn:' message to console
* @param logText string to log as error
* @returns {boolean}
*/
2016-06-16 00:17:28 +00:00
export let warn = (logText) => {
2016-10-16 00:26:43 +00:00
return internalLog('warn',logText)
}
2016-05-02 00:23:40 +00:00
/**
* logs an error to console
* @param logText
* @returns {boolean}
*/
2016-06-16 00:17:28 +00:00
export let error = (logText) => {
2016-10-16 00:26:43 +00:00
return internalLog('error',logText)
}
2016-05-02 00:23:40 +00:00
/**
* logs an directory to console
* @param logText
* @returns {boolean}
*/
2016-06-16 00:17:28 +00:00
export let dir = (logText) => {
2016-10-16 00:26:43 +00:00
return internalLog('dir',logText)
}
2016-06-16 00:17:28 +00:00
2016-06-16 21:57:49 +00:00
/**
* creates a new empty line
* @param linesArg
* @returns void
*/
2016-10-16 00:26:43 +00:00
export let newLine = (linesArg: number = 1) => {
for (let i = 0; i < linesArg; i++) {
console.log('\n')
2016-06-16 00:17:28 +00:00
}
2016-06-16 21:57:49 +00:00
}
/**
* logs a reduced log that only logs changes of consequential log messages
*/
2016-10-16 00:26:43 +00:00
export let logReduced = (logTextArg: string,repeatEveryTimesArg: number = 0) => {
2017-01-21 00:05:28 +00:00
if (logTextArg === previousMessage && (repeatEveryTimesArg === 0 || sameMessageCounter !== repeatEveryTimesArg)) {
2016-10-16 00:26:43 +00:00
sameMessageCounter++
2016-06-16 21:57:49 +00:00
} else {
2016-10-16 00:26:43 +00:00
sameMessageCounter = 0
previousMessage = logTextArg
log(logTextArg)
2016-06-16 21:57:49 +00:00
}
2016-10-16 00:26:43 +00:00
}
let previousMessage: string = ''
let sameMessageCounter: number = 0