Compare commits

..

49 Commits

Author SHA1 Message Date
7ec6579cc3 2.0.20 2019-10-22 15:04:16 +02:00
0c6240ae60 fix(core): update dependencies 2019-10-22 15:04:15 +02:00
5d9fb7c25a 2.0.19 2019-01-30 03:26:31 +01:00
6ee63d1e96 fix(license): update license files 2019-01-30 03:26:31 +01:00
e648a787e5 2.0.18 2019-01-30 03:24:47 +01:00
96bc87ecbd fix(readme): fix typo 2019-01-30 03:24:47 +01:00
de81a174f8 2.0.17 2019-01-30 03:23:57 +01:00
027216914d fix(readme): fix typo 2019-01-30 03:23:56 +01:00
34cc6cbed5 2.0.16 2019-01-28 23:30:56 +01:00
0bcca99349 fix(core): update 2019-01-28 23:30:55 +01:00
dc72beaf61 2.0.15 2019-01-28 02:03:12 +01:00
3b706a3b54 fix(core): update 2019-01-28 02:03:11 +01:00
acde7f2204 2.0.14 2019-01-22 12:49:09 +01:00
890d592072 fix(core): update 2019-01-22 12:49:09 +01:00
31d8aa84ec 2.0.13 2019-01-22 12:44:45 +01:00
3050a63323 fix(core): update 2019-01-22 12:44:45 +01:00
9e294ee357 2.0.12 2019-01-18 01:51:22 +01:00
ba19654a5e fix(core): update 2019-01-18 01:51:21 +01:00
0ac464875a 2.0.11 2019-01-16 00:01:20 +01:00
fa074facbb fix(core): update 2019-01-16 00:01:19 +01:00
ac4d466ab4 2.0.10 2019-01-15 23:22:45 +01:00
a0aa3c1122 fix(core): update 2019-01-15 23:22:44 +01:00
5dff4961fb 2.0.9 2018-11-11 01:40:09 +01:00
3a98c2e7d9 fix(core): update 2018-11-11 01:40:08 +01:00
39d08ef53a 2.0.8 2018-11-04 18:21:18 +01:00
74e6bc7a3c fix(core): update 2018-11-04 18:21:18 +01:00
5d0056558a 2.0.7 2018-11-04 15:26:40 +01:00
2b920e2f5e fix(core): update 2018-11-04 15:26:40 +01:00
793cd38381 2.0.6 2018-11-04 14:19:31 +01:00
7a05e4484d fix(api): streamline api 2018-11-04 14:19:31 +01:00
2fe657f5af 2.0.5 2018-11-04 02:41:18 +01:00
5508beae25 fix(core): update 2018-11-04 02:41:18 +01:00
f2c0f1acff 2.0.4 2018-11-03 23:19:15 +01:00
5805cc51a6 fix(core): update 2018-11-03 23:19:15 +01:00
c9c38368c1 2.0.3 2018-10-31 18:51:54 +01:00
640eddae2d fix(core): update 2018-10-31 18:51:54 +01:00
ade4d86597 2.0.2 2018-10-30 18:56:27 +01:00
d4cc9dbcd0 fix(core): implement log router 2018-10-30 18:56:26 +01:00
cde3686209 2.0.1 2018-07-10 22:36:53 +02:00
485e04c0b3 fix(.enableConsole()): now works 2018-07-10 22:36:53 +02:00
0ee2b8295a 2.0.0 2018-07-10 22:34:33 +02:00
4fd4de20c2 BREAKING CHANGE(core): now has simple defaultLogger 2018-07-10 22:34:33 +02:00
accf03f1b4 1.0.6 2018-07-08 22:30:22 +02:00
8e8e2c7bd6 fix(npm): package distribution 2018-07-08 22:30:21 +02:00
698d5927cc 1.0.5 2018-06-05 20:49:54 +02:00
3d8e2f881b fix(package): update package name 2018-06-05 20:49:54 +02:00
e104d33822 1.0.4 2018-06-05 20:48:14 +02:00
73e04348da fix(core): update to latest standards 2018-06-05 20:48:14 +02:00
3409d48858 system change 2018-03-03 13:57:55 +01:00
19 changed files with 1986 additions and 556 deletions

View File

