1 |
|
2 | var fs, mustache, path, stream;
|
3 |
|
4 | module.exports = {
|
5 | ssh: null,
|
6 | handler: function(options) {
|
7 | var latestdir, logdir, now;
|
8 | if (!options.serializer) {
|
9 | throw Error("Missing option: serializer");
|
10 | }
|
11 | if (options.archive == null) {
|
12 | options.archive = false;
|
13 | }
|
14 | if (options.basedir == null) {
|
15 | options.basedir = './log';
|
16 | }
|
17 | options.basedir = path.resolve(options.basedir);
|
18 | if (options.basename == null) {
|
19 | options.basename = 'localhost';
|
20 | }
|
21 | if (options.filename == null) {
|
22 | options.filename = "{{basename}}.log";
|
23 | }
|
24 | options.basedir = mustache.render(options.basedir, options);
|
25 | options.filename = mustache.render(options.filename, options);
|
26 | if (!options.archive) {
|
27 | logdir = path.resolve(options.basedir);
|
28 | } else {
|
29 | latestdir = path.resolve(options.basedir, 'latest');
|
30 | now = new Date();
|
31 | if (options.archive === true) {
|
32 | options.archive = ("" + (now.getFullYear())).slice(-2) + ("0" + (now.getFullYear())).slice(-2) + ("0" + (now.getDate())).slice(-2);
|
33 | }
|
34 | logdir = path.resolve(options.basedir, options.archive);
|
35 | }
|
36 | this.mkdir({
|
37 | shy: true
|
38 | }, logdir);
|
39 | this.call(function() {
|
40 | if (options.stream == null) {
|
41 | options.stream = fs.createWriteStream(path.resolve(logdir, options.filename));
|
42 | }
|
43 | return this.call(options, stream);
|
44 | });
|
45 | return this.link({
|
46 | "if": latestdir,
|
47 | shy: true,
|
48 | source: logdir,
|
49 | target: latestdir
|
50 | });
|
51 | }
|
52 | };
|
53 |
|
54 | fs = require('fs');
|
55 |
|
56 | path = require('path');
|
57 |
|
58 | mustache = require('mustache');
|
59 |
|
60 | stream = require('./stream');
|