winston-google-spreadsheet
Log data into your Google Spreadsheet with winston logger modules.
Usage
var winston = ;//// Requiring `winston-google-spreadsheet` will expose// `winston.transports.GoogleSpreadsheet`//GoogleSpreadsheet;winston;
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.
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.
Client Login
const EMAIL = 'your@gmail.com';const PASSWORD = 'your_password';const FILE_ID = 'your_file_id';var winston = ;GoogleSpreadSheet;var ssLogger = new winstontransportsGoogleSpreadsheet'email': EMAIL'password': PASSWORD'fileId' : FILE_ID'level' : 'info';var logger = new winstonLogger'transports': ssLogger'exceptionHandlers': ssLogger'exitOnError': true;logger;
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 = ;GoogleSpreadSheet;var ssLogger = new winstontransportsGoogleSpreadsheet'fileId' : FILE_ID'level' : 'info''refreshToken': REFRESH_TOKEN'clientId': CLIENT_ID'clientSecret': CLIENT_SECRET;var logger = new winstonLogger'transports': ssLogger'exceptionHandlers': ssLogger'exitOnError': true;logger;
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 winstontransportsGoogleSpreadsheet'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