@ -3,94 +3,148 @@ image: hosttoday/ht-docker-node:npmci
cache: cache:
paths: paths:
- .yarn/ - .npmci_cache/
key: "$CI_BUILD_STAGE" key: "$CI_BUILD_STAGE"
stages: stages:
- mirror
- security - security
- test - test
- release - release
- trigger - metadata
- pages
# ====================
# security stage
# ====================
mirror: mirror:
stage: mirror stage: security
script: script:
- npmci git mirror - npmci git mirror
tags: tags:
- docker - docker
- notpriv
security: snyk:
stage: security stage: security
script: script:
- npmci command yarn global add snyk - npmci npm prepare
- npmci command yarn install --ignore-scripts - npmci command npm install -g snyk
- npmci command npm install --ignore-scripts
- npmci command snyk test - npmci command snyk test
tags: tags:
- docker - docker
- notpriv
testLEGACY: sast:
stage: test stage: security
image: registry.gitlab.com/hosttoday/ht-docker-dbase:npmci
variables:
DOCKER_DRIVER: overlay2
allow_failure: true
services:
- docker:stable-dind
script: script:
- npmci node install legacy - npmci npm prepare
- npmci npm install - npmci npm install
- npmci npm test - npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/ - 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: tags:
- docker - docker
allow_failure: true - priv
# ====================
# test stage
# ====================
testLTS: testLTS:
stage: test stage: test
script: script:
- npmci npm prepare
- npmci node install lts - npmci node install lts
- npmci npm install - npmci npm install
- npmci npm test - npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- notpriv
testSTABLE: testSTABLE:
stage: test stage: test
script: script:
- npmci npm prepare
- npmci node install stable - npmci node install stable
- npmci npm install - npmci npm install
- npmci npm test - npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- notpriv
release: release:
stage: release stage: release
script: script:
- npmci npm prepare - npmci node install stable
- npmci npm publish - npmci npm publish
only: only:
- tags - tags
tags: tags:
- docker - 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: trigger:
stage: trigger stage: metadata
script: script:
- npmci trigger - npmci trigger
only: only:
- tags - tags
tags: tags:
- docker - docker
- notpriv
pages: pages:
image: hosttoday/ht-docker-node:npmci image: hosttoday/ht-docker-node:npmci
stage: pages stage: metadata
script: script:
- npmci command yarn global add npmpage - npmci command npm install -g typedoc typescript
- npmci command npmpage - npmci npm prepare
- npmci npm install
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
tags: tags:
- docker - docker
- notpriv
only: only:
- tags - tags
artifacts: artifacts:
expire_in: 1 week expire_in: 1 week
paths: paths:
- public - public
allow_failure: true

3
dist/index.d.ts vendored
View File

@ -1,3 +0,0 @@
import { Smartlog } from "./smartlog.classes.smartlog";
export { Smartlog };
export declare const getDefaultLogger: () => Smartlog;

12
dist/index.js vendored
View File

