Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
JCThePants committed May 1, 2020
0 parents commit fb2bb51
Show file tree
Hide file tree
Showing 25 changed files with 4,476 additions and 0 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Build & Test Package
on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
linux-node10:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '10.x'
- run: npm config set "@mintpond:registry" https://npm.pkg.github.com/mintpond
- run: npm config set //npm.pkg.github.com/:_authToken ${{secrets.NPM_INSTALL_TOKEN}}
- run: npm install
- run: npm test

linux-node12:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '12.x'
- run: npm config set "@mintpond:registry" https://npm.pkg.github.com
- run: npm config set //npm.pkg.github.com/:_authToken ${{secrets.NPM_INSTALL_TOKEN}}
- run: npm install
- run: npm test

windows-node10:
runs-on: windows-2016
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '10.x'
- run: npm config set "@mintpond:registry" https://npm.pkg.github.com
- run: npm config set //npm.pkg.github.com/:_authToken ${{secrets.NPM_INSTALL_TOKEN}}
- run: npm install
- run: npm test

windows-node12:
runs-on: windows-2016
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '12.x'
- run: npm config set "@mintpond:registry" https://npm.pkg.github.com
- run: npm config set //npm.pkg.github.com/:_authToken ${{secrets.NPM_INSTALL_TOKEN}}
- run: npm install
- run: npm test
16 changes: 16 additions & 0 deletions .github/workflows/publish-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Publish Package
on:
release:
types: [created]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '10.x'
- run: npm config set "@mintpond:registry" https://npm.pkg.github.com/mintpond
- run: npm config set //npm.pkg.github.com/:_authToken ${{secrets.GITHUB_TOKEN}}
- run: npm install
- run: npm publish
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
.idea/
.forever/
.vscode/
*.iml
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 JCThePants, contributors

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.
181 changes: 181 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
mint-logger
===========

A _console_, _rolling file_, _log server_ and _remote log sending_ JSON based logger with process fork handling
capability for NodeJS used by [MintPond Mining Pool](https://mintpond.com).

## Install ##
__Install as Dependency in NodeJS Project__
```bash
# Install from Github NPM repository

npm config set @mintpond:registry https://npm.pkg.github.com/mintpond
npm config set //npm.pkg.github.com/:_authToken <PERSONAL_ACCESS_TOKEN>

npm install @mintpond/mint-logger@1.0.0 --save
```
[Creating a personal access token](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line)

__Install & Test__
```bash
# Install nodejs v10
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install nodejs -y

# Download mint-logger
git clone https://github.com/MintPond/mint-loggers

# build & test
cd mint-logger
npm install
npm test
```

## Examples ##

__Configuration__
```javascript
const MasterLogger = require('@mintpond/mint-logger').MasterLogger;

const logger = new MasterLogger('logger'/*groupId*/);
logger.configure({
level: 'info', // possible: trace, debug, info, warn, error
streams: [
{
name: 'console', // print log to console (stdout and stderr)
useColors: true,
level: 'trace', // main level overrides this if it is lower
tags: ['timeMs', 'host', 'process', 'context'], // names of logged data properties to include as [tags]
excludeProperties: [] // names of properties in custom logged data to exclude from console display
},
{
name: 'rollingFile', // rollover on new day or when file size gets too large
autoArchive: true, // archive logs into tar.gz files automatically
level: 'trace',
logDir: './logs', // the directory where log files will be written
file: 'log' // will output file as "./logs/log.2020_04_30.1588292809.0.log" (file.YYYY_MM_DD.startTime.fileSizeRolloverCount.log)
},
{
name: 'remoteLog',
level: 'trace',
listen: [ // listen for connections from remote log clients and stream logs to them
{
host: '127.0.0.1', // open a server on 127.0.0.1:18001
port: 18001
}
],
connect: [ // connect to remote log clients and stream logs to them
{
host: '127.0.0.1', // connect to a server on 127.0.0.1:18002
port: 18002
}
]
}
]
});
```

__Cluster__
```javascript
const cluster = require('cluster');
const MasterLogger = require('@mintpond/mint-logger').MasterLogger;
const ForkLogger = require('@mintpond/mint-logger').ForkLogger;

let logger;

if (cluster.isMaster) {
logger = new MasterLogger('logger'/*groupId*/);

// Only the root master logger is configurable
logger.configure({
level: 'info', // possible: trace, debug, info, warn, error
streams: [
{
name: 'rollingFile', // rollover on new day or when file size gets too large
autoArchive: true,
level: 'trace',
logDir: './logs',
file: 'log' // will output file as "./logs/log.2020_04_30.1588292809.0.log" (file.YYYY_MM_DD.startTime.fileSizeRolloverCount.log)
}
]
});

// Fork process
const fork = cluster.fork({});

logger.info('Master started');
}
else {
logger = new ForkLogger('logger'); // groupId assigns this fork logger to the master with the same groupId.

logger.info('Fork process started'); // sends log to master where it will be sent to configured output streams.

logger.trace('Trace message');
logger.debug('Debug message');
logger.warn('Warn message');
logger.error('Error message');
logger.special('Special message');
}
```

__Log Data__
```javascript

logger.info({
msg: 'The primary message must be in a property called "msg"',
data: [
"Any data that can be converted to JSON can be logged",
true
],
moreStuff: "hello",
note: "Every log entry automatically includes data such as time, process name, host, IP, PID and context."
});

```

__Contexts__
```javascript

// Create a logger with a sub context. Each log created by the new logger will include the context path.
const contextLogger = logger.createLogger('contextName');

// Create a logger whose context is "contextName.subContext"
const subContextLogger = contextLogger.createLogger('subContext');
```

__Events__
```javascript
const Logger = require('@mintpond/mint-logger').Logger;

logger.on(Logger.EVENT_LOG_TRACE, ev => {
console.log(ev.message);
console.log(ev.level);
});

logger.on(Logger.EVENT_LOG_DEBUG, ev => {
console.log(ev.message);
console.log(ev.level);
});

logger.on(Logger.EVENT_LOG_INFO, ev => {
console.log(ev.message);
console.log(ev.level);
});

logger.on(Logger.EVENT_LOG_WARN, ev => {
console.log(ev.message);
console.log(ev.level);
});

logger.on(Logger.EVENT_LOG_ERROR, ev => {
console.log(ev.message);
console.log(ev.level);
console.log(ev.logStack);
});

logger.on(Logger.EVENT_LOG_SPECIAL, ev => {
console.log(ev.message);
console.log(ev.level);
});

```
9 changes: 9 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

module.exports = {
Logger: require('./libs/loggers/abstract.Logger'),
MasterLogger: require('./libs/loggers/class.MasterLogger'),
ForkLogger: require('./libs/loggers/class.ForkLogger'),
ForkMessageType: require('./libs/const.ForkMessageType'),
LoggerLevel: require('./libs/const.LoggerLevel')
}
Loading

0 comments on commit fb2bb51

Please sign in to comment.