1 | const util = require('util');
|
2 |
|
3 | const writeLine = (prefix, msg, stream) => {
|
4 | stream.write(`[squidex-client-manager][${prefix}]: ${msg}\n`);
|
5 | };
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | function Debug(msg) {
|
13 | if (process.env.PRODUCTION) {
|
14 | return;
|
15 | }
|
16 | writeLine('debug', msg, process.stdout);
|
17 | }
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | const Info = msg => writeLine('info', msg, process.stdout);
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | const Error = (error) => {
|
30 | writeLine('error', error, process.stdout);
|
31 | if (error.stack) {
|
32 | writeLine('stack', error.stack, process.stdout);
|
33 | }
|
34 | };
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | const bail = (msg, err, exitCode) => {
|
43 | Info(msg);
|
44 | Error(err);
|
45 |
|
46 | if (exitCode) {
|
47 | process.exit(exitCode);
|
48 | } else {
|
49 | process.exit(1);
|
50 | }
|
51 | };
|
52 |
|
53 | const inspect = (prefix, object) => {
|
54 | Info(`${prefix} inspecting ${util.inspect(object)}`);
|
55 | };
|
56 |
|
57 | module.exports.Log = {
|
58 | Debug,
|
59 | Info,
|
60 | Error,
|
61 | bail,
|
62 | inspect,
|
63 | };
|