winston-google-spreadsheet

0.0.5 • Public • Published

winston-google-spreadsheet

Log data into your Google Spreadsheet with winston logger modules.

Usage

  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. image2

Installation

Installing winston-google-spreadsheet

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

Create a log file

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

image1

Client Login

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' });

OAuth2

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' });

Change time zone

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

Readme

Keywords

none

Package Sidebar

Install

npm i winston-google-spreadsheet

Weekly Downloads

59

Version

0.0.5

License

none

Last publish

Collaborators

  • wf9a5m75