Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getTransports(isDev) {
const transports = [];
if (!isDev) {
transports.push(new StackdriverTransport());
}
if (process.env.NODE_ENV === "test") {
// During testing, we just dump logging to a stream.
// This isn't used for anything at all right now, but we could use
// it for snapshot testing with some updates at some point.
const sink = new stream.Writable({write: () => {}});
// This is a hack to make our writable stream work $FlowFixMe
sink._write = sink.write;
transports.push(
new winston.transports.Stream({
format: getFormatters(isDev),
stream: sink,
}),
);
} else {
const winston = require('winston');
// Imports the Google Cloud client library for Winston
const { LoggingWinston } = require('@google-cloud/logging-winston');
const projectId = 'github-did';
const loggingWinston = new LoggingWinston({ projectId });
// Create a Winston logger that streams to Stackdriver Logging
// Logs will be written to: "projects/YOUR_PROJECT_ID/logs/winston_log"
const logger = winston.createLogger({
level: 'info',
transports: [
new winston.transports.Console(),
// Add Stackdriver Logging
loggingWinston,
],
});
logger.stream = {
write(message) {
logger.info(message);
},
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const {createLogger, format, transports} = require('winston');
const {LoggingWinston} = require('@google-cloud/logging-winston');
const logger = createLogger({
format: format.simple(),
level: 'debug',
transports: [new transports.Console()],
});
if ('environment' in process.env && process.env.environment === 'production') {
logger.add(new LoggingWinston());
}
module.exports = logger;