This repository was archived by the owner on Apr 18, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.js
More file actions
131 lines (97 loc) · 2.93 KB
/
logger.js
File metadata and controls
131 lines (97 loc) · 2.93 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Prepare Log
let logger = null;
const objType = require('@tinypudding/puddy-lib/get/objType');
const clone = require('clone');
// Fix BigInt
const loopInteraction = function (data) {
// Check Data
const interaction = {};
const checkData = function (item) {
// Checking
if (objType(data[item], 'object') || Array.isArray(data[item])) {
interaction[item] = {};
interaction[item] = loopInteraction(data[item]);
}
// BigInt
else if (objType(data[item], 'bigint')) {
data[item] = { _type_object: 'BIGINT', value: data[item].toString() };
}
// Complete
return;
}
// Data
if (objType(data, 'object') || Array.isArray(data)) {
for (const item in data) {
checkData(item);
}
} else {
// Get BigInt
if (objType(data, 'bigint')) {
data = { _type_object: 'BIGINT', value: data.toString() };
}
}
// Complete
return data;
};
// Module Base
const logBase = async function (type, args) {
// Production
if (!require('./isEmulator')()) {
// Try Get Log
if (!logger) {
try {
logger = require("firebase-functions/logger");
} catch (err) {
logger = null;
console.error('Firebase Logger Module not found or something happened.');
}
}
// Exist Log
if (logger) {
let consoleData;
if(objType(args, 'error')) {
consoleData = JSON.parse(JSON.stringify(args, Object.getOwnPropertyNames(args)));
} else {
consoleData = args;
}
for (const item in consoleData) {
let argData = clone(consoleData[item]);
loopInteraction(argData);
if (objType(argData, 'object') || Array.isArray(argData)) {
argData = JSON.stringify(argData, null, 2);
}
consoleData[item] = argData;
}
const result = await logger[type].apply(logger, consoleData);
return {
result: result,
type: 'firebase-functions/logger'
};
}
// Nope
else {
return {
result: console[type].apply(console, args),
type: 'console/javascript-vanilla'
};
}
}
// Nope
else {
return {
result: console[type].apply(console, args),
type: 'console/javascript-vanilla'
};
}
};
// Module
module.exports = {
// Log
log: function () { return logBase('log', arguments); },
// Info
info: function () { return logBase('info', arguments); },
// Warn
warn: function () { return logBase('warn', arguments); },
// Error
error: function () { return logBase('error', arguments); },
};