-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
POC, still WIP
- Loading branch information
0 parents
commit f0cc9d1
Showing
17 changed files
with
3,980 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: CI - master | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
ci-tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Cache node_modules | ||
uses: actions/cache@v4 | ||
id: tests | ||
env: | ||
cache-name: tests | ||
with: | ||
path: ./node_modules/ | ||
key: tests-${{ hashFiles('./package-lock.json') }} | ||
restore-keys: tests-${{ hashFiles('./package-lock.json') }} | ||
timeout-minutes: 4 | ||
- name: Install dependencies | ||
if: steps.tests.outputs.cache-hit != true | ||
run: npm ci | ||
- name: Build | ||
run: npm run build | ||
- name: Run tests | ||
run: npm test | ||
|
||
# publish-pages: | ||
# runs-on: ubuntu-latest | ||
# needs: ci-tests | ||
# if: success() | ||
# steps: | ||
# - name: Checkout code | ||
# uses: actions/checkout@v3 | ||
# with: | ||
# ref: master | ||
# - name: Configure Git | ||
# run: | | ||
# git config user.name "Allen" | ||
# git config user.email "accounts@stupid-genius.com" | ||
# - name: Publish to pages branch | ||
# run: ./publish.sh | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
*.swp | ||
.idea | ||
node_modules | ||
*.log | ||
*.log.gz | ||
*.pem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Log-Ng | ||
Provides both a node.js and a browser logger, inspired by loggers like [log4j](https://logging.apache.org/log4j/2.x/) and [Winston](https://github.com/winstonjs/winston) (The node.js logger uses Winston under the hood). | ||
## Browser Logger | ||
The browser logger was inspired by Winston, and aims to provide configurable log levels, allowing logging to be left in place without needing to modify the code to enable or disable logging. It uses `ConsoleTransport` by default, but also comes with `APITransport` for sending logs to a server and `FileTransport` for saving logs to a file (requires support for the File System API). | ||
### Example | ||
#### ConsoleTransport (default) | ||
```javascript | ||
import { Logger } from 'log-ng'; | ||
const logger = new Logger('thisFile'); | ||
Logger.setLevel('info'); | ||
logger.info('Hello, World!'); | ||
``` | ||
#### APITransport | ||
```javascript | ||
import { Logger, APITransport } from 'log-ng'; | ||
Logger.setLevel('info'); | ||
Logger.addTransport('api', new APITransport({ | ||
url: 'http://localhost:3000/log', | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body: { | ||
msg: '{{msg}}', | ||
level: '{{level}}', | ||
category: '{{category}}', | ||
timestamp: '{{timestamp}}', | ||
group: '{{group}}', | ||
isTable: '{{isTable}}', | ||
args: '{{args}}' | ||
} | ||
})); | ||
const logger = new Logger('thisFile'); | ||
logger.info('Hello, World!'); | ||
```` | ||
#### FileTransport | ||
```javascript | ||
import { Logger, FileTransport } from 'log-ng'; | ||
Logger.setLevel('info'); | ||
const fileTransport = new FileTransport({}); | ||
await fileTransport.initialize(); | ||
Logger.addTransport('file', fileTransport); | ||
const logger = new Logger('thisFile'); | ||
logger.info('Hello, World!'); | ||
``` | ||
## Node.js Logger | ||
The node.js logger is a wrapper around Winston, and provides a simple way to log messages to the console. Additional Winston transports can be added, as needed. The primary purpose of this Logger is to simplify creation of pre-configured Winston child instances of the main singleton instance. | ||
### Example | ||
#### Basic Usage | ||
```javascript | ||
const { Logger } = require('log-ng'); | ||
const logger = new Logger(path.basename(__filename)); | ||
logger.info('Hello, World!'); | ||
``` | ||
#### Adding Transports | ||
```javascript | ||
const { Logger } = require('log-ng'); | ||
const { File } = require('winston').transports; | ||
Logger.addTransport('file', new File({ filename: 'log.log' })); | ||
const logger = new Logger(path.basename(__filename)); | ||
logger.info('Hello, World!'); | ||
``` | ||
|
||
## TODO | ||
- [ ] Implement table and group rendering in the API and File transports | ||
- [ ] Implement console placeholder for API and File transports | ||
- [ ] Implement escaping of {{ and }} in interpolate function |
Oops, something went wrong.