Skip to content

Commit 60ecbd1

Browse files
committed
Init
0 parents  commit 60ecbd1

File tree

7 files changed

+146
-0
lines changed

7 files changed

+146
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea
2+
node_modules

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# @barchart/log4js-node-appenders
2+

gulpfile.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
const git = require('gulp-git'),
2+
gitStatus = require('git-get-status'),
3+
gulp = require('gulp'),
4+
jshint = require('gulp-jshint'),
5+
prompt = require('gulp-prompt');
6+
7+
function getVersionFromPackage() {
8+
return JSON.parse(fs.readFileSync('./package.json', 'utf8')).version;
9+
}
10+
11+
gulp.task('ensure-clean-working-directory', (cb) => {
12+
gitStatus((err, status) => {
13+
if (err, !status.clean) {
14+
throw new Error('Unable to proceed, your working directory is not clean.');
15+
}
16+
17+
cb();
18+
});
19+
});
20+
21+
gulp.task('bump-choice', (cb) => {
22+
const processor = prompt.prompt({
23+
type: 'list',
24+
name: 'bump',
25+
message: 'What type of bump would you like to do?',
26+
choices: ['patch', 'minor', 'major'],
27+
}, (res) => {
28+
global.bump = res.bump;
29+
30+
return cb();
31+
});
32+
33+
return gulp.src(['./package.json']).pipe(processor);
34+
});
35+
36+
gulp.task('bump-version', (cb) => {
37+
exec(`npm version ${global.bump || 'patch'} --no-git-tag-version`, {
38+
cwd: './'
39+
}, (error) => {
40+
if (error) {
41+
cb(error);
42+
}
43+
44+
cb();
45+
});
46+
});
47+
48+
gulp.task('commit-changes', () => {
49+
return gulp.src([ './package*', ])
50+
.pipe(git.add())
51+
.pipe(git.commit('Release. Bump version number'));
52+
});
53+
54+
gulp.task('push-changes', (cb) => {
55+
git.push('origin', 'master', cb);
56+
});
57+
58+
gulp.task('create-tag', (cb) => {
59+
const version = getVersionFromPackage();
60+
61+
git.tag(version, 'Release ' + version, (error) => {
62+
if (error) {
63+
return cb(error);
64+
}
65+
66+
git.push('origin', 'master', { args: '--tags' }, cb);
67+
});
68+
});
69+
70+
gulp.task('release', gulp.series(
71+
'ensure-clean-working-directory',
72+
'bump-choice',
73+
'bump-version',
74+
'commit-changes',
75+
'push-changes',
76+
'create-tag'
77+
));
78+
79+
gulp.task('lint', () => {
80+
return gulp.src([ './**/*.js', '!./node_modules/**' ])
81+
.pipe(jshint({ esversion: 6 }))
82+
.pipe(jshint.reporter('default'));
83+
});
84+
85+
gulp.task('default', gulp.series('lint'));

index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const lambdaAppender = require('./lib/lambda.js');
2+
3+
const appenders = { };
4+
5+
appenders.lambda = lambdaAppender;
6+
7+
module.exports = appenders;
8+

lib/lambda.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const levels = new Map();
2+
3+
levels.set('TRACE', console.trace.bind(console));
4+
levels.set('DEBUG', console.debug.bind(console));
5+
levels.set('INFO', console.log.bind(console));
6+
levels.set('WARN', console.warn.bind(console));
7+
levels.set('ERROR', console.error.bind(console));
8+
levels.set('FATAL', console.error.bind(console));
9+
10+
function appender(layout, timezoneOffset) {
11+
return (loggingEvent) => {
12+
let log;
13+
14+
if (levels.has(loggingEvent.levelStr)) {
15+
log = levels.get(loggingEvent.levelStr);
16+
} else {
17+
log = levels.get('INFO');
18+
}
19+
20+
log(layout(loggingEvent, timezoneOffset));
21+
};
22+
}
23+
24+
function configure(config, layouts) {
25+
let layout = layouts.colouredLayout;
26+
27+
if (config.layout) {
28+
layout = layouts.layout(config.layout.type, config.layout);
29+
}
30+
31+
return appender(layout, config.timezoneOffset);
32+
}
33+
34+
module.exports.configure = configure;

package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "@barchart/log4js-node-appenders",
3+
"version": "1.0.0",
4+
"description": "JavaScript library with custom appenders for log4js",
5+
"dependencies": {},
6+
"devDependencies": {
7+
"git-get-status": "^1.0.2",
8+
"gulp": "^4.0.2",
9+
"gulp-git": "^2.10.1",
10+
"gulp-jshint": "~2.1.0",
11+
"gulp-prompt": "^1.2.0",
12+
"jshint": "2.9.5"
13+
}
14+
}

0 commit comments

Comments
 (0)