Azure Storage transports for winston >= 3
.
npm install winston@next
npm install winston-azure-storage-transport
npm install azure-storage
const { AzureBlobTransport } = require('./index');
const { BlobService } = require('azure-storage');
const winston = require('winston');
const blobTransport = new AzureBlobTransport({
blobs: new BlobService(),
containerName: 'mylogs',
blobName: 'myappendblob',
});
const logger = winston.createLogger({
level: 'info',
format: winston.format.json(),
transports: [ blobTransport ],
});
You can write logs 'silently' so that calls to the logger do not block the callback chain. In this case, listen for 'error' events on your AzureBlobTransport to handle IO errors.
const blobTransport = new AzureBlobTransport({
blobs: new BlobService(),
containerName: 'mylogs',
blobName: 'myappendblob.log',
silent: true,
}).on('error', console.error);
You can customize the blob name using a callback function. The blob will be created if it does not exist.
const blobTransport = new AzureBlobTransport({
blobs: new BlobService(),
containerName: 'mylogs',
blobName: () => {
const d = new Date();
return [
d.getFullYear(),
d.getMonth() + 1,
d.getDate(),
'myappendblob.log',
].join('/');
},
});