Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
---
root: true

parserOptions:
ecmaVersion: 2019

env:
node: true
es6: true
jest: true

plugins:
- 'jsdoc'
- 'node'
- '@typescript-eslint/eslint-plugin'

extends:
- 'xo-space'
- 'plugin:jsdoc/recommended'
- 'plugin:node/recommended'

rules:
array-element-newline: off
Expand All @@ -29,5 +25,15 @@ rules:
no-negated-condition: off
keyword-spacing: ['error', { overrides: { if: { after: false }, for: { after: false }, while: { after: false }, catch: { after: false } } }]
jsdoc/newline-after-description: off
node/no-unsupported-features/es-syntax: ['error', { version: '>=10.0.0' }]
node/no-missing-require: off

overrides:
- files: ['*.ts']
parserOptions:
project: './tsconfig.eslint.json'
extends:
- 'xo-typescript/space'
rules:
'@typescript-eslint/keyword-spacing': ['error', { overrides: { if: { after: false }, for: { after: false }, while: { after: false }, catch: { after: false } } }]
'@typescript-eslint/object-curly-spacing': ['error', 'always']
'@typescript-eslint/comma-dangle': ['error', 'never']
'@typescript-eslint/naming-convention': off
13 changes: 9 additions & 4 deletions .github/workflows/module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ on:
push:
branches:
- master
- next
- beta
- alpha
pull_request:
branches:
- master
Expand All @@ -11,7 +14,7 @@ jobs:
test:
strategy:
matrix:
node: [ '10', '12', '14', '16' ]
node: [ '12', '14', '16' ]
name: test/node v${{ matrix.node }}
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -50,7 +53,7 @@ jobs:
threshold: 100
- name: Upload Coverage to Code Climate
uses: paambaati/codeclimate-action@v2.7.2
if: ${{ github.event_name == 'push' }}
if: ${{ github.event_name == 'push' && github.branch == 'master' }}
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
with:
Expand Down Expand Up @@ -79,7 +82,7 @@ jobs:
dry_run: "false"
- uses: bradennapier/eslint-plus-action@v3.4.2
with:
includeGlob: 'index.js,index.test.js,lib/*.js'
includeGlob: 'src/*.ts'

release:
name: Release
Expand All @@ -92,9 +95,11 @@ jobs:
- name: Setup Node
uses: actions/setup-node@master
with:
node-version: 14
node-version: 16
- name: Install Dependencies
run: npm i
- name: Build Package
run: npm run build
- name: Publish to NPM
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ package-lock.json
# DS_Store file
.DS_Store

dist
res
5 changes: 4 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
gh-pages
site
.eslintrc.yml
.releaserc
release.config.js
commitlint.config.js
tsconfig.json
tsconfig.eslint.json
*.test.js
jest.config.js
.all-contributorsrc
.codeclimate.yml
babel.config.js
CHANGELOG.md
README.md
src
13 changes: 0 additions & 13 deletions .releaserc

This file was deleted.

6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
"changeProcessCWD": true
}
],
"eslint.validate": [
"mdx",
"javascript",
"javascriptreact",
"typescript"
],
"[mdx]": {
"editor.wordWrap": "on"
}
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# [3.2.0](https://github.com/KyleRoss/node-lambda-log/compare/v3.1.0...v3.2.0) (2021-11-17)


### Features

