Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function createLogger() {
// Use Bunyan logger connected to StackDriver if GCP credentials are present.
if (hasGCloudKey) {
const consoleLogger = new ConsoleLogger();
const stackDriverLogger = new StackdriverBunyan({ keyFilename: GCLOUD_KEY_PATH });
return Bunyan.createLogger({
name: 'kotoba-bot',
streams: [
stackDriverLogger.stream('info'),
consoleLogger.stream('info'),
],
});
}
return undefined; // Use default console logger
}
'use strict';
// [START logging_bunyan_quickstart]
const bunyan = require('bunyan');
const production = process.env.NODE_ENV === 'production';
const streams = [{
stream: process.stdout,
level: 'info'
}];
if (production) {
// 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();
streams.push(loggingBunyan.stream('info'));
}
// 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: 'frontend',
streams
});
module.exports = logger;
export default function create() {
if (!config.google.credentials) {
return null;
}
const gcloudStream = new LoggingBunyan({
name: 'turtle',
resource: {
type: 'generic_node',
labels: {
node_id: config.hostname,
location: '', // default value
namespace: '', // default value
},
},
});
return {
level: config.logger.level,
type: 'raw',
stream: gcloudStream,
};
}
* distributed under the License is distributed on an "AS IS" BASIS,
* 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.
*/
'use strict';
// [START logging_bunyan_quickstart]
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: 'my-service',
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'),
],
});
// Writes some log entries
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
// sample-metadata:
// title: Explict Auth Setup
/* eslint-disable no-unused-vars */
// [START logging_bunyan_setup_explicit]
// Imports the Google Cloud client library for Bunyan
const {LoggingBunyan} = require('@google-cloud/logging-bunyan');
// Creates a client
const loggingBunyan = new LoggingBunyan({
projectId: 'your-project-id',
keyFilename: '/path/to/key.json',
});
// [END logging_bunyan_setup_explicit]
/* eslint-enable no-unused-vars */
* distributed under the License is distributed on an "AS IS" BASIS,
* 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.
*/
'use strict';
// [START logging_bunyan_quickstart]
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: 'shortlink',
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'),
],
});
module.exports = logger;
NODE_ENV,
GAE_INSTANCE,
GCLOUD_PROJECT,
GAE_VERSION,
GAE_SERVICE,
DISABLE_GAE_LOG,
} = process.env;
if (!NODE_ENV || NODE_ENV === 'development') {
streams.push({
type: 'raw',
stream: bunyanDebugStream({ forceColor: true, basepath: process.cwd() }),
});
}
if (GAE_INSTANCE && !DISABLE_GAE_LOG) {
const GAELogger = new LoggingBunyan({
logName: 'mwp_log',
resource: {
type: 'gae_app',
labels: {
project_id: GCLOUD_PROJECT,
module_id: GAE_SERVICE,
version_id: GAE_VERSION,
},
},
serviceContext: {
service: GAE_SERVICE,
version: GAE_VERSION,
},
});
GAELogger.on('error', err => console.error(err));
NODE_ENV,
GAE_INSTANCE,
GCLOUD_PROJECT,
GAE_VERSION,
GAE_SERVICE,
DISABLE_GAE_LOG,
} = process.env;
if (!NODE_ENV || NODE_ENV === 'development') {
streams.push({
type: 'raw',
stream: bunyanDebugStream({ forceColor: true, basepath: process.cwd() }),
});
}
if (GAE_INSTANCE && !DISABLE_GAE_LOG) {
const GAELogger = new LoggingBunyan({
logName: 'mwp_log',
resource: {
type: 'gae_app',
labels: {
project_id: GCLOUD_PROJECT,
module_id: GAE_SERVICE,
version_id: GAE_VERSION,
},
},
serviceContext: {
service: GAE_SERVICE,
version: GAE_VERSION,
},
});
GAELogger.on('error', err => console.error(err));