@ -1,12 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const smartlog_classes_smartlog_1 = require("./smartlog.classes.smartlog");
exports.Smartlog = smartlog_classes_smartlog_1.Smartlog;
let defaultLogger;
exports.getDefaultLogger = () => {
if (!defaultLogger) {
defaultLogger = new smartlog_classes_smartlog_1.Smartlog();
}
return defaultLogger;
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUNBLDJFQUF1RDtBQUU5QyxtQkFGQSxvQ0FBUSxDQUVBO0FBRWpCLElBQUksYUFBdUIsQ0FBQztBQUVmLFFBQUEsZ0JBQWdCLEdBQUcsR0FBRyxFQUFFO0lBQ25DLEVBQUUsQ0FBQyxDQUFDLENBQUMsYUFBYSxDQUFDLENBQUMsQ0FBQztRQUNuQixhQUFhLEdBQUcsSUFBSSxvQ0FBUSxFQUFFLENBQUM7SUFDakMsQ0FBQztJQUNELE1BQU0sQ0FBQyxhQUFhLENBQUM7QUFDdkIsQ0FBQyxDQUFDIn0=

View File

@ -1,24 +0,0 @@
export declare type TLogLevel = "error" | "warn" | "info" | "verbose" | "debug" | "silly";
export declare class Smartlog {
private winstonInstance;
/**
* enables console logging
*/
enableConsole(): void;
/**
* set a minimum serverity level to log
* @param levelArg
*/
level(levelArg: TLogLevel): void;
/**
* log stuff
* @param logLevelArg
* @param logMessageArg
*/
log(logLevelArg: TLogLevel, logMessageArg: string): void;
silly(logMessageArg: string): void;
debug(logMessageArg: any): void;
info(logMessageArg: string): void;
warn(logMessageArg: any): void;
error(logMessageArg: any): void;
}

View File

@ -1,55 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const plugins = require("./smartlog.plugins");
class Smartlog {
constructor() {
this.winstonInstance = new plugins.winston.createLogger({
level: 'silly',
format: plugins.winston.format.json()
});
}
// ============
// Logger Setup
// ============
/**
* enables console logging
*/
enableConsole() {
this.winstonInstance.add(new plugins.winston.transports.Console());
}
/**
* set a minimum serverity level to log
* @param levelArg
*/
level(levelArg) {
this.winstonInstance.level(levelArg);
}
// =============
// log functions
// =============
/**
* log stuff
* @param logLevelArg
* @param logMessageArg
*/
log(logLevelArg, logMessageArg) {
this.winstonInstance.log(logLevelArg, logMessageArg);
}
silly(logMessageArg) {
this.log('silly', logMessageArg);
}
debug(logMessageArg) {
this.log('debug', logMessageArg);
}
info(logMessageArg) {
this.log('info', logMessageArg);
}
warn(logMessageArg) {
this.log('warn', logMessageArg);
}
error(logMessageArg) {
this.log('error', logMessageArg);
}
}
exports.Smartlog = Smartlog;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRsb2cuY2xhc3Nlcy5zbWFydGxvZy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bG9nLmNsYXNzZXMuc21hcnRsb2cudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSw4Q0FBOEM7QUFVOUM7SUFBQTtRQUNVLG9CQUFlLEdBQUcsSUFBSSxPQUFPLENBQUMsT0FBTyxDQUFDLFlBQVksQ0FBQztZQUN6RCxLQUFLLEVBQUUsT0FBTztZQUNkLE1BQU0sRUFBRSxPQUFPLENBQUMsT0FBTyxDQUFDLE1BQU0sQ0FBQyxJQUFJLEVBQUU7U0FDdEMsQ0FBQyxDQUFBO0lBb0RKLENBQUM7SUFsREMsZUFBZTtJQUNmLGVBQWU7SUFDZixlQUFlO0lBRWY7O09BRUc7SUFDSCxhQUFhO1FBQ1gsSUFBSSxDQUFDLGVBQWUsQ0FBQyxHQUFHLENBQUMsSUFBSSxPQUFPLENBQUMsT0FBTyxDQUFDLFVBQVUsQ0FBQyxPQUFPLEVBQUUsQ0FBQyxDQUFDO0lBQ3JFLENBQUM7SUFFRDs7O09BR0c7SUFDSCxLQUFLLENBQUUsUUFBbUI7UUFDeEIsSUFBSSxDQUFDLGVBQWUsQ0FBQyxLQUFLLENBQUMsUUFBUSxDQUFDLENBQUM7SUFDdkMsQ0FBQztJQUVELGdCQUFnQjtJQUNoQixnQkFBZ0I7SUFDaEIsZ0JBQWdCO0lBQ2hCOzs7O09BSUc7SUFDSCxHQUFHLENBQUMsV0FBc0IsRUFBRSxhQUFxQjtRQUMvQyxJQUFJLENBQUMsZUFBZSxDQUFDLEdBQUcsQ0FBQyxXQUFXLEVBQUUsYUFBYSxDQUFDLENBQUE7SUFDdEQsQ0FBQztJQUVELEtBQUssQ0FBQyxhQUFxQjtRQUN6QixJQUFJLENBQUMsR0FBRyxDQUFDLE9BQU8sRUFBRSxhQUFhLENBQUMsQ0FBQTtJQUNsQyxDQUFDO0lBRUQsS0FBSyxDQUFDLGFBQWE7UUFDakIsSUFBSSxDQUFDLEdBQUcsQ0FBQyxPQUFPLEVBQUUsYUFBYSxDQUFDLENBQUE7SUFDbEMsQ0FBQztJQUVELElBQUksQ0FBQyxhQUFxQjtRQUN4QixJQUFJLENBQUMsR0FBRyxDQUFDLE1BQU0sRUFBRSxhQUFhLENBQUMsQ0FBQTtJQUNqQyxDQUFDO0lBRUQsSUFBSSxDQUFDLGFBQWE7UUFDaEIsSUFBSSxDQUFDLEdBQUcsQ0FBQyxNQUFNLEVBQUUsYUFBYSxDQUFDLENBQUE7SUFDakMsQ0FBQztJQUVELEtBQUssQ0FBQyxhQUFhO1FBQ2pCLElBQUksQ0FBQyxHQUFHLENBQUMsT0FBTyxFQUFFLGFBQWEsQ0FBQyxDQUFBO0lBQ2xDLENBQUM7Q0FDRjtBQXhERCw0QkF3REMifQ==

View File

@ -1,2 +0,0 @@
import * as winston from "winston";
export { winston };

View File

@ -1,5 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const winston = require("winston");
exports.winston = winston;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRsb2cucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bG9nLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSxtQ0FBbUM7QUFDMUIsMEJBQU8ifQ==

19
license Normal file
View File

@ -0,0 +1,19 @@
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.

View File

@ -1,7 +1,17 @@
{ {
"gitzone": {
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"gitrepo": "smartlog",
"shortDescription": "minimalistic distributed and extensible logging tool",
"npmPackagename": "@pushrocks/smartlog",
"license": "MIT",
"projectDomain": "push.rocks"
}
},
"npmci": { "npmci": {
"npmGlobalTools": [ "npmGlobalTools": [],
"npmts" "npmAccessLevel": "public"
]
} }
} }

