6.11.2 • Published 1 year ago

ut-log v6.11.2

Weekly downloads
19
License
Apache-2.0
Repository
github
Last release
1 year ago

ut-log

'ut-log' is a module aimed to provide logging functionality for the UT5 implementations. A basic log instance can be obtained with the following code:

var utLog = require('ut-log');
var utLogConfig = {
    type: 'bunyan',
    streams: [
        {
            level: 'trace',
            stream: 'process.stdout'
        }
    ]
};
var logFactory = new utLog(utLogConfig);
var log = logFactory.createLog('info', {name: 'a', context: 'b'});
  • ut-log module exposes a constructor for creating logFactory objects

  • The configuration object that the ut-log constructor accepts as an argument has to have properties type and streams (for bunyan) or transports (for winston) where:

    • type is a string specifying which vendor node module will be used for logging. The possible values are: bunyan or winston
    • streams (for bunyan) is an array of objects where each object specifies a single logging stream or transports (for winston) is an object of transports. For more information visit bunyan streams and winston transports
  • The logFactory object has a single method (createLog) which has to be called in order for a log instance to get obtained. logFactory.createLog method has 2 arguments: level and params

    • level is a string specifying the minimum logging level the logger will be able to log to. The possible values for this argument are: trace, debug, info, warn, error, fatal.

    Each log level has a weight and the priority of the levels is as listed above.

Once having the log instantiated it can be used to log data across all specified streams simultaneously (in this case only the NodeJS console through process.stdout). Logging itself happens by calling one of the log's methods (logFactory.createLog returns an object with each logging level assigned as a method). In our case, because we set 'info' as a minimum logging level, the 'log' object will be equipped with 4 methods:

  • log.info
  • log.warn
  • log.error
  • log.fatal

To log something, pass the data that needs to be log as an argument to some of the functions listed above. E.g:

log.info('log message');

Doing so will log the data to all specified streams with a minimum level equal to 'info' or higher. For optimal performance all log method calls should always be verified before being called so that changing the global logFactory object's minimum log level should not break the code and high volume log data will not occupy memory. I.e. logging should always happen like:

log.info && log.info('log message');

Multiple streams example:

var utLog = require('ut-log');
var level = require('level');
var path = require('path');
// stream constructors
var SocketStream = require('ut-log/socketStream');
var LevelDBStream = require('ut-log/leveldbStream');
var SentryStream = require('ut-log/sentryStream');
var LogRotateStream = require('ut-log/logRotateStream');

var utLogConfig = {
    type: 'bunyan',
    transformData: {
        // which field should be (hidden/overwritten with *) value from log
        id: 'hide'
    },
    streams: [
        {
            level: 'trace',
            stream: 'process.stdout'
        },
        {
            level: 'trace',
            stream: new SocketStream({
                host: '127.0.0.1',
                port: '30001',
                objectMode: true
            }),
            type: 'raw'
        },
        {
            level: 'trace',
            stream: new LevelDBStream({
                dbPath: './leveldbLogs'
            }),
            type: 'raw'
        },
        {
            level: 'error',
            stream: new SentryStream({
                dsn : 'http://b62b47864e93466cbb16a2b4a1d749b1:05968d770cdf4f8f8f09985d95ea9911@sentry.softwaregroup.com:49161/2',
                patchGlobal: true,
                logger: 'impl-test'
            }),
            type: 'raw'
        },
        {
            level: 'trace',
            stream: new LogRotateStream({
                path : path.join('logs', 'ut5_%Y-%m-%d.log'),
                symlink: path.join('logs', 'ut5.log'),
                compress: true
            })
        }
    ]
};
var logFactory = new utLog(utLogConfig);
var log = logFactory.createLog('info', {name: 'a', context: 'b'});

LogRotateStream options

path

A string file path with any of the below options to define rotation schedule:

