@miketako3/cloki 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -1
- package/biome.json +0 -15
- package/src/index.ts +0 -1
- package/src/logger.ts +0 -160
- package/tsconfig.json +0 -14
package/package.json
CHANGED
package/biome.json
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://biomejs.dev/schemas/1.5.2/schema.json",
|
|
3
|
-
"organizeImports": {
|
|
4
|
-
"enabled": true
|
|
5
|
-
},
|
|
6
|
-
"linter": {
|
|
7
|
-
"enabled": true,
|
|
8
|
-
"rules": {
|
|
9
|
-
"recommended": true
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
"files": {
|
|
13
|
-
"ignore": ["dist/*.js", "dist/*.d.ts", "dist/*.d.ts.map", "dist/*.js.map"]
|
|
14
|
-
}
|
|
15
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import { getLokiLogger } from "./logger";
|
package/src/logger.ts
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Loki config
|
|
3
|
-
*/
|
|
4
|
-
type LokiConfig = {
|
|
5
|
-
lokiHost: string;
|
|
6
|
-
lokiToken: string;
|
|
7
|
-
lokiUser: string;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Loki labels
|
|
12
|
-
*/
|
|
13
|
-
type LokiLabels = {
|
|
14
|
-
[key: string]: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Loki message
|
|
19
|
-
*/
|
|
20
|
-
type LokiMessage = {
|
|
21
|
-
streams: [
|
|
22
|
-
{
|
|
23
|
-
stream: LokiLabels;
|
|
24
|
-
values: [string[]];
|
|
25
|
-
},
|
|
26
|
-
];
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Create a Loki logger
|
|
31
|
-
* logger has some async logging methods like info, error, warn, etc.
|
|
32
|
-
*
|
|
33
|
-
* @param config
|
|
34
|
-
*/
|
|
35
|
-
export const getLokiLogger = (
|
|
36
|
-
config: LokiConfig,
|
|
37
|
-
): {
|
|
38
|
-
info: (message: object) => Promise<void>;
|
|
39
|
-
warn: (message: object) => Promise<void>;
|
|
40
|
-
error: (message: object) => Promise<void>;
|
|
41
|
-
debug: (message: object) => Promise<void>;
|
|
42
|
-
} => {
|
|
43
|
-
return {
|
|
44
|
-
info: lokiInfo(config),
|
|
45
|
-
warn: lokiWarn(config),
|
|
46
|
-
error: lokiError(config),
|
|
47
|
-
debug: lokiDebug(config),
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Log info to Loki curried
|
|
53
|
-
*
|
|
54
|
-
* @param config
|
|
55
|
-
*/
|
|
56
|
-
const lokiInfo =
|
|
57
|
-
(config: LokiConfig) =>
|
|
58
|
-
async (message: object, labels: LokiLabels = {}) => {
|
|
59
|
-
await log(config, "info", message, labels);
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Log warn to Loki curried
|
|
64
|
-
*
|
|
65
|
-
* @param config
|
|
66
|
-
*/
|
|
67
|
-
const lokiWarn =
|
|
68
|
-
(config: LokiConfig) =>
|
|
69
|
-
async (message: object, labels: LokiLabels = {}) => {
|
|
70
|
-
await log(config, "warn", message, labels);
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Log error to Loki curried
|
|
75
|
-
*
|
|
76
|
-
* @param config
|
|
77
|
-
*/
|
|
78
|
-
const lokiError =
|
|
79
|
-
(config: LokiConfig) =>
|
|
80
|
-
async (message: object, labels: LokiLabels = {}) => {
|
|
81
|
-
await log(config, "error", message, labels);
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Log debug to Loki curried
|
|
86
|
-
*
|
|
87
|
-
* @param config
|
|
88
|
-
*/
|
|
89
|
-
const lokiDebug =
|
|
90
|
-
(config: LokiConfig) =>
|
|
91
|
-
async (message: object, labels: LokiLabels = {}) => {
|
|
92
|
-
await log(config, "debug", message, labels);
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Log to Loki
|
|
97
|
-
*
|
|
98
|
-
* @param config
|
|
99
|
-
* @param logLevel
|
|
100
|
-
* @param message
|
|
101
|
-
* @param labels
|
|
102
|
-
*/
|
|
103
|
-
async function log(
|
|
104
|
-
config: LokiConfig,
|
|
105
|
-
logLevel: string,
|
|
106
|
-
message: object,
|
|
107
|
-
labels: LokiLabels,
|
|
108
|
-
) {
|
|
109
|
-
console.log(message);
|
|
110
|
-
const lokiMessage = generateLokiMessage(logLevel, message, labels);
|
|
111
|
-
await sendToLoki(config, lokiMessage);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Generate a Loki message object
|
|
116
|
-
*
|
|
117
|
-
* @param logLevel
|
|
118
|
-
* @param message
|
|
119
|
-
* @param labels
|
|
120
|
-
*/
|
|
121
|
-
function generateLokiMessage(
|
|
122
|
-
logLevel: string,
|
|
123
|
-
message: object,
|
|
124
|
-
labels: LokiLabels,
|
|
125
|
-
): LokiMessage {
|
|
126
|
-
return {
|
|
127
|
-
streams: [
|
|
128
|
-
{
|
|
129
|
-
stream: {
|
|
130
|
-
level: logLevel,
|
|
131
|
-
...labels,
|
|
132
|
-
},
|
|
133
|
-
values: [[`${Date.now().toString()}000000`, message.toString()]],
|
|
134
|
-
},
|
|
135
|
-
],
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Send a message to Loki
|
|
141
|
-
*
|
|
142
|
-
* @param config
|
|
143
|
-
* @param lokiMessage
|
|
144
|
-
*/
|
|
145
|
-
async function sendToLoki(config: LokiConfig, lokiMessage: LokiMessage) {
|
|
146
|
-
try {
|
|
147
|
-
await fetch(
|
|
148
|
-
`https://${config.lokiUser}:${config.lokiToken}@${config.lokiHost}/loki/api/v1/push`,
|
|
149
|
-
{
|
|
150
|
-
method: "POST",
|
|
151
|
-
headers: {
|
|
152
|
-
"Content-Type": "application/json",
|
|
153
|
-
},
|
|
154
|
-
body: JSON.stringify(lokiMessage),
|
|
155
|
-
},
|
|
156
|
-
);
|
|
157
|
-
} catch (e) {
|
|
158
|
-
console.log("Send message to Loki was failed. : {}", e);
|
|
159
|
-
}
|
|
160
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "es2016",
|
|
4
|
-
"module": "commonjs",
|
|
5
|
-
"sourceMap": true,
|
|
6
|
-
"esModuleInterop": true,
|
|
7
|
-
"forceConsistentCasingInFileNames": true,
|
|
8
|
-
"declaration": true,
|
|
9
|
-
"outDir": "./dist",
|
|
10
|
-
"strict": true,
|
|
11
|
-
"skipLibCheck": true
|
|
12
|
-
},
|
|
13
|
-
"include": ["src/**/*.ts"]
|
|
14
|
-
}
|