@meshwatch/logging
Advanced tools
Comparing version 1.0.8 to 1.0.9
@@ -1,7 +0,1 @@ | ||
## [1.0.8](https://gitlab.com/meshwatch/logging/compare/v1.0.7...v1.0.8) (2019-08-04) | ||
### Bug Fixes | ||
* Add CHANGELOG ([3c4cafb](https://gitlab.com/meshwatch/logging/commit/3c4cafb)) | ||
* rename changelog file ([f763aba](https://gitlab.com/meshwatch/logging/commit/f763aba)) | ||
[RELEASES](https://gitlab.com/meshwatch/logging/-/releases) |
import { Dictionary } from './types'; | ||
declare let clearAll: () => void; | ||
declare let replaceAllWith: (ctx: Dictionary<string>) => void; | ||
declare let set: (key: string, value: string) => void; | ||
declare let get: () => Dictionary<string>; | ||
declare const clearAll: () => void; | ||
declare const replaceAllWith: (ctx: Dictionary<string>) => void; | ||
declare const set: (key: string, value: string) => void; | ||
declare const get: () => Dictionary<string>; | ||
export { clearAll, replaceAllWith, set, get }; |
@@ -27,3 +27,3 @@ 'use strict'; | ||
let get = () => { | ||
const get = () => { | ||
return typedGlobal.CONTEXT || {}; | ||
@@ -92,3 +92,8 @@ }; | ||
function productionStream(levelName, message, params) { | ||
function productionStream({ | ||
logFn, | ||
levelName, | ||
message, | ||
params | ||
}) { | ||
const context = getContext(); | ||
@@ -101,7 +106,12 @@ | ||
console.log(JSON.stringify(logMsg)); | ||
logFn(JSON.stringify(logMsg)); | ||
} | ||
function developmentStream(levelName, message, params) { | ||
console.log(levelName, message, util.inspect(params, { | ||
function developmentStream({ | ||
logFn, | ||
levelName, | ||
message, | ||
params | ||
}) { | ||
logFn(levelName, message, util.inspect(params, { | ||
depth: Infinity | ||
@@ -113,3 +123,3 @@ })); | ||
const log = (levelName, message, params = {}) => { | ||
const log = (logFn, levelName, message, params = {}) => { | ||
if (skipLogging(levelName)) { | ||
@@ -119,19 +129,24 @@ return; | ||
logStream(levelName, message, params); | ||
logStream({ | ||
logFn, | ||
levelName, | ||
message, | ||
params | ||
}); | ||
}; | ||
const debug = (msg, params) => { | ||
log('DEBUG', msg, params); | ||
log(console.debug, 'DEBUG', msg, params); | ||
}; | ||
const info = (msg, params) => { | ||
log('INFO', msg, params); | ||
log(console.log, 'INFO', msg, params); | ||
}; | ||
const warn = (msg, error, params) => { | ||
log('WARN', msg, appendError(error, params)); | ||
log(console.warn, 'WARN', msg, appendError(error, params)); | ||
}; | ||
const error = (msg, error, params) => { | ||
log('ERROR', msg, appendError(error, params)); | ||
log(console.error, 'ERROR', msg, appendError(error, params)); | ||
}; | ||
@@ -138,0 +153,0 @@ |
@@ -1,2 +0,2 @@ | ||
"use strict";var e,r=(e=require("util"))&&"object"==typeof e&&"default"in e?e.default:e;function n(){return(n=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e}).apply(this,arguments)}const o=global;let s=()=>o.CONTEXT||{};const t=()=>!(!process.env.LAMBDA_TASK_ROOT||!process.env.AWS_EXECUTION_ENV),c="INFO",a={DEBUG:0,INFO:1,WARN:2,ERROR:3},E={awsRegion:process.env.AWS_REGION||process.env.AWS_DEFAULT_REGION,functionName:process.env.AWS_LAMBDA_FUNCTION_NAME,functionVersion:process.env.AWS_LAMBDA_FUNCTION_VERSION,functionMemorySize:process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE,stage:process.env.ENVIRONMENT||process.env.STAGE},i=()=>{const e=s();return n({},E,{},e)},p=()=>{const e=s();return"true"===process.env.DEBUG_LOG||"true"===e["Debug-Log-Enabled"]},u=(e,r={})=>e?n({},r,{errorName:e.name,errorMessage:e.message,stackTrace:e.stack}):r;function O(e={}){const{logLevel:o}=e,s=()=>o||process.env.LOG_LEVEL||c,E=t()?function(e,r,o){const s=n({},i(),{},o,{level:e,message:r});console.log(JSON.stringify(s))}:function(e,n,o){console.log(e,n,r.inspect(o,{depth:Infinity}))},O=(e,r,n={})=>{(e=>{const r=(e=>e>=a[s()])(a[e]),n=p();return!r&&!n})(e)||E(e,r,n)};return{info:(e,r)=>{O("INFO",e,r)},debug:(e,r)=>{O("DEBUG",e,r)},warn:(e,r,n)=>{O("WARN",e,u(r,n))},error:(e,r,n)=>{O("ERROR",e,u(r,n))}}}const v=O(),{DEBUG_SAMPLE_RATE:N="0.05"}=process.env;exports.createLogger=O,exports.debuggy=(({sampleRate:e=parseFloat(N)}={})=>{let r;return{before:(n,o)=>{Math.random()<=e&&(r=process.env.LOG_LEVEL,process.env.LOG_LEVEL="DEBUG"),o()},after:(e,n)=>{r&&(process.env.LOG_LEVEL=void 0),n()},onError:(e,r)=>{const{awsRequestId:n}=e.context,o=JSON.stringify(e.event);v.error("invocation failed",e.error,{awsRequestId:n,invocationEvent:o}),r(e.error)}}}),exports.logger=v; | ||
"use strict";var e,r=(e=require("util"))&&"object"==typeof e&&"default"in e?e.default:e;function o(){return(o=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var o=arguments[r];for(var s in o)Object.prototype.hasOwnProperty.call(o,s)&&(e[s]=o[s])}return e}).apply(this,arguments)}const s=global,n=()=>s.CONTEXT||{},t=()=>!(!process.env.LAMBDA_TASK_ROOT||!process.env.AWS_EXECUTION_ENV),a="INFO",c={DEBUG:0,INFO:1,WARN:2,ERROR:3},E={awsRegion:process.env.AWS_REGION||process.env.AWS_DEFAULT_REGION,functionName:process.env.AWS_LAMBDA_FUNCTION_NAME,functionVersion:process.env.AWS_LAMBDA_FUNCTION_VERSION,functionMemorySize:process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE,stage:process.env.ENVIRONMENT||process.env.STAGE},l=()=>{const e=n();return o({},E,{},e)},i=()=>{const e=n();return"true"===process.env.DEBUG_LOG||"true"===e["Debug-Log-Enabled"]},p=(e,r={})=>e?o({},r,{errorName:e.name,errorMessage:e.message,stackTrace:e.stack}):r;function v(e={}){const{logLevel:s}=e,n=()=>s||process.env.LOG_LEVEL||a,E=t()?function({logFn:e,levelName:r,message:s,params:n}){const t=o({},l(),{},n,{level:r,message:s});e(JSON.stringify(t))}:function({logFn:e,levelName:o,message:s,params:n}){e(o,s,r.inspect(n,{depth:Infinity}))},v=(e,r,o,s={})=>{(e=>{const r=(e=>e>=c[n()])(c[e]),o=i();return!r&&!o})(r)||E({logFn:e,levelName:r,message:o,params:s})};return{info:(e,r)=>{v(console.log,"INFO",e,r)},debug:(e,r)=>{v(console.debug,"DEBUG",e,r)},warn:(e,r,o)=>{v(console.warn,"WARN",e,p(r,o))},error:(e,r,o)=>{v(console.error,"ERROR",e,p(r,o))}}}const g=v(),{DEBUG_SAMPLE_RATE:u="0.05"}=process.env;exports.createLogger=v,exports.debuggy=(({sampleRate:e=parseFloat(u)}={})=>{let r;return{before:(o,s)=>{Math.random()<=e&&(r=process.env.LOG_LEVEL,process.env.LOG_LEVEL="DEBUG"),s()},after:(e,o)=>{r&&(process.env.LOG_LEVEL=void 0),o()},onError:(e,r)=>{const{awsRequestId:o}=e.context,s=JSON.stringify(e.event);g.error("invocation failed",e.error,{awsRequestId:o,invocationEvent:s}),r(e.error)}}}),exports.logger=g; | ||
//# sourceMappingURL=logging.cjs.production.min.js.map |
@@ -23,3 +23,3 @@ import util from 'util'; | ||
let get = () => { | ||
const get = () => { | ||
return typedGlobal.CONTEXT || {}; | ||
@@ -88,3 +88,8 @@ }; | ||
function productionStream(levelName, message, params) { | ||
function productionStream({ | ||
logFn, | ||
levelName, | ||
message, | ||
params | ||
}) { | ||
const context = getContext(); | ||
@@ -97,7 +102,12 @@ | ||
console.log(JSON.stringify(logMsg)); | ||
logFn(JSON.stringify(logMsg)); | ||
} | ||
function developmentStream(levelName, message, params) { | ||
console.log(levelName, message, util.inspect(params, { | ||
function developmentStream({ | ||
logFn, | ||
levelName, | ||
message, | ||
params | ||
}) { | ||
logFn(levelName, message, util.inspect(params, { | ||
depth: Infinity | ||
@@ -109,3 +119,3 @@ })); | ||
const log = (levelName, message, params = {}) => { | ||
const log = (logFn, levelName, message, params = {}) => { | ||
if (skipLogging(levelName)) { | ||
@@ -115,19 +125,24 @@ return; | ||
logStream(levelName, message, params); | ||
logStream({ | ||
logFn, | ||
levelName, | ||
message, | ||
params | ||
}); | ||
}; | ||
const debug = (msg, params) => { | ||
log('DEBUG', msg, params); | ||
log(console.debug, 'DEBUG', msg, params); | ||
}; | ||
const info = (msg, params) => { | ||
log('INFO', msg, params); | ||
log(console.log, 'INFO', msg, params); | ||
}; | ||
const warn = (msg, error, params) => { | ||
log('WARN', msg, appendError(error, params)); | ||
log(console.warn, 'WARN', msg, appendError(error, params)); | ||
}; | ||
const error = (msg, error, params) => { | ||
log('ERROR', msg, appendError(error, params)); | ||
log(console.error, 'ERROR', msg, appendError(error, params)); | ||
}; | ||
@@ -134,0 +149,0 @@ |
{ | ||
"name": "@meshwatch/logging", | ||
"description": "NodeJS serverless logging", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"license": "UNLICENSED", | ||
@@ -25,4 +25,4 @@ "source": "src/index.ts", | ||
"lint": "concurrently \"npm run prettier\" \"npm run eslint\"", | ||
"prettier": "prettier -l 'src/**/*'", | ||
"eslint": "eslint --max-warnings 0 --ext .ts 'src/**/*'", | ||
"prettier": "prettier -l 'src/**/*.ts'", | ||
"eslint": "eslint --max-warnings 0 'src/**/*.ts'", | ||
"semantic-release": "semantic-release" | ||
@@ -32,23 +32,22 @@ }, | ||
"devDependencies": { | ||
"@semantic-release/changelog": "^3.0.4", | ||
"@semantic-release/gitlab": "^3.1.7", | ||
"@types/jest": "^24.0.16", | ||
"@types/node": "^12.6.9", | ||
"@types/jest": "^24.0.18", | ||
"@types/node": "^12.7.2", | ||
"@types/sinon": "^7.0.13", | ||
"@typescript-eslint/eslint-plugin": "^1.13.0", | ||
"@typescript-eslint/parser": "^1.13.0", | ||
"concurrently": "^4.1.1", | ||
"eslint": "^6.1.0", | ||
"eslint-config-prettier": "^6.0.0", | ||
"@typescript-eslint/eslint-plugin": "^2.0.0", | ||
"@typescript-eslint/parser": "^2.0.0", | ||
"concurrently": "^4.1.2", | ||
"eslint": "^6.2.2", | ||
"eslint-config-prettier": "^6.1.0", | ||
"eslint-plugin-import": "^2.18.2", | ||
"eslint-plugin-prettier": "^3.1.0", | ||
"husky": "^3.0.2", | ||
"jest": "^24.8.0", | ||
"middy": "^0.28.4", | ||
"husky": "^3.0.4", | ||
"jest": "^24.9.0", | ||
"middy": "^0.29.0", | ||
"prettier": "^1.18.2", | ||
"pretty-quick": "^1.11.1", | ||
"semantic-release": "^15.13.19", | ||
"sinon": "^7.4.0", | ||
"semantic-release": "^15.13.24", | ||
"sinon": "^7.4.1", | ||
"ts-jest": "^24.0.2", | ||
"tsdx": "^0.7.2", | ||
"tsdx": "^0.8.0", | ||
"typescript": "^3.5.3" | ||
@@ -55,0 +54,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
52058
21
395