e.g. ./logs/ut5-%Y-%m-%d.log would result in logs like ./logs/ut5-2015-07-06.log

  • %Y 4-digit year e.g. 2013
  • %m month (01..12)
  • %d day of month (01..31)
  • %x iso8601 date portion (e.g. 2012-09-24)
  • %h hour (00..23)
  • %M minute (00..59)
  • %S second (00..61)
  • %X iso8601 time portion to the second (e.g.: 15:12:47)
  • %I iso8601 date/time to the second (e.g. 2012-09-24T15:12:47)

symlink

A path to a symlink that will be maintained to point at the current log file.

compress

Boolean value, whether to gzip the files once they aren't being written to.

6.11.1

1 year ago

6.11.0

1 year ago

6.11.2

1 year ago

6.10.5

1 year ago

6.10.4

2 years ago

6.10.3

2 years ago

6.10.2

2 years ago

6.10.1

3 years ago

6.10.0

3 years ago

6.9.1

3 years ago

6.9.0

3 years ago

6.7.2

3 years ago

6.8.0

3 years ago

6.7.1

3 years ago

6.7.0

4 years ago

6.6.12

4 years ago

6.6.11

4 years ago

6.6.10

4 years ago

6.6.9

4 years ago

6.6.7

4 years ago

6.6.8

4 years ago

6.6.6

4 years ago

6.6.5

4 years ago

6.6.4

4 years ago

6.6.3

4 years ago

6.6.2

4 years ago

6.6.1

5 years ago

6.6.0

5 years ago

6.5.8

5 years ago

6.5.7

5 years ago

6.5.6

5 years ago

6.5.5

5 years ago

6.5.4

5 years ago

6.5.3

5 years ago

6.5.2

5 years ago

6.5.1

5 years ago

6.5.0

5 years ago

6.4.0

5 years ago

6.3.0

6 years ago

6.2.3

6 years ago

6.2.2

6 years ago

6.2.0

6 years ago

6.1.1

6 years ago

6.1.0

6 years ago

6.1.0-rc-bahur.6

6 years ago

6.1.0-rc-bahur.5

6 years ago

6.1.0-rc-bahur.4

6 years ago

6.1.0-rc-bahur.3

6 years ago

5.11.1

6 years ago

6.1.0-rc-bahur.2

6 years ago

6.1.0-rc-bahur.1

6 years ago

6.1.0-rc-bahur.0

6 years ago

6.0.1

6 years ago

6.0.0

6 years ago

6.0.0-ut6.11

6 years ago

6.0.0-ut6.10

6 years ago

6.0.0-ut6.9

6 years ago

6.0.0-ut6.8

6 years ago

6.0.0-ut6.7

6 years ago

6.0.0-ut6.6

6 years ago

6.0.0-ut6.5

6 years ago

6.0.0-ut6.4

6 years ago

6.0.0-ut6.3

6 years ago

6.0.0-ut6.2

6 years ago

6.0.0-ut6.1

6 years ago

6.0.0-ut6.0

7 years ago

5.11.0-rc.2

7 years ago

5.11.0

7 years ago

5.11.0-rc.1

7 years ago

5.11.0-rc.0

7 years ago

5.10.9

7 years ago

5.10.8

7 years ago

5.10.8-ws.1

7 years ago

5.10.8-ws.0

7 years ago

5.10.7

7 years ago

5.10.6

7 years ago

5.10.5

7 years ago

5.10.4

7 years ago

5.10.3

7 years ago

5.10.2

7 years ago

5.10.1

7 years ago

5.10.0

7 years ago

5.9.0

7 years ago

5.8.1

7 years ago

5.8.0

7 years ago

5.7.1

7 years ago

5.7.0

7 years ago

5.6.2

7 years ago

5.6.1

7 years ago

5.6.0

7 years ago

5.5.1

7 years ago

5.5.0

7 years ago

5.4.10

7 years ago

5.4.9

8 years ago

5.4.8

8 years ago

5.4.7

8 years ago

5.4.6

8 years ago

5.4.5

8 years ago

5.4.4

8 years ago