chore: Basic logging met loki
This commit is contained in:
		
							parent
							
								
									c07bb959cf
								
							
						
					
					
						commit
						0f8bd3df6a
					
				
					 5 changed files with 133 additions and 23 deletions
				
			
		|  | @ -19,4 +19,31 @@ async function startServer() { | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| startServer(); | 
 | ||||||
|  | import { LokiClient, LogError, LokiLabels, LogInfo } from 'loki-logger-ts'; | ||||||
|  | 
 | ||||||
|  | const HostData = { | ||||||
|  |     url: "http://localhost:3100/loki/api/v1/push", | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | const labels: LokiLabels = { | ||||||
|  |     source: "Test", | ||||||
|  |     job: "TestJob", | ||||||
|  |     host: "localhost", | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | async function main() { | ||||||
|  |     const client = new LokiClient(HostData.url); | ||||||
|  | 
 | ||||||
|  |     const msg = 'Hello World'; | ||||||
|  |     await LogError(client, msg, labels); | ||||||
|  |     await LogInfo(client, 'Dit is een goed bericht', labels); | ||||||
|  | 
 | ||||||
|  |     console.log(client.showMetrics()); | ||||||
|  | 
 | ||||||
|  |     console.log(client.getMetrics()); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | main(); | ||||||
|  | 
 | ||||||
|  | // startServer();
 | ||||||
|  |  | ||||||
							
								
								
									
										30
									
								
								config/loki-config.yml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								config/loki-config.yml
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,30 @@ | ||||||
|  | 
 | ||||||
|  | # This is a complete configuration to deploy Loki backed by the filesystem. | ||||||
|  | # The index will be shipped to the storage via tsdb-shipper. | ||||||
|  | 
 | ||||||
|  | auth_enabled: false | ||||||
|  | 
 | ||||||
|  | server: | ||||||
|  |     http_listen_port: 3100 | ||||||
|  | 
 | ||||||
|  | common: | ||||||
|  |     ring: | ||||||
|  |         instance_addr: 127.0.0.1 | ||||||
|  |         kvstore: | ||||||
|  |             store: inmemory | ||||||
|  |     replication_factor: 1 | ||||||
|  |     path_prefix: /tmp/loki | ||||||
|  | 
 | ||||||
|  | schema_config: | ||||||
|  |     configs: | ||||||
|  |         - from: 2020-05-15 | ||||||
|  |           store: tsdb | ||||||
|  |           object_store: filesystem | ||||||
|  |           schema: v13 | ||||||
|  |           index: | ||||||
|  |               prefix: index_ | ||||||
|  |               period: 24h | ||||||
|  | 
 | ||||||
|  | storage_config: | ||||||
|  |     filesystem: | ||||||
|  |         directory: /tmp/loki/chunks | ||||||
|  | @ -1,16 +1,26 @@ | ||||||
| services: | services: | ||||||
|   db: |     db: | ||||||
|     image: postgres:latest |         image: postgres:latest | ||||||
|     environment: |         environment: | ||||||
|       POSTGRES_USER: postgres |             POSTGRES_USER: postgres | ||||||
|       POSTGRES_PASSWORD: postgres |             POSTGRES_PASSWORD: postgres | ||||||
|       POSTGRES_DB: postgres |             POSTGRES_DB: postgres | ||||||
|     ports: |         ports: | ||||||
|       - "5432:5432" |             - '5432:5432' | ||||||
|     network_mode: "host" |         network_mode: 'host' | ||||||
|     volumes: |         volumes: | ||||||
|         - postgres_data:/var/lib/postgresql/data |             - dwengo_postgres_data:/var/lib/postgresql/data | ||||||
|         - ./backend/config/db/init.sql:/docker-entrypoint-initdb.d/init.sql |             - ./backend/config/db/init.sql:/docker-entrypoint-initdb.d/init.sql | ||||||
|  | 
 | ||||||
|  |     logging: | ||||||
|  |         image: grafana/loki:latest | ||||||
|  |         ports: | ||||||
|  |             - '3100:3100' | ||||||
|  |             - '9095:9095' | ||||||
|  |         network_mode: 'host' | ||||||
|  |         volumes: | ||||||
|  |             - ./config/loki-config.yml:/etc/loki/config.yaml | ||||||
|  |         command: -config.file=/etc/loki/config.yaml | ||||||
| 
 | 
 | ||||||
| volumes: | volumes: | ||||||
|     postgres_data: |     dwengo_postgres_data: | ||||||
|  |  | ||||||
							
								
								
									
										58
									
								
								package-lock.json
									
										
									
										generated
									
									
									
								
							
							
						
						
									
										58
									
								
								package-lock.json
									
										
									
										generated
									
									
									
								
							|  | @ -7,10 +7,14 @@ | ||||||
|         "": { |         "": { | ||||||
|             "name": "dwengo-1-monorepo", |             "name": "dwengo-1-monorepo", | ||||||
|             "version": "0.0.1", |             "version": "0.0.1", | ||||||
|  |             "license": "MIT", | ||||||
|             "workspaces": [ |             "workspaces": [ | ||||||
|                 "backend", |                 "backend", | ||||||
|                 "frontend" |                 "frontend" | ||||||
|             ], |             ], | ||||||
|  |             "dependencies": { | ||||||
|  |                 "loki-logger-ts": "^1.0.2" | ||||||
|  |             }, | ||||||
|             "devDependencies": { |             "devDependencies": { | ||||||
|                 "@eslint/compat": "^1.2.6", |                 "@eslint/compat": "^1.2.6", | ||||||
|                 "@eslint/js": "^9.20.0", |                 "@eslint/js": "^9.20.0", | ||||||
|  | @ -26,7 +30,6 @@ | ||||||
|         "backend": { |         "backend": { | ||||||
|             "name": "dwengo-1-backend", |             "name": "dwengo-1-backend", | ||||||
|             "version": "0.0.1", |             "version": "0.0.1", | ||||||
|             "license": "MIT", |  | ||||||
|             "dependencies": { |             "dependencies": { | ||||||
|                 "@mikro-orm/core": "^6.4.6", |                 "@mikro-orm/core": "^6.4.6", | ||||||
|                 "@mikro-orm/postgresql": "^6.4.6", |                 "@mikro-orm/postgresql": "^6.4.6", | ||||||
|  | @ -3142,9 +3145,19 @@ | ||||||
|             "version": "0.4.0", |             "version": "0.4.0", | ||||||
|             "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", |             "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", | ||||||
|             "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", |             "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", | ||||||
|             "dev": true, |  | ||||||
|             "license": "MIT" |             "license": "MIT" | ||||||
|         }, |         }, | ||||||
|  |         "node_modules/axios": { | ||||||
|  |             "version": "1.7.9", | ||||||
|  |             "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.9.tgz", | ||||||
|  |             "integrity": "sha512-LhLcE7Hbiryz8oMDdDptSrWowmB4Bl6RCt6sIJKpRB4XtVf0iEgewX3au/pJqm+Py1kCASkb/FFKjxQaLtxJvw==", | ||||||
|  |             "license": "MIT", | ||||||
|  |             "dependencies": { | ||||||
|  |                 "follow-redirects": "^1.15.6", | ||||||
|  |                 "form-data": "^4.0.0", | ||||||
|  |                 "proxy-from-env": "^1.1.0" | ||||||
|  |             } | ||||||
|  |         }, | ||||||
|         "node_modules/balanced-match": { |         "node_modules/balanced-match": { | ||||||
|             "version": "1.0.2", |             "version": "1.0.2", | ||||||
|             "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", |             "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", | ||||||
|  | @ -3510,7 +3523,6 @@ | ||||||
|             "version": "1.0.8", |             "version": "1.0.8", | ||||||
|             "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", |             "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", | ||||||
|             "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", |             "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", | ||||||
|             "dev": true, |  | ||||||
|             "license": "MIT", |             "license": "MIT", | ||||||
|             "dependencies": { |             "dependencies": { | ||||||
|                 "delayed-stream": "~1.0.0" |                 "delayed-stream": "~1.0.0" | ||||||
|  | @ -3778,7 +3790,6 @@ | ||||||
|             "version": "1.0.0", |             "version": "1.0.0", | ||||||
|             "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", |             "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", | ||||||
|             "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", |             "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", | ||||||
|             "dev": true, |  | ||||||
|             "license": "MIT", |             "license": "MIT", | ||||||
|             "engines": { |             "engines": { | ||||||
|                 "node": ">=0.4.0" |                 "node": ">=0.4.0" | ||||||
|  | @ -3993,7 +4004,6 @@ | ||||||
|             "version": "2.1.0", |             "version": "2.1.0", | ||||||
|             "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz", |             "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz", | ||||||
|             "integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==", |             "integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==", | ||||||
|             "dev": true, |  | ||||||
|             "license": "MIT", |             "license": "MIT", | ||||||
|             "dependencies": { |             "dependencies": { | ||||||
|                 "es-errors": "^1.3.0", |                 "es-errors": "^1.3.0", | ||||||
|  | @ -4735,6 +4745,26 @@ | ||||||
|             "dev": true, |             "dev": true, | ||||||
|             "license": "ISC" |             "license": "ISC" | ||||||
|         }, |         }, | ||||||
|  |         "node_modules/follow-redirects": { | ||||||
|  |             "version": "1.15.9", | ||||||
|  |             "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz", | ||||||
|  |             "integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==", | ||||||
|  |             "funding": [ | ||||||
|  |                 { | ||||||
|  |                     "type": "individual", | ||||||
|  |                     "url": "https://github.com/sponsors/RubenVerborgh" | ||||||
|  |                 } | ||||||
|  |             ], | ||||||
|  |             "license": "MIT", | ||||||
|  |             "engines": { | ||||||
|  |                 "node": ">=4.0" | ||||||
|  |             }, | ||||||
|  |             "peerDependenciesMeta": { | ||||||
|  |                 "debug": { | ||||||
|  |                     "optional": true | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         }, | ||||||
|         "node_modules/foreground-child": { |         "node_modules/foreground-child": { | ||||||
|             "version": "3.3.0", |             "version": "3.3.0", | ||||||
|             "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.3.0.tgz", |             "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.3.0.tgz", | ||||||
|  | @ -4756,7 +4786,6 @@ | ||||||
|             "version": "4.0.2", |             "version": "4.0.2", | ||||||
|             "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.2.tgz", |             "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.2.tgz", | ||||||
|             "integrity": "sha512-hGfm/slu0ZabnNt4oaRZ6uREyfCj6P4fT/n6A1rGV+Z0VdGXjfOhVUpkn6qVQONHGIFwmveGXyDs75+nr6FM8w==", |             "integrity": "sha512-hGfm/slu0ZabnNt4oaRZ6uREyfCj6P4fT/n6A1rGV+Z0VdGXjfOhVUpkn6qVQONHGIFwmveGXyDs75+nr6FM8w==", | ||||||
|             "dev": true, |  | ||||||
|             "license": "MIT", |             "license": "MIT", | ||||||
|             "dependencies": { |             "dependencies": { | ||||||
|                 "asynckit": "^0.4.0", |                 "asynckit": "^0.4.0", | ||||||
|  | @ -4772,7 +4801,6 @@ | ||||||
|             "version": "1.52.0", |             "version": "1.52.0", | ||||||
|             "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", |             "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", | ||||||
|             "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", |             "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", | ||||||
|             "dev": true, |  | ||||||
|             "license": "MIT", |             "license": "MIT", | ||||||
|             "engines": { |             "engines": { | ||||||
|                 "node": ">= 0.6" |                 "node": ">= 0.6" | ||||||
|  | @ -4782,7 +4810,6 @@ | ||||||
|             "version": "2.1.35", |             "version": "2.1.35", | ||||||
|             "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", |             "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", | ||||||
|             "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", |             "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", | ||||||
|             "dev": true, |  | ||||||
|             "license": "MIT", |             "license": "MIT", | ||||||
|             "dependencies": { |             "dependencies": { | ||||||
|                 "mime-db": "1.52.0" |                 "mime-db": "1.52.0" | ||||||
|  | @ -5067,7 +5094,6 @@ | ||||||
|             "version": "1.0.2", |             "version": "1.0.2", | ||||||
|             "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", |             "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", | ||||||
|             "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", |             "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", | ||||||
|             "dev": true, |  | ||||||
|             "license": "MIT", |             "license": "MIT", | ||||||
|             "dependencies": { |             "dependencies": { | ||||||
|                 "has-symbols": "^1.0.3" |                 "has-symbols": "^1.0.3" | ||||||
|  | @ -5786,6 +5812,14 @@ | ||||||
|             "dev": true, |             "dev": true, | ||||||
|             "license": "MIT" |             "license": "MIT" | ||||||
|         }, |         }, | ||||||
|  |         "node_modules/loki-logger-ts": { | ||||||
|  |             "version": "1.0.2", | ||||||
|  |             "resolved": "https://registry.npmjs.org/loki-logger-ts/-/loki-logger-ts-1.0.2.tgz", | ||||||
|  |             "integrity": "sha512-SV/B5o+9jaxiThcU5N3LUxCNTx20IgR9xjCjx/ED/pVc/097mqKSRpmvSjvx9ezFcjJlUF7GBkrBBpR6veNp7Q==", | ||||||
|  |             "dependencies": { | ||||||
|  |                 "axios": "^1.4.0" | ||||||
|  |             } | ||||||
|  |         }, | ||||||
|         "node_modules/loupe": { |         "node_modules/loupe": { | ||||||
|             "version": "3.1.3", |             "version": "3.1.3", | ||||||
|             "resolved": "https://registry.npmjs.org/loupe/-/loupe-3.1.3.tgz", |             "resolved": "https://registry.npmjs.org/loupe/-/loupe-3.1.3.tgz", | ||||||
|  | @ -6763,6 +6797,12 @@ | ||||||
|                 "node": ">= 0.10" |                 "node": ">= 0.10" | ||||||
|             } |             } | ||||||
|         }, |         }, | ||||||
|  |         "node_modules/proxy-from-env": { | ||||||
|  |             "version": "1.1.0", | ||||||
|  |             "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", | ||||||
|  |             "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", | ||||||
|  |             "license": "MIT" | ||||||
|  |         }, | ||||||
|         "node_modules/punycode": { |         "node_modules/punycode": { | ||||||
|             "version": "2.3.1", |             "version": "2.3.1", | ||||||
|             "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", |             "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", | ||||||
|  |  | ||||||
|  | @ -34,5 +34,8 @@ | ||||||
|         "eslint-config-prettier": "^10.0.1", |         "eslint-config-prettier": "^10.0.1", | ||||||
|         "jiti": "^2.4.2", |         "jiti": "^2.4.2", | ||||||
|         "typescript-eslint": "^8.24.1" |         "typescript-eslint": "^8.24.1" | ||||||
|  |     }, | ||||||
|  |     "dependencies": { | ||||||
|  |         "loki-logger-ts": "^1.0.2" | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
		Reference in a new issue