Skip to content

Commit

Permalink
Add stackdriver logging
Browse files Browse the repository at this point in the history
  • Loading branch information
boczeratul committed Apr 18, 2019
1 parent 52a4aed commit 484448a
Show file tree
Hide file tree
Showing 3 changed files with 808 additions and 18 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@cobinhood/web3": "1.0.0-beta.35",
"@dexon-foundation/truffle": "^5.0.15",
"@dexon-foundation/truffle-contract": "^4.0.12",
"@google-cloud/logging-bunyan": "^0.10.1",
"add-asset-html-webpack-plugin": "^3.1.3",
"babel-cli": "6.26.0",
"babel-core": "6.26.3",
Expand All @@ -44,6 +45,7 @@
"babel-preset-react": "6.24.1",
"babel-preset-stage-0": "6.24.1",
"bip39": "^3.0.0",
"bunyan": "^1.8.12",
"circular-dependency-plugin": "^5.0.2",
"css-loader": "0.28.11",
"eslint": "4.19.1",
Expand Down
26 changes: 25 additions & 1 deletion runTimer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,28 @@ const { mnemonic } = require('./secret');
const { address, times } = require('./constants');
const lottery = require('./build/contracts/Lottery.json');

const bunyan = require('bunyan');

// Imports the Google Cloud client library for Bunyan
const { LoggingBunyan } = require('@google-cloud/logging-bunyan');

// Creates a Bunyan Stackdriver Logging client
const loggingBunyan = new LoggingBunyan();

// Create a Bunyan logger that streams to Stackdriver Logging
// Logs will be written to: "projects/YOUR_PROJECT_ID/logs/bunyan_log"
const logger = bunyan.createLogger({
// The JSON payload of the log as it appears in Stackdriver Logging
// will contain "name": "my-service"
name: 'dexon-lottery',
streams: [
// Log to the console at 'info' and above
{ stream: process.stdout, level: 'info' },
// And log to Stackdriver Logging, logging at 'info' and above
loggingBunyan.stream('info'),
],
});

const web3 = new Web3('https://testnet-rpc.dexon.org');

let account;
Expand All @@ -21,7 +43,7 @@ const runTime = (time) => {
gas: 1000000,
});

console.log('Revealed for: ', time);
logger.info(`Revealed for: ${time}`);
};

mnemonicToSeed(mnemonic)
Expand All @@ -38,3 +60,5 @@ mnemonicToSeed(mnemonic)

times.forEach(runTime);
});

logger.info('Service started');
Loading

0 comments on commit 484448a

Please sign in to comment.