@miketako3/cloki 0.1.1 → 0.1.3
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/README.md +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -1
- package/package.json +5 -2
- package/biome.json +0 -15
- package/dist/hello.d.ts +0 -1
- package/dist/hello.js +0 -8
- package/dist/hello.js.map +0 -1
- package/src/index.ts +0 -1
- package/src/logger.ts +0 -160
- package/tsconfig.json +0 -14
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Cloki - Simple Logging from Cloudflare Workers to Grafana Cloud's Loki
|
|
2
2
|
|
|
3
|
+
[](https://badge.fury.io/js/@miketako3%2Fcloki)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
3
5
|
## Introduction
|
|
4
6
|
|
|
5
7
|
Welcome to **Cloki**, an open-source logger designed to bridge Cloudflare Workers with Grafana Cloud's Loki seamlessly and efficiently. Targeted at individual developers, Cloki aims to reduce maintenance costs while offering a straightforward logging solution. With minimal configuration and the sole use of the fetch API, Cloki is an easy-to-implement tool for effective logging.
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from "./logger";
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./logger"), exports);
|
|
3
18
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAwB"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@miketako3/cloki",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "cloki is logger library for Loki and Cloudflare Workers.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
6
9
|
"publishConfig": {
|
|
7
10
|
"access": "public"
|
|
8
11
|
},
|
|
@@ -10,7 +13,7 @@
|
|
|
10
13
|
"build": "tsc",
|
|
11
14
|
"format": "npx @biomejs/biome format . --write",
|
|
12
15
|
"lint": "npx @biomejs/biome lint .",
|
|
13
|
-
"test": "echo \"Error: no test specified\"
|
|
16
|
+
"test": "echo \"Error: no test specified\""
|
|
14
17
|
},
|
|
15
18
|
"repository": {
|
|
16
19
|
"type": "git",
|
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/dist/hello.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const hello: () => void;
|
package/dist/hello.js
DELETED
package/dist/hello.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hello.js","sourceRoot":"","sources":["../src/hello.ts"],"names":[],"mappings":";;;AAAO,MAAM,KAAK,GAAG,GAAG,EAAE;IACxB,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;AACtB,CAAC,CAAA;AAFY,QAAA,KAAK,SAEjB"}
|
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
|
-
}
|