winston-google-spreadsheet

Log data into your Google Spreadsheet with [winston][0] logger modules.

winston-google-spreadsheet

Log data into your Google Spreadsheet with winston logger modules.

  var winston = require('winston');
  
  // 
  // Requiring `winston-google-spreadsheet` will expose  
  // `winston.transports.GoogleSpreadsheet` 
  // 
  require('winston-google-spreadsheet').GoogleSpreadsheet;
  
  winston.add(winston.transports.GoogleSpreadsheet, options);

This transport accepts the follow options:

  • fileId: (Default None) The file ID of Google Spreadsheet that you want to log.
  • sheetIdx: (Default 1) The worksheet index of the file.
  • accessToken: (Default None) The access token to the file.
  • level: (Default Info) Level of messages that this transport should log.
  • timezone: (Default Node) Specify timezone for log timestamp.

In addition for OAuth2, this module also accepts the following options.

  • refreshToken: (Default None) OAuth2 refresh token.
  • clientId: (Default None) OAuth2 client ID.
  • clientSecret: (Default None) OAuth2 client secret.

If you want to use client login, this module also accepts the following options.

  • email: (Default None) Your gmail address.
  • password: (Default None) Your gmail password.

Metadata: Logged as JSON literal in cell

fileId: A file ID is included in the URL of the file.

  $ npm install winston
  $ npm install winston-google-spreadsheet

Create a Google Spreadsheet in your Google Drive, then add timestamp, level, message and meta columns like this image.

const EMAIL = 'your@gmail.com';
const PASSWORD = 'your_password';
const FILE_ID = 'your_file_id';
 
var winston = require('winston');
require('winston-google-spreadsheet').GoogleSpreadSheet;
 
var ssLogger = new (winston.transports.GoogleSpreadsheet)({
      'email': EMAIL,
      'password': PASSWORD,
      'fileId' : FILE_ID,
      'level' : 'info'
    });
 
var logger = new (winston.Logger)({
  'transports': [ssLogger],
  'exceptionHandlers': [ssLogger],
  'exitOnError': true
});
 
logger.log('info', 'Test Log Message', { anything: 'This is metadata' });
const REFRESH_TOKEN = 'your_refresh_token';
const CLIENT_ID = 'your_client_id';
const CLIENT_SECRET = 'your_client_secret';
const FILE_ID = 'your_file_id';
 
var winston = require('winston');
require('winston-google-spreadsheet').GoogleSpreadSheet;
 
var ssLogger = new (winston.transports.GoogleSpreadsheet)({
  'fileId' : FILE_ID,
  'level' : 'info',
  'refreshToken': REFRESH_TOKEN,
  'clientId': CLIENT_ID,
  'clientSecret': CLIENT_SECRET
});
  
var logger = new (winston.Logger)({
  'transports': [ssLogger],
  'exceptionHandlers': [ssLogger],
  'exitOnError': true
});
 
logger.log('info', 'Test Log Message', { anything: 'This is metadata' });

If you send your log data from in different time zones, you can specify time zone for log timestamp.

var ssLogger = new (winston.transports.GoogleSpreadsheet)({
  'fileId' : FILE_ID,
  'level' : 'info',
  'timezone': 'America/Los_Angeles'  // Asia/Tokyo etc. 
});

See more detailed explain at http://masashi-k.blogspot.com/2013/08/logging-data-into-google-spreadsheet.html

Author: Masashi Katsumata