forked from skolmer/i18n-tag-schema
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logging.js
59 lines (55 loc) · 1.34 KB
/
logging.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* Logging helper function
*
* @param {Object} logger - The logger object.
* @param {any} message - The message to log.
* @param {string} [type=log] - The type of the log function.
*/
function log(logger, message, type) {
if(!logger) return
if(logger.toConsole) {
if (console.group) console.group('i18n-tag-schema')
const log = console[type] || console.log
log(message)
if (console.groupEnd) console.groupEnd()
} else {
const log = logger[type]
if(log) log(message)
}
}
/**
* Info logging helper function
*
* @param {Object} logger - The logger object.
* @param {any} message - The message to log.
*/
export function logInfo(logger, message) {
log(logger, message, 'info')
}
/**
* Trace logging helper function
*
* @param {Object} logger - The logger object.
* @param {any} message - The message to log.
*/
export function logTrace(logger, message) {
log(logger, message, 'trace')
}
/**
* Error logging helper function
*
* @param {Object} logger - The logger object.
* @param {string} message - The message to log.
*/
export function logError(logger, message) {
log(logger, message, 'error')
}
/**
* Warning logging helper function
*
* @param {Object} logger - The logger object.
* @param {string} message - The message to log.
*/
export function logWarn(logger, message) {
log(logger, message, 'warn')
}