1701
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,25 +1,35 @@
{ {
"name": "smartlog", "name": "@pushrocks/smartlog",
"version": "1.0.3", "version": "2.0.20",
"description": "winston based logger for large scale projects", "private": false,
"description": "minimalistic distributed and extensible logging tool",
"keywords": [
"logging",
"centralized logging",
"json logging",
"scalyr",
"elasticsearch",
"logdna"
],
"main": "dist/index.js", "main": "dist/index.js",
"typings": "dist/index.d.ts", "typings": "dist/index.d.ts",
"author": "Lossless GmbH", "author": "Lossless GmbH",
"license": "", "license": "MIT",
"scripts": { "scripts": {
"test": "(npmts)", "test": "(tstest test/)",
"build": "(tsbuild)",
"format": "(gitzone format)" "format": "(gitzone format)"
}, },
"devDependencies": { "devDependencies": {
"cz-conventional-changelog": "^2.1.0", "@gitzone/tsbuild": "^2.1.17",
"tapbundle": "^1.0.13" "@gitzone/tsrun": "^1.2.8",
"@gitzone/tstest": "^1.0.28",
"@pushrocks/tapbundle": "^3.0.13",
"@types/node": "^12.11.2",
"tslint": "^5.20.0",
"tslint-config-prettier": "^1.18.0"
}, },
"dependencies": { "dependencies": {
"winston": "^3.0.0-rc1" "@pushrocks/smartlog-interfaces": "^2.0.5"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
} }
} }

View File

