Compare commits
No commits in common. "master" and "v2.0.15" have entirely different histories.
17
.gitignore
vendored
17
.gitignore
vendored
@ -1,20 +1,5 @@
|
||||
.nogit/
|
||||
|
||||
# artifacts
|
||||
node_modules/
|
||||
coverage/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
# custom
|
150
.gitlab-ci.yml
Normal file
150
.gitlab-ci.yml
Normal file
@ -0,0 +1,150 @@
|
||||
# gitzone standard
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: "$CI_BUILD_STAGE"
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
snyk:
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install -g snyk
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command snyk test
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
sast:
|
||||
stage: security
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-dbase:npmci
|
||||
variables:
|
||||
DOCKER_DRIVER: overlay2
|
||||
allow_failure: true
|
||||
services:
|
||||
- docker:stable-dind
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||
- docker run
|
||||
--env SAST_CONFIDENCE_LEVEL="${SAST_CONFIDENCE_LEVEL:-3}"
|
||||
--volume "$PWD:/code"
|
||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
||||
"registry.gitlab.com/gitlab-org/security-products/sast:$SP_VERSION" /app/bin/run /code
|
||||
artifacts:
|
||||
reports:
|
||||
sast: gl-sast-report.json
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testLTS:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
testSTABLE:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
image: docker:stable
|
||||
allow_failure: true
|
||||
services:
|
||||
- docker:stable-dind
|
||||
script:
|
||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||
- docker run
|
||||
--env SOURCE_CODE="$PWD"
|
||||
--volume "$PWD":/code
|
||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
||||
artifacts:
|
||||
paths: [codeclimate.json]
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command npm install -g typedoc typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
allow_failure: true
|
11
.vscode/launch.json
vendored
11
.vscode/launch.json
vendored
@ -1,11 +0,0 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"request": "launch",
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
26
.vscode/settings.json
vendored
26
.vscode/settings.json
vendored
@ -1,26 +0,0 @@
|
||||
{
|
||||
"json.schemas": [
|
||||
{
|
||||
"fileMatch": ["/npmextra.json"],
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"npmci": {
|
||||
"type": "object",
|
||||
"description": "settings for npmci"
|
||||
},
|
||||
"gitzone": {
|
||||
"type": "object",
|
||||
"description": "settings for gitzone",
|
||||
"properties": {
|
||||
"projectType": {
|
||||
"type": "string",
|
||||
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
19
license
19
license
@ -1,19 +0,0 @@
|
||||
Copyright (c) 2018 Lossless GmbH (hello@lossless.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
@ -1,37 +1,17 @@
|
||||
{
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "code.foss.global",
|
||||
"gitscope": "push.rocks",
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"gitrepo": "smartlog",
|
||||
"description": "A minimalistic, distributed, and extensible logging tool supporting centralized log management.",
|
||||
"npmPackagename": "@push.rocks/smartlog",
|
||||
"shortDescription": "minimalistic distributed and extensible logging tool",
|
||||
"npmPackagename": "@pushrocks/smartlog",
|
||||
"license": "MIT",
|
||||
"projectDomain": "push.rocks",
|
||||
"keywords": [
|
||||
"logging",
|
||||
"log management",
|
||||
"typescript",
|
||||
"centralized logging",
|
||||
"json logging",
|
||||
"node.js",
|
||||
"distributed systems",
|
||||
"extensible logging",
|
||||
"log routing",
|
||||
"console logging",
|
||||
"log destinations",
|
||||
"log levels",
|
||||
"error tracking",
|
||||
"development tools"
|
||||
]
|
||||
"projectDomain": "push.rocks"
|
||||
}
|
||||
},
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"tsdoc": {
|
||||
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
1590
package-lock.json
generated
Normal file
1590
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
70
package.json
70
package.json
@ -1,65 +1,27 @@
|
||||
{
|
||||
"name": "@push.rocks/smartlog",
|
||||
"version": "3.0.7",
|
||||
"name": "@pushrocks/smartlog",
|
||||
"version": "2.0.15",
|
||||
"private": false,
|
||||
"description": "A minimalistic, distributed, and extensible logging tool supporting centralized log management.",
|
||||
"keywords": [
|
||||
"logging",
|
||||
"log management",
|
||||
"typescript",
|
||||
"centralized logging",
|
||||
"json logging",
|
||||
"node.js",
|
||||
"distributed systems",
|
||||
"extensible logging",
|
||||
"log routing",
|
||||
"console logging",
|
||||
"log destinations",
|
||||
"log levels",
|
||||
"error tracking",
|
||||
"development tools"
|
||||
],
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"description": "winston based logger for large scale projects",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"license": "UNLICENSED",
|
||||
"scripts": {
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild --web && tsbundle npm)",
|
||||
"format": "(gitzone format)",
|
||||
"buildDocs": "tsdoc"
|
||||
"build": "(tsbuild)",
|
||||
"format": "(gitzone format)"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@git.zone/tsbuild": "^2.1.66",
|
||||
"@git.zone/tsbundle": "^2.0.8",
|
||||
"@git.zone/tsrun": "^1.2.44",
|
||||
"@git.zone/tstest": "^1.0.77",
|
||||
"@push.rocks/tapbundle": "^5.0.23",
|
||||
"@types/node": "^20.14.2"
|
||||
"@gitzone/tsbuild": "^2.1.4",
|
||||
"@gitzone/tsrun": "^1.1.17",
|
||||
"@gitzone/tstest": "^1.0.18",
|
||||
"@pushrocks/tapbundle": "^3.0.7",
|
||||
"@types/node": "^10.12.18",
|
||||
"tslint": "^5.12.1",
|
||||
"tslint-config-prettier": "^1.17.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@push.rocks/isounique": "^1.0.4",
|
||||
"@push.rocks/smartlog-interfaces": "^3.0.2"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
"dist/**/*",
|
||||
"dist_*/**/*",
|
||||
"dist_ts/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
],
|
||||
"type": "module",
|
||||
"homepage": "https://code.foss.global/push.rocks/smartlog",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://code.foss.global/push.rocks/smartlog.git"
|
||||
"@pushrocks/smartlog-interfaces": "^2.0.5"
|
||||
}
|
||||
}
|
||||
|
6654
pnpm-lock.yaml
generated
6654
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -1 +0,0 @@
|
||||
|
141
readme.md
141
readme.md
@ -1,120 +1,77 @@
|
||||
# @push.rocks/smartlog
|
||||
|
||||
# smartlog
|
||||
minimalistic distributed and extensible logging tool
|
||||
|
||||
## Install
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartlog)
|
||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartlog)
|
||||
* [github.com (source mirror)](https://github.com/pushrocks/smartlog)
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartlog/)
|
||||
|
||||
You can install `@push.rocks/smartlog` using npm:
|
||||
|
||||
```sh
|
||||
npm install @push.rocks/smartlog --save
|
||||
```
|
||||
|
||||
Ensure that you have TypeScript and node.js installed in your development environment, as this module is intended to be used with TypeScript.
|
||||
## Status for master
|
||||
[](https://gitlab.com/pushrocks/smartlog/commits/master)
|
||||
[](https://gitlab.com/pushrocks/smartlog/commits/master)
|
||||
[](https://www.npmjs.com/package/@pushrocks/smartlog)
|
||||
[](https://snyk.io/test/npm/@pushrocks/smartlog)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](http://standardjs.com/)
|
||||
|
||||
## Usage
|
||||
|
||||
`@push.rocks/smartlog` is a flexible and extensible logging tool designed to provide a minimalistic yet powerful logging solution across different environments, making it especially useful in distributed systems. This documentation aims to guide you through its capabilities, setup, and how to integrate it seamlessly into your TypeScript projects.
|
||||
Use TypeScript for best in class instellisense.
|
||||
|
||||
### Creating a Logger Instance
|
||||
|
||||
Start by importing `Smartlog` and create a logger instance by providing a context that describes your logging environment:
|
||||
|
||||
```typescript
|
||||
import { Smartlog } from '@push.rocks/smartlog';
|
||||
smartlog id s minimal logging package that provides a consistent experience across the complete logging stack. Smartlog allows you to create a logger instance like this:
|
||||
|
||||
```ts
|
||||
import { Smartlog } from '@pushrocks/smartlog';
|
||||
const logger = new Smartlog({
|
||||
logContext: {
|
||||
company: 'My awesome company',
|
||||
companyunit: 'my awesome cloud team',
|
||||
containerName: 'awesome-container',
|
||||
environment: 'kubernetes-production',
|
||||
{
|
||||
company?: 'My awesome company',
|
||||
companyunit?: 'my awesome cloud team',
|
||||
containerName?: 'awesome-container',
|
||||
environment: TEnvironment: 'kubernetes-production',
|
||||
runtime: 'node',
|
||||
zone: 'zone x'
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
logger.log('silly', `a silly statement`); // log levels are shown to you by the IDE
|
||||
```
|
||||
|
||||
This context enriches your logs with valuable information, making them easier to filter and analyze in a distributed system.
|
||||
There is also a default logger available that you can use:
|
||||
|
||||
### Logging Messages
|
||||
```ts
|
||||
import { Smartlog, defaultLogger } from '@pushrocks/smartlog';
|
||||
|
||||
Logging is straightforward; you can log messages at various levels such as `info`, `warn`, `error`, `silly`, etc.:
|
||||
|
||||
```typescript
|
||||
logger.log('info', 'This is an info message');
|
||||
logger.log('error', 'This is an error message with details', { errorCode: 123 });
|
||||
```
|
||||
|
||||
The logging method accepts additional data as the third parameter, allowing you to attach more context to each log message, which is immensely useful for debugging.
|
||||
|
||||
### Using the Default Logger
|
||||
|
||||
For convenience, `@push.rocks/smartlog` provides a default logger that you can use out of the box:
|
||||
|
||||
```typescript
|
||||
import { defaultLogger } from '@push.rocks/smartlog';
|
||||
|
||||
defaultLogger.log('warn', 'This is a warning message using the default logger');
|
||||
```
|
||||
|
||||
This is particularly helpful for simple applications or for initial project setup.
|
||||
|
||||
### Extending With Log Destinations
|
||||
|
||||
One of the core strengths of `@push.rocks/smartlog` is its ability to work with multiple log destinations, enabling you to log messages not just to the console but also to external logging services or custom destinations.
|
||||
|
||||
To add a log destination, you create a class that implements the `ILogDestination` interface and then add it to the logger:
|
||||
|
||||
```typescript
|
||||
import { Smartlog, ILogDestination } from '@push.rocks/smartlog';
|
||||
|
||||
class MyCustomLogDestination implements ILogDestination {
|
||||
async handleLog(logPackage) {
|
||||
// Implement your custom logging logic here
|
||||
console.log(`Custom log: ${logPackage.message}`);
|
||||
export class MyAwesomeClass {
|
||||
constructor(public logger: Smartlog = defaultLogger) {
|
||||
// what happens here that a instance of this class will have instance.logger available
|
||||
// if you set a custom logger, than that will be used, if not the default logger.
|
||||
}
|
||||
}
|
||||
|
||||
const logger = new Smartlog({ logContext: { /* your context */ } });
|
||||
logger.addLogDestination(new MyCustomLogDestination());
|
||||
```
|
||||
|
||||
After adding your custom log destination(s), every log message sent through `Smartlog` will also be routed to them according to their implementation.
|
||||
### Destinations
|
||||
|
||||
### Integration with Logging Services
|
||||
smartlog supports different kinds of destinations.
|
||||
|
||||
`@push.rocks/smartlog` is designed to be extensible; you can integrate it with various logging services like Scalyr, Elasticsearch, LogDNA, etc., by developing or using existing log destinations conforming to those services.
|
||||
The following destinations are available:
|
||||
|
||||
Check the npm registry or GitHub for community-contributed log destinations that can seamlessly integrate `@push.rocks/smartlog` into your preferred logging infrastructure.
|
||||
- [@pushrocks/smartlog-destination-local](https://www.npmjs.com/package/@pushrocks/smartlog-destination-local) - outputs logs to the local console in a colorful, nice to read way.
|
||||
- [@pushrocks/smartlog-destination-devtools](https://www.npmjs.com/package/@pushrocks/smartlog-destination-devtools) - outputs logs into the browser console in a colorful, nice to read way.
|
||||
- [@pushrocks/smartlog-destination-receiver](https://www.npmjs.com/package/@pushrocks/smartlog-destination-receiver) - sends logs to a smartlog receiver (more about that below)
|
||||
- [@mojoio/scalyr](https://www.npmjs.com/package/@pushrocks/smartlog-destination-receiver) - an scalyr API package that comes with a smartlog log destination included
|
||||
- [@mojoio/elasticsearch](https://www.npmjs.com/package/@mojoio/elasticsearch) - an elasticsearch API package that comes with a smartlog destination included
|
||||
|
||||
### Advanced Usage
|
||||
### Adding a log destination
|
||||
|
||||
- **Log Groups**: You can use log groups to associate related log messages, which is especially handy for tracking logs across distributed systems.
|
||||
- **Custom Log Levels**: Beyond the standard log levels, you can define custom log levels that suit your project needs.
|
||||
- **Dynamic Log Contexts**: The log context can be dynamically adjusted to reflect different stages or aspects of your application logic.
|
||||
```
|
||||
// TBD
|
||||
```
|
||||
|
||||
### Conclusion
|
||||
For further information read the linked docs at the top of this readme.
|
||||
|
||||
`@push.rocks/smartlog` empowers you to implement a robust logging solution tailored to your needs with minimal effort. Its design promotes clarity, flexibility, and integration ease, making it an excellent choice for projects of any scale.
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||
|
||||
Remember to refer to the official documentation and the type definitions for detailed information on all available methods and configurations. Happy logging!
|
||||
|
||||
## License and Legal Information
|
||||
|
||||
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
||||
|
||||
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||
|
||||
### Trademarks
|
||||
|
||||
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
|
||||
|
||||
### Company Information
|
||||
|
||||
Task Venture Capital GmbH
|
||||
Registered at District court Bremen HRB 35230 HB, Germany
|
||||
|
||||
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
||||
|
||||
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
||||
[](https://push.rocks)
|
||||
|
@ -1,48 +0,0 @@
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import * as smartlog from '../ts/index.js';
|
||||
|
||||
let testConsoleLog: smartlog.ConsoleLog;
|
||||
let testSmartLog: smartlog.Smartlog;
|
||||
|
||||
tap.test('should produce a valid ConsoleLog instance', async () => {
|
||||
testConsoleLog = new smartlog.ConsoleLog();
|
||||
testConsoleLog.log('ok', 'this is ok');
|
||||
});
|
||||
|
||||
tap.test('should produce instance of Smartlog', async () => {
|
||||
testSmartLog = new smartlog.Smartlog({
|
||||
logContext: {
|
||||
environment: 'test',
|
||||
runtime: 'node',
|
||||
zone: 'gitzone',
|
||||
company: 'Lossless GmbH',
|
||||
companyunit: 'Lossless Cloud',
|
||||
containerName: 'testing',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('should enable console logging', async () => {
|
||||
testSmartLog.enableConsole({
|
||||
captureAll: true,
|
||||
});
|
||||
console.log('this is a normal log that should be captured');
|
||||
console.log(new Error('hi there'));
|
||||
testSmartLog.log('info', 'this should only be printed once');
|
||||
});
|
||||
|
||||
tap.test('should be able to log things', async () => {
|
||||
testSmartLog.log('silly', 'hi');
|
||||
});
|
||||
|
||||
tap.test('should create a log group', async () => {
|
||||
const logGroup = testSmartLog.createLogGroup('some cool transaction');
|
||||
logGroup.log('info', 'this is logged from a log group');
|
||||
});
|
||||
|
||||
tap.test('should catch error', async () => {
|
||||
console.error(new Error('hey'));
|
||||
// throw new Error('hey');
|
||||
});
|
||||
|
||||
export default tap.start();
|
45
test/test.ts
45
test/test.ts
@ -1,48 +1,19 @@
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import * as smartlog from '../ts/index.js';
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import * as smartlog from '../ts/index';
|
||||
|
||||
let testConsoleLog: smartlog.ConsoleLog;
|
||||
let testSmartLog: smartlog.Smartlog;
|
||||
|
||||
tap.test('should produce a valid ConsoleLog instance', async () => {
|
||||
testConsoleLog = new smartlog.ConsoleLog();
|
||||
testConsoleLog.log('ok', 'this is ok');
|
||||
});
|
||||
let defaultLogger: smartlog.Smartlog;
|
||||
|
||||
tap.test('should produce instance of Smartlog', async () => {
|
||||
testSmartLog = new smartlog.Smartlog({
|
||||
logContext: {
|
||||
environment: 'test',
|
||||
runtime: 'node',
|
||||
zone: 'gitzone',
|
||||
company: 'Lossless GmbH',
|
||||
companyunit: 'Lossless Cloud',
|
||||
containerName: 'testing',
|
||||
},
|
||||
});
|
||||
defaultLogger = smartlog.defaultLogger;
|
||||
expect(defaultLogger).to.be.instanceOf(smartlog.Smartlog);
|
||||
});
|
||||
|
||||
tap.test('should enable console logging', async () => {
|
||||
testSmartLog.enableConsole({
|
||||
captureAll: true,
|
||||
});
|
||||
console.log('this is a normal log that should be captured');
|
||||
console.log(new Error('hi there'));
|
||||
testSmartLog.log('info', 'this should only be printed once');
|
||||
defaultLogger.enableConsole();
|
||||
});
|
||||
|
||||
tap.test('should be able to log things', async () => {
|
||||
testSmartLog.log('silly', 'hi');
|
||||
defaultLogger.log('silly', 'hi');
|
||||
});
|
||||
|
||||
tap.test('should create a log group', async () => {
|
||||
const logGroup = testSmartLog.createLogGroup('some cool transaction');
|
||||
logGroup.log('info', 'this is logged from a log group');
|
||||
});
|
||||
|
||||
tap.test('should catch error', async () => {
|
||||
console.error(new Error('hey'));
|
||||
// throw new Error('hey');
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
tap.start();
|
||||
|
@ -1,8 +0,0 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartlog',
|
||||
version: '3.0.7',
|
||||
description: 'A minimalistic, distributed, and extensible logging tool supporting centralized log management.'
|
||||
}
|
20
ts/index.ts
20
ts/index.ts
@ -1,6 +1,16 @@
|
||||
import * as plugins from './smartlog.plugins.js';
|
||||
import { ConsoleLog } from './smartlog.classes.consolelog.js';
|
||||
import { LogGroup } from './smartlog.classes.loggroup.js';
|
||||
import { Smartlog } from './smartlog.classes.smartlog.js';
|
||||
import * as plugins from './smartlog.plugins';
|
||||
import { Smartlog } from './smartlog.classes.smartlog';
|
||||
const defaultLogger: Smartlog = new Smartlog({
|
||||
logContext: {
|
||||
company: 'undefined',
|
||||
companyunit: 'undefefined',
|
||||
containerName: 'undefined',
|
||||
environment: 'local',
|
||||
runtime: 'node',
|
||||
zone: 'undefined'
|
||||
}
|
||||
});
|
||||
|
||||
export { ConsoleLog, LogGroup, Smartlog };
|
||||
defaultLogger.enableConsole();
|
||||
|
||||
export { Smartlog, defaultLogger };
|
||||
|
@ -1,15 +0,0 @@
|
||||
import * as plugins from './smartlog.plugins.js';
|
||||
|
||||
/**
|
||||
* a console log optimized for smartlog
|
||||
*/
|
||||
export class ConsoleLog {
|
||||
public log(
|
||||
logLevelArg: plugins.smartlogInterfaces.TLogLevel,
|
||||
logMessageArg: string,
|
||||
dataArg?: any,
|
||||
correlationArg?: plugins.smartlogInterfaces.ILogCorrelation
|
||||
) {
|
||||
console.log(`__# ${logLevelArg}: ${logMessageArg}`);
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
import * as plugins from './smartlog.plugins.js';
|
||||
import { Smartlog } from './smartlog.classes.smartlog.js';
|
||||
|
||||
export class LogGroup {
|
||||
public smartlogRef: Smartlog;
|
||||
public transactionId: string;
|
||||
public groupId = plugins.isounique.uni();
|
||||
|
||||
constructor(smartlogInstance: Smartlog, transactionIdArg: string) {
|
||||
this.smartlogRef = smartlogInstance;
|
||||
this.transactionId = transactionIdArg;
|
||||
}
|
||||
|
||||
public log(
|
||||
logLevelArg: plugins.smartlogInterfaces.TLogLevel,
|
||||
logMessageArg: string,
|
||||
logDataArg?: any
|
||||
) {
|
||||
this.smartlogRef.log(logLevelArg, logMessageArg, logDataArg, {
|
||||
id: plugins.isounique.uni(),
|
||||
type: 'none',
|
||||
group: this.groupId,
|
||||
instance: this.smartlogRef.uniInstanceId,
|
||||
transaction: this.transactionId,
|
||||
});
|
||||
}
|
||||
}
|
@ -1,21 +1,23 @@
|
||||
import * as plugins from './smartlog.plugins.js';
|
||||
import * as plugins from './smartlog.plugins';
|
||||
|
||||
import { ILogDestination, ILogPackage } from '@pushrocks/smartlog-interfaces';
|
||||
|
||||
export class LogRouter {
|
||||
/**
|
||||
* all log destinations
|
||||
*/
|
||||
private logDestinations: plugins.smartlogInterfaces.ILogDestination[] = [];
|
||||
private logDestinations: ILogDestination[] = [];
|
||||
|
||||
constructor() {}
|
||||
|
||||
public addLogDestination(logDestination: plugins.smartlogInterfaces.ILogDestination) {
|
||||
public addLogDestination(logDestination: ILogDestination) {
|
||||
this.logDestinations.push(logDestination);
|
||||
}
|
||||
|
||||
// routes the log according to added logDestinations
|
||||
public async routeLog(logPackageArg: plugins.smartlogInterfaces.ILogPackage) {
|
||||
routeLog(logPackageArg: ILogPackage) {
|
||||
for (const logDestination of this.logDestinations) {
|
||||
await logDestination.handleLog(logPackageArg);
|
||||
logDestination.handleLog(logPackageArg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,40 +1,38 @@
|
||||
import * as plugins from './smartlog.plugins.js';
|
||||
import * as plugins from './smartlog.plugins';
|
||||
|
||||
import { LogRouter } from './smartlog.classes.logrouter.js';
|
||||
import { LogGroup } from './smartlog.classes.loggroup.js';
|
||||
// interfaces
|
||||
import {
|
||||
TLogType,
|
||||
TEnvironment,
|
||||
ILogContext,
|
||||
TLogLevel,
|
||||
TRuntime,
|
||||
ILogDestination,
|
||||
ILogPackage
|
||||
} from '@pushrocks/smartlog-interfaces';
|
||||
|
||||
import { LogRouter } from './smartlog.classes.logrouter';
|
||||
|
||||
export interface ISmartlogContructorOptions {
|
||||
logContext: plugins.smartlogInterfaces.ILogContext;
|
||||
minimumLogLevel?: plugins.smartlogInterfaces.TLogLevel;
|
||||
logContext: ILogContext;
|
||||
minimumLogLevel?: TLogLevel;
|
||||
}
|
||||
|
||||
export class Smartlog implements plugins.smartlogInterfaces.ILogDestination {
|
||||
// STATIC
|
||||
public static createForCommitinfo(commitinfo: plugins.smartlogInterfaces.ILogContext['commitinfo']) {
|
||||
return new Smartlog({
|
||||
logContext: {
|
||||
commitinfo
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// INSTANCE
|
||||
public logContext: plugins.smartlogInterfaces.ILogContext;
|
||||
public minimumLogLevel: plugins.smartlogInterfaces.TLogLevel;
|
||||
|
||||
public uniInstanceId: string = plugins.isounique.uni();
|
||||
export class Smartlog {
|
||||
private logContext: ILogContext;
|
||||
private minimumLogLevel: TLogLevel;
|
||||
|
||||
private consoleEnabled: boolean;
|
||||
|
||||
private logRouter = new LogRouter();
|
||||
|
||||
public addLogDestination(logDestinationArg: plugins.smartlogInterfaces.ILogDestination) {
|
||||
public addLogDestination(logDestinationArg: ILogDestination) {
|
||||
this.logRouter.addLogDestination(logDestinationArg);
|
||||
}
|
||||
|
||||
constructor(optionsArg: ISmartlogContructorOptions) {
|
||||
this.logContext = optionsArg.logContext;
|
||||
this.minimumLogLevel = optionsArg.minimumLogLevel || 'silly';
|
||||
this.minimumLogLevel = optionsArg.minimumLogLevel;
|
||||
}
|
||||
|
||||
// ============
|
||||
@ -44,40 +42,7 @@ export class Smartlog implements plugins.smartlogInterfaces.ILogDestination {
|
||||
/**
|
||||
* enables console logging
|
||||
*/
|
||||
public enableConsole(optionsArg?: { captureAll: boolean }) {
|
||||
if (globalThis.process && optionsArg && optionsArg.captureAll) {
|
||||
const process = globalThis.process;
|
||||
const originalStdoutWrite = process.stdout.write.bind(process.stdout);
|
||||
const originalStderrWrite = process.stderr.write.bind(process.stderr);
|
||||
|
||||
process.stdout.write = (...args: any) => {
|
||||
const logString: string = args[0];
|
||||
if (!logString || typeof logString !== 'string') {
|
||||
// continue as planned
|
||||
return originalStdoutWrite(...args);
|
||||
}
|
||||
|
||||
if (!logString.startsWith('LOG')) {
|
||||
if (logString.includes('Error:')) {
|
||||
this.log('error', logString);
|
||||
} else {
|
||||
this.log('info', logString);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return originalStdoutWrite(...args);
|
||||
};
|
||||
|
||||
process.stderr.write = (...args: any) => {
|
||||
const logString: string = args[0];
|
||||
if (!logString || typeof logString !== 'string' || !logString.startsWith('LOG')) {
|
||||
this.log('error', logString);
|
||||
return true;
|
||||
}
|
||||
return originalStderrWrite(...args);
|
||||
};
|
||||
}
|
||||
enableConsole() {
|
||||
this.consoleEnabled = true;
|
||||
}
|
||||
|
||||
@ -89,74 +54,40 @@ export class Smartlog implements plugins.smartlogInterfaces.ILogDestination {
|
||||
* @param logLevelArg - the log level
|
||||
* @param logMessageArg - the log message
|
||||
* @param logDataArg - any additional log data
|
||||
* @param correlationArg - info about corrleations
|
||||
*/
|
||||
public async log(
|
||||
logLevelArg: plugins.smartlogInterfaces.TLogLevel,
|
||||
logMessageArg: string,
|
||||
logDataArg?: any,
|
||||
correlationArg?: plugins.smartlogInterfaces.ILogCorrelation
|
||||
) {
|
||||
correlationArg = {
|
||||
...{
|
||||
id: plugins.isounique.uni(),
|
||||
type: 'none',
|
||||
instance: this.uniInstanceId,
|
||||
},
|
||||
...correlationArg,
|
||||
};
|
||||
|
||||
public log(logLevelArg: TLogLevel, logMessageArg: string, logDataArg?: any) {
|
||||
if (this.consoleEnabled) {
|
||||
this.safeConsoleLog(`${logLevelArg}: ${logMessageArg}`);
|
||||
console.log(
|
||||
`LOG => ${new Date().getHours()}:${new Date().getMinutes()}:${new Date().getSeconds()} => ${logLevelArg}: ${logMessageArg}`
|
||||
);
|
||||
}
|
||||
|
||||
const logPackage: plugins.smartlogInterfaces.ILogPackage = {
|
||||
const logPackage: ILogPackage = {
|
||||
timestamp: Date.now(),
|
||||
type: 'log',
|
||||
context: this.logContext,
|
||||
level: logLevelArg,
|
||||
correlation: correlationArg,
|
||||
message: logMessageArg,
|
||||
message: logMessageArg
|
||||
};
|
||||
if (logDataArg) {
|
||||
logPackage.data = logDataArg;
|
||||
}
|
||||
await this.logRouter.routeLog(logPackage);
|
||||
this.logRouter.routeLog(logPackage);
|
||||
}
|
||||
|
||||
public increment(
|
||||
logLevelArg: plugins.smartlogInterfaces.TLogLevel,
|
||||
logMessageArg: string,
|
||||
logDataArg?: any,
|
||||
correlationArg: plugins.smartlogInterfaces.ILogCorrelation = {
|
||||
id: plugins.isounique.uni(),
|
||||
type: 'none',
|
||||
}
|
||||
) {
|
||||
public increment(logLevelArg: TLogLevel, logMessageArg) {
|
||||
if (this.consoleEnabled) {
|
||||
this.safeConsoleLog(`INCREMENT: ${logLevelArg}: ${logMessageArg}`);
|
||||
console.log(`INCREMENT: ${logLevelArg}: ${logMessageArg}`);
|
||||
}
|
||||
this.logRouter.routeLog({
|
||||
timestamp: Date.now(),
|
||||
type: 'increment',
|
||||
context: this.logContext,
|
||||
level: logLevelArg,
|
||||
message: logMessageArg,
|
||||
correlation: correlationArg,
|
||||
message: logMessageArg
|
||||
});
|
||||
}
|
||||
|
||||
public async handleLog(logPackageArg: plugins.smartlogInterfaces.ILogPackage) {
|
||||
await this.logRouter.routeLog(logPackageArg);
|
||||
}
|
||||
|
||||
private safeConsoleLog(logLine: string) {
|
||||
console.log(
|
||||
`LOG => ${new Date().getHours()}:${new Date().getMinutes()}:${new Date().getSeconds()} => ${logLine}`
|
||||
);
|
||||
}
|
||||
|
||||
public createLogGroup(transactionId: string = 'none') {
|
||||
return new LogGroup(this, transactionId);
|
||||
public handleLogPackage(logPackageArg: ILogPackage) {
|
||||
this.logRouter.routeLog(logPackageArg);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1 @@
|
||||
import * as isounique from '@push.rocks/isounique';
|
||||
import * as smartlogInterfaces from '@push.rocks/smartlog-interfaces';
|
||||
|
||||
export { isounique, smartlogInterfaces };
|
||||
export {};
|
||||
|
@ -1,14 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true
|
||||
},
|
||||
"exclude": [
|
||||
"dist_*/**/*.d.ts"
|
||||
]
|
||||
}
|
17
tslint.json
Normal file
17
tslint.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||
"rules": {
|
||||
"semicolon": [true, "always"],
|
||||
"no-console": false,
|
||||
"ordered-imports": false,
|
||||
"object-literal-sort-keys": false,
|
||||
"member-ordering": {
|
||||
"options":{
|
||||
"order": [
|
||||
"static-method"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultSeverity": "warning"
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user