@Fhillis/

winston

Nodejs

No description

fork
loading
Files
  • index.js
  • package-lock.json
  • package.json
  • quick-start-combined.log
  • quick-start-error.log

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.8640514654188054","path":"index.js","file":{"path":"index.js","content":{"asEncoding":{"base64":"Y29uc3QgeyBjcmVhdGVMb2dnZXIsIGZvcm1hdCwgdHJhbnNwb3J0cyB9ID0gcmVxdWlyZSgnd2luc3RvbicpOwoKY29uc3QgbG9nZ2VyID0gY3JlYXRlTG9nZ2VyKHsKICBsZXZlbDogJ2luZm8nLAogIGZvcm1hdDogZm9ybWF0LmNvbWJpbmUoCiAgICBmb3JtYXQudGltZXN0YW1wKHsKICAgICAgZm9ybWF0OiAnWVlZWS1NTS1ERCBISDptbTpzcycKICAgIH0pLAogICAgZm9ybWF0LmVycm9ycyh7IHN0YWNrOiB0cnVlIH0pLAogICAgZm9ybWF0LnNwbGF0KCksCiAgICBmb3JtYXQuanNvbigpCiAgKSwKICBkZWZhdWx0TWV0YTogeyBzZXJ2aWNlOiAneW91ci1zZXJ2aWNlLW5hbWUnIH0sCiAgdHJhbnNwb3J0czogWwogICAgLy8KICAgIC8vIC0gV3JpdGUgdG8gYWxsIGxvZ3Mgd2l0aCBsZXZlbCBgaW5mb2AgYW5kIGJlbG93IHRvIGBjb21iaW5lZC5sb2dgCiAgICAvLyAtIFdyaXRlIGFsbCBsb2dzIGVycm9yIChhbmQgYmVsb3cpIHRvIGBlcnJvci5sb2dgLgogICAgLy8KICAgIG5ldyB0cmFuc3BvcnRzLkZpbGUoeyAKICAgICAgZmlsZW5hbWU6ICdxdWljay1zdGFydC1lcnJvci5sb2cnLCAKICAgICAgbGV2ZWw6ICdlcnJvcicKICAgIH0pLAogICAgbmV3IHRyYW5zcG9ydHMuRmlsZSh7IAogICAgICBmaWxlbmFtZTogJ3F1aWNrLXN0YXJ0LWNvbWJpbmVkLmxvZycKICAgIH0pCiAgXQp9KTsKCi8vCi8vIElmIHdl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nJvciBpbnN0YW5jZXMKLy8gKioqKioqKioqKioqKioqCgpsb2dnZXIud2FybihuZXcgRXJyb3IoJ0Vycm9yIHBhc3NlZCBhcyBpbmZvJykpOwpsb2dnZXIubG9nKCdlcnJvcicsIG5ldyBFcnJvcignRXJyb3IgcGFzc2VkIGFzIG1lc3NhZ2UnKSk7Cgpsb2dnZXIud2FybignTWF5YmUgaW1wb3J0YW50IGVycm9yOiAnLCBuZXcgRXJyb3IoJ0Vycm9yIHBhc3NlZCBhcyBtZXRhJykpOwpsb2dnZXIubG9nKCdlcnJvcicsICdJbXBvcnRhbnQgZXJyb3I6ICcsIG5ldyBFcnJvcignRXJyb3IgcGFzc2VkIGFzIG1ldGEnKSk7Cgpsb2dnZXIuZXJyb3IobmV3IEVycm9yKCdFcnJvciBhcyBpbmZvJykpOwo="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
const { createLogger, format, transports } = require('winston');

const logger = createLogger({
  level: 'info',
  format: format.combine(
    format.timestamp({
      format: 'YYYY-MM-DD HH:mm:ss'
    }),
    format.errors({ stack: true }),
    format.splat(),
    format.json()
  ),
  defaultMeta: { service: 'your-service-name' },
  transports: [
    //
    // - Write to all logs with level `info` and below to `combined.log`
    // - Write all logs error (and below) to `error.log`.
    //
    new transports.File({ 
      filename: 'quick-start-error.log', 
      level: 'error'
    }),
    new transports.File({ 
      filename: 'quick-start-combined.log'
    })
  ]
});

//
// If we're not in production then **ALSO** log to the `console`
// with the colorized simple format.
//
if (process.env.NODE_ENV !== 'production') {
  logger.add(new transports.Console({
    format: format.combine(
      format.colorize(),
      format.simple()
    )
  }));
}

// ***************
// Allows for JSON logging
// ***************

logger.log({
  level: 'info',
  message: 'Pass an object and this works',
  additional: 'properties',
  are: 'passed along'
});

logger.info({
  message: 'Use a helper method if you want',
  additional: 'properties',
  are: 'passed along'
});

// ***************
// Allows for parameter-based logging
// ***************

logger.log('info', 'Pass a message and this works', {
  additional: 'properties',
  are: 'passed along'
});

logger.info('Use a helper method if you want', {
  additional: 'properties',
  are: 'passed along'
});

// ***************
// Allows for string interpolation
// ***************

// info: test message my string {}
logger.log('info', 'test message %s', 'my string');

// info: test message my 123 {}
logger.log('info', 'test message %d', 123);

// info: test message first second {number: 123}
logger.log('info', 'test message %s, %s', 'first', 'second', { number: 123 });

// prints "Found error at %s"
logger.info('Found %s at %s', 'error', new Date());
logger.info('Found %s at %s', 'error', new Error('chill winston'));
logger.info('Found %s at %s', 'error', /WUT/);
logger.info('Found %s at %s', 'error', true);
logger.info('Found %s at %s', 'error', 100.00);
logger.info('Found %s at %s', 'error', ['1, 2, 3']);

// ***************
// Allows for logging Error instances
// ***************

logger.warn(new Error('Error passed as info'));
logger.log('error', new Error('Error passed as message'));

logger.warn('Maybe important error: ', new Error('Error passed as meta'));
logger.log('error', 'Important error: ', new Error('Error passed as meta'));

logger.error(new Error('Error as info'));
node v10.16.0