* change minimum support to node v12+ ([726a209](https://github.com/KyleRoss/node-lambda-log/commit/726a209040eb6aac5e64e7155ba40b1fedd8249b))
* rewrite into typescript ([2800655](https://github.com/KyleRoss/node-lambda-log/commit/280065579846369ac241142f6c1dd71196af9b56))
* support esm and cjs ([0e8f0ac](https://github.com/KyleRoss/node-lambda-log/commit/0e8f0ac907be771290627d3aac25b507b955c529))

# [3.1.0](https://github.com/KyleRoss/node-lambda-log/compare/v3.0.2...v3.1.0) (2021-10-14)


Expand Down
102 changes: 72 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,80 @@
[![All Contributors](https://img.shields.io/badge/all_contributors-10-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

## CAUTION!

This branch and release (`@next`) is under heavy development. This exists for testing and anyone who is willing to help out with testing. **DO NOT USE IN PRODUCTION!**

If you do decide to try out this brand new version of LambdaLog, please report any issues you face as I can only catch so much. Any help would be greatly appreciated, especially if you are more versed in TypeScript than I am!



### What's new?

This is the next major release of LambdaLog (v4.0.0) which contains many major breaking changes, new features, and TypeScript support.

#### Breaking Changes

- Complete rewrite of most of the core functionality into TypeScript.
- Custom Log Levels has been removed.
- Log levels are now hardcoded and cannot be changed. This greatly simplifies the code and allows us to support TypeScript.
- Use of `Symbol` has been removed along with any static properties on the classes to retrieve the symbols.
- The `debug` option has been removed.
- The default key name for `levelKey` has changed from `_logLevel` to `__level`.
- The default key name for `tagsKey` has changed from `_tags` to `__tags`.
- The shortcut log methods are now hardcoded instead of dynamically generated.
- Removed `addLevel()` method from LambdaLog class.
- Removed `isError()` and `stubError()` static methods from the LogMessage class and moved them into utility functions.
- Environment variables that configure different options now take precedence over locally configured options.
- Internally used properties on the LogMessage class have been renamed.

#### New Features

- You can now configure the verbosity of your log messages through the new `level` option or `LAMBDALOG_LEVEL` env variable.
- Added `fatal` and `trace` log levels.
- Added `onParse` option that allows for custom parsing of log messages.
- Added `onCompile` option that allows for custom structuring of the object that is logged to the console.
- Added `onFormat` option that allows for custom formatting of the logged message. This gives the ability to render log messages in any format, not just JSON. (#75)
- Added `clean` formatter that logs a message in a readable format.
- Added `minimal` formatter that logs a message in a readable format without tags and metadata.
- Ability to provide your own custom formatter as a function.
- Added ability to configure the `level`, `dev`, and `silent` options via environment variables.
- Full written in TypeScript with complete type definitions. (#63, #64)
- The package now provides an ESM and CommonJS version to support your project.

#### Fixes

- Fixed issue where directly setting `log.options.logHandler` did not work (#45).

#### Misc. Changes

- Rewrote most tests into TypeScript and still maintaining 100% coverage.



### What's left?

It has been a pretty large undertaking for me, but one that this package desperately needed. This was my first real dive into TypeScript, so I'm sure there are things than can be written better. **If there is anyone with more advanced TypeScript knowledge, I'm in great need of someone who can review the code and suggest any changes or help refactor the code to get this production-ready.** _(I'll even add you as a maintainer!)_

- Testing package implementation in Node for both vanilla JavaScript and TypeScript.
- Testing ESM support with Node and ensuring CommonJS works correctly as well.
- Ensuring the end-user has access to all the proper files and functionality.
- Documentation.



### Release Date

As much as I am trying to rush this out the door to get these features in the hands of all you awesome developers/engineers, I'm also limited on time (eg. I'm currently writing this documentation at midnight knowing that I have to wake up at 5:30am). Not only that, but I want to ensure I ship this next version of LambdaLog with performance, features, and stability in mind. I hope this will be the last major version for awhile.

Enough with all of that cheesy sob-story, let's talk about when this will be released, well, what I'm aiming for at this point. I hope to finish up most of my to-do list in the next couple of weeks and try to solicit some outside help for testing/analysis. Once that is complete, I hope to get this released as the latest stable version towards the end of 2021 or at the beginning of 2022. That's not guarantee at this point, but it will definitely be feasible if anyone in the community can help out!

---

LambdaLog is a [Node.js package](https://www.npmjs.com/package/lambda-log) facilitates and enforces logging standards in Node.js processes or applications **anywhere** by formatting your log messages as JSON for simple parsing and filtering within log management tools, such as CloudWatch Logs. _Works with all of the supported versions of Node.js on Lambda._

Originally created for AWS Lambda Functions, LambdaLog is a lightweight and feature-rich library that has **no** dependency on AWS or Lambda, meaning you can use it in any type of Node.js project you wish. **It's really a universal JSON logger.**


**Why another lambda logger?**
There are plenty of other logging libraries in the NPM ecosystem but most are convoluted, included more functionality than needed, not maintained, or are not configurable enough. I created LambdaLog to include the important functionality from other loggers, but still maintaining simplicity with minimal dependencies.

Expand All @@ -26,41 +95,14 @@ Anyone can log JSON to the `console`, but with Lambda Log you also get:
- Over 1.5 million downloads and more than 35k weekly downloads.
- Small footprint.

#### New in Version 3.0.0

Version 3.0.0 of Lambda Log brings a bunch of changes, new features, and a [new website](https://lambdalog.dev).

**Broad Changes:**

* Refactor all code to meet new ESLint specifications and to stay up-to-date with newer ecmascript specifications.
* New website with better documentation.
* Tests are now using Jest instead of Mocha.
* Switched from TravisCI to Github Actions.

**New Features:**

- Added `levelKey` configuration option to be able to change the key name for log levels.
- Added `messageKey` configuration option to be able to change the key name for log messages.
- Added `tagsKey` configuration option to be able to change the key name for tags.
- Added ability to remove log level and tags from the outputted log JSON.
- Added `addLevel()` method to quickly add a custom log level to an instance of LambdaLog.
- Tags can now be functions that return a dynamic tag for log messages.
- Tags now have variable support.
- Tags that are `null`, `undefined` or `""` are now removed from the tags array.
- Metadata that contains `Error` objects are now automatically converted to a plain object.

**Breaking Changes:**

- All of the private properties of both the LambdaLog and LogMessage classes are stored using Symbols. This may break some advanced uses of Lambda Log from version 2.
- Tags no longer contain any default, built-in tags and are empty by default.
- Some of the properties of LogMessage have been moved from the constructor to their own getter functions.



## Documentation

Documentation for Lambda Log has moved to our [new website](https://lambdalog.dev).

*Note: The documentation has NOT been updated for this new release yet. I'm working on it!*



## Tests
Expand Down
10 changes: 0 additions & 10 deletions jest.config.js

This file was deleted.

17 changes: 17 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { Config } from '@jest/types';

const config: Config.InitialOptions = {
testEnvironment: 'node',
testRegex: '\\.test\\.ts$',
collectCoverage: true,
collectCoverageFrom: ['src/**/*.ts'],
coverageDirectory: 'coverage',
coverageProvider: 'v8',
coveragePathIgnorePatterns: ['/node_modules/', '/dist/', '<rootDir>/src/typings.ts'],
transform: {
'^.+\\.ts$': 'ts-jest'
},
moduleFileExtensions: ['ts', 'js', 'json', 'node']
};

export default config;
Loading