@ -1,28 +1,75 @@
# smartlog # @pushrocks/smartlog
winston based logger for large scale projects minimalistic distributed and extensible logging tool
## Availabililty ## Availabililty and Links
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartlog) * [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartlog)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartlog) * [gitlab.com (source)](https://gitlab.com/pushrocks/smartlog)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartlog) * [github.com (source mirror)](https://github.com/pushrocks/smartlog)
[![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartlog/) * [docs (typedoc)](https://pushrocks.gitlab.io/smartlog/)
## Status for master ## Status for master
[![build status](https://GitLab.com/pushrocks/smartlog/badges/master/build.svg)](https://GitLab.com/pushrocks/smartlog/commits/master) [![build status](https://gitlab.com/pushrocks/smartlog/badges/master/build.svg)](https://gitlab.com/pushrocks/smartlog/commits/master)
[![coverage report](https://GitLab.com/pushrocks/smartlog/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smartlog/commits/master) [![coverage report](https://gitlab.com/pushrocks/smartlog/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartlog/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/smartlog.svg)](https://www.npmjs.com/package/smartlog) [![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartlog.svg)](https://www.npmjs.com/package/@pushrocks/smartlog)
[![Dependency Status](https://david-dm.org/pushrocks/smartlog.svg)](https://david-dm.org/pushrocks/smartlog) [![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smartlog/badge.svg)](https://snyk.io/test/npm/@pushrocks/smartlog)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartlog/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartlog/master/dependencies/npm) [![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![bitHound Code](https://www.bithound.io/github/pushrocks/smartlog/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartlog) [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![Known Vulnerabilities](https://snyk.io/test/npm/smartlog/badge.svg)](https://snyk.io/test/npm/smartlog)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) [![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
## Usage ## Usage
Use TypeScript for best in class instellisense. Use TypeScript for best in class instellisense.
For further information read the linked docs at the top of this README. 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({
{
company: 'My awesome company',
companyunit: 'my awesome cloud team',
containerName: 'awesome-container',
environment: 'kubernetes-production',
runtime: 'node',
zone: 'zone x'
}
})
logger.log('silly', `a silly statement`); // log levels are shown to you by the IDE
```
There is also a default logger available that you can use:
```ts
import { Smartlog, defaultLogger } from '@pushrocks/smartlog';
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.
}
}
```
### Destinations
smartlog supports different kinds of destinations.
The following destinations are available:
- [@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
### Adding a log destination
```
// TBD
```
For further information read the linked docs at the top of this readme.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh) > MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html) | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)

View File

@ -1,19 +1,19 @@
import { expect, tap } from "tapbundle"; import { expect, tap } from '@pushrocks/tapbundle';
import * as smartlog from "../ts/index"; import * as smartlog from '../ts/index';
let defaultLogger: smartlog.Smartlog; let defaultLogger: smartlog.Smartlog;
tap.test("should produce instance of Smartlog", async () => { tap.test('should produce instance of Smartlog', async () => {
defaultLogger = smartlog.getDefaultLogger(); defaultLogger = smartlog.defaultLogger;
expect(defaultLogger).to.be.instanceOf(smartlog.Smartlog); expect(defaultLogger).to.be.instanceOf(smartlog.Smartlog);
}); });
tap.test("should enable console logging", async () => { tap.test('should enable console logging', async () => {
defaultLogger.enableConsole(); defaultLogger.enableConsole();
}); });
tap.test("should be able to log things", async () => { tap.test('should be able to log things', async () => {
defaultLogger.log("silly", "hi"); defaultLogger.log('silly', 'hi');
}); });
tap.start(); tap.start();

View File

@ -1,13 +1,16 @@
import * as plugins from "./smartlog.plugins"; import * as plugins from './smartlog.plugins';
import { Smartlog } from "./smartlog.classes.smartlog"; import { Smartlog } from './smartlog.classes.smartlog';
const defaultLogger: Smartlog = new Smartlog({
export { Smartlog }; logContext: {
company: 'undefined',
let defaultLogger: Smartlog; companyunit: 'undefefined',
containerName: 'undefined',
export const getDefaultLogger = () => { environment: 'local',
if (!defaultLogger) { runtime: 'node',
defaultLogger = new Smartlog(); zone: 'undefined'
} }
return defaultLogger; });
};
defaultLogger.enableConsole();
export { Smartlog, defaultLogger };

View File

@ -0,0 +1,23 @@
import * as plugins from './smartlog.plugins';
import { ILogDestination, ILogPackage } from '@pushrocks/smartlog-interfaces';
export class LogRouter {
/**
* all log destinations
*/
private logDestinations: ILogDestination[] = [];
constructor() {}
public addLogDestination(logDestination: ILogDestination) {
this.logDestinations.push(logDestination);
}
// routes the log according to added logDestinations
routeLog(logPackageArg: ILogPackage) {
for (const logDestination of this.logDestinations) {
logDestination.handleLog(logPackageArg);
}
}
}

View File

@ -1,18 +1,28 @@
import * as plugins from "./smartlog.plugins"; import * as plugins from './smartlog.plugins';
export type TLogLevel = import { LogRouter } from './smartlog.classes.logrouter';
| "error"
| "warn" export interface ISmartlogContructorOptions {
| "info" logContext: plugins.smartlogInterfaces.ILogContext;
| "verbose" minimumLogLevel?: plugins.smartlogInterfaces.TLogLevel;
| "debug" }
| "silly";
export class Smartlog { export class Smartlog {
private winstonInstance = new plugins.winston.createLogger({ private logContext: plugins.smartlogInterfaces.ILogContext;
level: "silly", private minimumLogLevel: plugins.smartlogInterfaces.TLogLevel;
format: plugins.winston.format.json()
}); private consoleEnabled: boolean;
private logRouter = new LogRouter();
public addLogDestination(logDestinationArg: plugins.smartlogInterfaces.ILogDestination) {
this.logRouter.addLogDestination(logDestinationArg);
}
constructor(optionsArg: ISmartlogContructorOptions) {
this.logContext = optionsArg.logContext;
this.minimumLogLevel = optionsArg.minimumLogLevel;
}
// ============ // ============
// Logger Setup // Logger Setup
@ -21,47 +31,52 @@ export class Smartlog {
/** /**
* enables console logging * enables console logging
*/ */
enableConsole() { public enableConsole() {
this.winstonInstance.add(new plugins.winston.transports.Console()); this.consoleEnabled = true;
}
/**
* set a minimum serverity level to log
* @param levelArg
*/
level(levelArg: TLogLevel) {
this.winstonInstance.level(levelArg);
} }
// ============= // =============
// log functions // log functions
// ============= // =============
/** /**
* log stuff * main log method
* @param logLevelArg * @param logLevelArg - the log level
* @param logMessageArg * @param logMessageArg - the log message
* @param logDataArg - any additional log data
*/ */
log(logLevelArg: TLogLevel, logMessageArg: string) { public log(logLevelArg: plugins.smartlogInterfaces.TLogLevel, logMessageArg: string, logDataArg?: any) {
this.winstonInstance.log(logLevelArg, logMessageArg); if (this.consoleEnabled) {
console.log(
`LOG => ${new Date().getHours()}:${new Date().getMinutes()}:${new Date().getSeconds()} => ${logLevelArg}: ${logMessageArg}`
);
}
const logPackage: plugins.smartlogInterfaces.ILogPackage = {
timestamp: Date.now(),
type: 'log',
context: this.logContext,
level: logLevelArg,
message: logMessageArg
};
if (logDataArg) {
logPackage.data = logDataArg;
}
this.logRouter.routeLog(logPackage);
} }
silly(logMessageArg: string) { public increment(logLevelArg: plugins.smartlogInterfaces.TLogLevel, logMessageArg) {
this.log("silly", logMessageArg); if (this.consoleEnabled) {
console.log(`INCREMENT: ${logLevelArg}: ${logMessageArg}`);
}
this.logRouter.routeLog({
timestamp: Date.now(),
type: 'increment',
context: this.logContext,
level: logLevelArg,
message: logMessageArg
});
} }
debug(logMessageArg) { public handleLogPackage(logPackageArg: plugins.smartlogInterfaces.ILogPackage) {
this.log("debug", logMessageArg); this.logRouter.routeLog(logPackageArg);
}
info(logMessageArg: string) {
this.log("info", logMessageArg);
}
warn(logMessageArg) {
this.log("warn", logMessageArg);
}
error(logMessageArg) {
this.log("error", logMessageArg);
} }
} }

View File

@ -1,2 +1,5 @@
import * as winston from "winston"; import * as smartlogInterfaces from '@pushrocks/smartlog-interfaces';
export { winston };
export {
smartlogInterfaces
};

View File

@ -1,3 +1,17 @@
{ {
"extends": "tslint-config-standard" "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"
} }

306
yarn.lock
View File

@ -1,306 +0,0 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"@types/code@^4.0.3":
version "4.0.3"
resolved "https://registry.yarnpkg.com/@types/code/-/code-4.0.3.tgz#9c4de39f86eb3eba070146d2dab7dbc3f8eac35f"
"@types/node@^8.0.33":
version "8.5.9"
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.5.9.tgz#7155cfb4ae405bca4dd8df1a214c339e939109bf"
ansi-256-colors@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/ansi-256-colors/-/ansi-256-colors-1.1.0.tgz#910de50efcc7c09e3d82f2f87abd6b700c18818a"
async@^1.0.0:
version "1.5.2"
resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a"
beautycolor@^1.0.7:
version "1.0.11"
resolved "https://registry.yarnpkg.com/beautycolor/-/beautycolor-1.0.11.tgz#71c5568d5a7ed5c144d3a54f753ad1b08862aea5"
dependencies:
ansi-256-colors "^1.1.0"
typings-global "^1.0.14"
bindings@^1.2.1:
version "1.3.0"
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.3.0.tgz#b346f6ecf6a95f5a815c5839fc7cdb22502f1ed7"
code@^5.1.0:
version "5.1.2"
resolved "https://registry.yarnpkg.com/code/-/code-5.1.2.tgz#e3310c2078ca7dc0b49b9c39a8b0a7b06bd75efe"
dependencies:
hoek "5.x.x"
color-convert@^0.5.0:
version "0.5.3"
resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-0.5.3.tgz#bdb6c69ce660fadffe0b0007cc447e1b9f7282bd"
color-name@^1.0.0:
version "1.1.3"
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25"
color-string@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/color-string/-/color-string-0.3.0.tgz#27d46fb67025c5c2fa25993bfbf579e47841b991"
dependencies:
color-name "^1.0.0"
color@0.8.x:
version "0.8.0"
resolved "https://registry.yarnpkg.com/color/-/color-0.8.0.tgz#890c07c3fd4e649537638911cf691e5458b6fca5"
dependencies:
color-convert "^0.5.0"
color-string "^0.3.0"
colornames@0.0.2:
version "0.0.2"
resolved "https://registry.yarnpkg.com/colornames/-/colornames-0.0.2.tgz#d811fd6c84f59029499a8ac4436202935b92be31"
colors@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/colors/-/colors-1.1.2.tgz#168a4701756b6a7f51a12ce0c97bfa28c084ed63"
colorspace@1.0.x:
version "1.0.1"
resolved "https://registry.yarnpkg.com/colorspace/-/colorspace-1.0.1.tgz#c99c796ed31128b9876a52e1ee5ee03a4a719749"
dependencies:
color "0.8.x"
text-hex "0.0.x"
define-properties@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/define-properties/-/define-properties-1.1.2.tgz#83a73f2fea569898fb737193c8f873caf6d45c94"
dependencies:
foreach "^2.0.5"
object-keys "^1.0.8"
diagnostics@^1.0.1:
version "1.1.0"
resolved "https://registry.yarnpkg.com/diagnostics/-/diagnostics-1.1.0.tgz#e1090900b49523e8527be20f081275205f2ae36a"
dependencies:
colorspace "1.0.x"
enabled "1.0.x"
kuler "0.0.x"
early@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/early/-/early-2.1.1.tgz#841e23254ea5dc54d8afaeee82f5ab65c00ee23c"
dependencies:
beautycolor "^1.0.7"
smartq "^1.1.1"
typings-global "^1.0.16"
enabled@1.0.x:
version "1.0.2"
resolved "https://registry.yarnpkg.com/enabled/-/enabled-1.0.2.tgz#965f6513d2c2d1c5f4652b64a2e3396467fc2f93"
dependencies:
env-variable "0.0.x"
env-variable@0.0.x:
version "0.0.3"
resolved "https://registry.yarnpkg.com/env-variable/-/env-variable-0.0.3.tgz#b86c1641be5610267d506f18071ea76d707097cb"
es-abstract@^1.5.1:
version "1.10.0"
resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.10.0.tgz#1ecb36c197842a00d8ee4c2dfd8646bb97d60864"
dependencies:
es-to-primitive "^1.1.1"
function-bind "^1.1.1"
has "^1.0.1"
is-callable "^1.1.3"
is-regex "^1.0.4"
es-to-primitive@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/es-to-primitive/-/es-to-primitive-1.1.1.tgz#45355248a88979034b6792e19bb81f2b7975dd0d"
dependencies:
is-callable "^1.1.1"
is-date-object "^1.0.1"
is-symbol "^1.0.1"
es6-error@^4.0.2:
version "4.1.1"
resolved "https://registry.yarnpkg.com/es6-error/-/es6-error-4.1.1.tgz#9e3af407459deed47e9a91f9b885a84eb05c561d"
fecha@^2.3.2:
version "2.3.2"
resolved "https://registry.yarnpkg.com/fecha/-/fecha-2.3.2.tgz#360f035dd6edd954bc9581f95f2a4a7f2a3505c1"
foreach@^2.0.5:
version "2.0.5"
resolved "https://registry.yarnpkg.com/foreach/-/foreach-2.0.5.tgz#0bee005018aeb260d0a3af3ae658dd0136ec1b99"
function-bind@^1.0.2, function-bind@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d"
has@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/has/-/has-1.0.1.tgz#8461733f538b0837c9361e39a9ab9e9704dc2f28"
dependencies:
function-bind "^1.0.2"
hoek@5.x.x:
version "5.0.2"
resolved "https://registry.yarnpkg.com/hoek/-/hoek-5.0.2.tgz#d2f2c95d36fe7189cf8aa8c237abc1950eca1378"
is-callable@^1.1.1, is-callable@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.1.3.tgz#86eb75392805ddc33af71c92a0eedf74ee7604b2"
is-date-object@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/is-date-object/-/is-date-object-1.0.1.tgz#9aa20eb6aeebbff77fbd33e74ca01b33581d3a16"
is-regex@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/is-regex/-/is-regex-1.0.4.tgz#5517489b547091b0930e095654ced25ee97e9491"
dependencies:
has "^1.0.1"
is-symbol@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/is-symbol/-/is-symbol-1.0.1.tgz#3cc59f00025194b6ab2e38dbae6689256b660572"
isstream@0.1.x:
version "0.1.2"
resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"
kuler@0.0.x:
version "0.0.0"
resolved "https://registry.yarnpkg.com/kuler/-/kuler-0.0.0.tgz#b66bb46b934e550f59d818848e0abba4f7f5553c"
dependencies:
colornames "0.0.2"
leakage@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/leakage/-/leakage-0.3.0.tgz#15d698abdc76bbc6439601f4f3020e77e2d50c39"
dependencies:
es6-error "^4.0.2"
left-pad "^1.1.3"
memwatch-next "^0.3.0"
minimist "^1.2.0"
pretty-bytes "^4.0.2"
left-pad@^1.1.3:
version "1.2.0"
resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.2.0.tgz#d30a73c6b8201d8f7d8e7956ba9616087a68e0ee"
logform@^1.2.1:
version "1.2.2"
resolved "https://registry.yarnpkg.com/logform/-/logform-1.2.2.tgz#7be8847684de07185029ed09c65b11d06191ef93"
dependencies:
colors "^1.1.2"
fecha "^2.3.2"
memwatch-next@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/memwatch-next/-/memwatch-next-0.3.0.tgz#2111050f9a906e0aa2d72a4ec0f0089c78726f8f"
dependencies:
bindings "^1.2.1"
nan "^2.3.2"
minimist@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284"
nan@^2.3.2:
version "2.8.0"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.8.0.tgz#ed715f3fe9de02b57a5e6252d90a96675e1f085a"
object-keys@^1.0.8:
version "1.0.11"
resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.0.11.tgz#c54601778ad560f1142ce0e01bcca8b56d13426d"
object.getownpropertydescriptors@^2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/object.getownpropertydescriptors/-/object.getownpropertydescriptors-2.0.3.tgz#8758c846f5b407adab0f236e0986f14b051caa16"
dependencies:
define-properties "^1.1.2"
es-abstract "^1.5.1"
one-time@0.0.4:
version "0.0.4"
resolved "https://registry.yarnpkg.com/one-time/-/one-time-0.0.4.tgz#f8cdf77884826fe4dff93e3a9cc37b1e4480742e"
pretty-bytes@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/pretty-bytes/-/pretty-bytes-4.0.2.tgz#b2bf82e7350d65c6c33aa95aaa5a4f6327f61cd9"
smartchai@^1.0.3:
version "1.0.8"
resolved "https://registry.yarnpkg.com/smartchai/-/smartchai-1.0.8.tgz#a074836f4ddd4b98c50f1e7ae9e8e8ad9f6f1902"
dependencies:
"@types/code" "^4.0.3"
code "^5.1.0"
typings-global "^1.0.20"
smartdelay@^1.0.3:
version "1.0.4"
resolved "https://registry.yarnpkg.com/smartdelay/-/smartdelay-1.0.4.tgz#791c1a4ee6770494064c10b1d2d2b8e6f3105b82"
dependencies:
smartq "^1.1.1"
typings-global "^1.0.16"
smartq@^1.1.1:
version "1.1.6"
resolved "https://registry.yarnpkg.com/smartq/-/smartq-1.1.6.tgz#0c1ff4336d95e95b4f1fdd8ccd7e2c5a323b8412"
dependencies:
typings-global "^1.0.19"
util.promisify "^1.0.0"
stack-trace@0.0.x:
version "0.0.10"
resolved "https://registry.yarnpkg.com/stack-trace/-/stack-trace-0.0.10.tgz#547c70b347e8d32b4e108ea1a2a159e5fdde19c0"
tapbundle@^1.0.13:
version "1.1.8"
resolved "https://registry.yarnpkg.com/tapbundle/-/tapbundle-1.1.8.tgz#e08aee0e100a830d8a26a583a85d37ce53312e02"
dependencies:
"@types/node" "^8.0.33"
early "^2.1.1"
leakage "^0.3.0"
smartchai "^1.0.3"
smartdelay "^1.0.3"
smartq "^1.1.1"
typings-global "^1.0.19"
text-hex@0.0.x:
version "0.0.0"
resolved "https://registry.yarnpkg.com/text-hex/-/text-hex-0.0.0.tgz#578fbc85a6a92636e42dd17b41d0218cce9eb2b3"
triple-beam@^1.0.1:
version "1.1.0"
resolved "https://registry.yarnpkg.com/triple-beam/-/triple-beam-1.1.0.tgz#2ac387c8c4bd04bd26c61df891a6079f8592fe10"
typings-global@^1.0.14, typings-global@^1.0.16, typings-global@^1.0.19, typings-global@^1.0.20:
version "1.0.28"
resolved "https://registry.yarnpkg.com/typings-global/-/typings-global-1.0.28.tgz#e28cc965476564cbc00e438739e0aa0735d323d4"
util.promisify@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/util.promisify/-/util.promisify-1.0.0.tgz#440f7165a459c9a16dc145eb8e72f35687097030"
dependencies:
define-properties "^1.1.2"
object.getownpropertydescriptors "^2.0.3"
winston-transport@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/winston-transport/-/winston-transport-3.0.1.tgz#8008b15eef5660c4fb3fa094d58ccbd08528c58d"
winston@^3.0.0-rc1:
version "3.0.0-rc1"
resolved "https://registry.yarnpkg.com/winston/-/winston-3.0.0-rc1.tgz#982bc0ad4ef5c53000ca68036d78a3deaa28cac5"
dependencies:
async "^1.0.0"
diagnostics "^1.0.1"
isstream "0.1.x"
logform "^1.2.1"
one-time "0.0.4"
stack-trace "0.0.x"
triple-beam "^1.0.1"
winston-transport "^3.0.1"