Skip to content
This repository was archived by the owner on Mar 11, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
extends:
- 'eslint:recommended'
- 'plugin:node/recommended'
- prettier
plugins:
- node
- prettier
rules:
prettier/prettier: error
block-scoped-var: error
eqeqeq: error
no-warning-comments: warn
Expand Down
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/*
samples/node_modules/*
src/**/doc/*
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
bracketSpacing: false
printWidth: 80
semi: true
singleQuote: true
tabWidth: 2
trailingComma: es5
useTabs: false
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
"lint": "gts check && eslint samples/",
"check": "gts check",
"clean": "gts clean",
"compile": "tsc -p . && cp -r src/v2 build/src/v2 && cp -r protos build",
"fix": "gts fix && gts fix samples/*.js samples/test/*.js",
"compile": "tsc -p . && cp -r src/v2 build/src/v2 && cp -r protos build && cp test/*.js build/test",
"fix": "gts fix && eslint --fix 'samples/*.js' 'samples/**/*.js'",
"prepare": "npm run compile",
"pretest": "npm run compile",
"posttest": "npm run check"
Expand Down Expand Up @@ -110,7 +110,9 @@
"bignumber.js": "^7.2.1",
"codecov": "^3.0.4",
"eslint": "^5.4.0",
"eslint-config-prettier": "^3.1.0",
"eslint-plugin-node": "^8.0.0",
"eslint-plugin-prettier": "^3.0.0",
"gts": "^0.8.0",
"ink-docstrap": "git+https://github.com/docstrap/docstrap.git",
"intelli-espower-loader": "^1.0.1",
Expand All @@ -119,6 +121,7 @@
"nock": "^10.0.1",
"nyc": "^13.0.1",
"power-assert": "^1.6.0",
"prettier": "^1.15.1",
"proxyquire": "^2.1.0",
"typescript": "~3.1.0",
"uuid": "^3.3.2"
Expand Down
276 changes: 145 additions & 131 deletions samples/logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,25 @@ function writeLogEntry(logName) {
const entry = log.entry({resource: resource}, 'Hello, world!');

// A structured log entry
const secondEntry = log.entry({resource: resource}, {
name: 'King Arthur',
quest: 'Find the Holy Grail',
favorite_color: 'Blue',
});
const secondEntry = log.entry(
{resource: resource},
{
name: 'King Arthur',
quest: 'Find the Holy Grail',
favorite_color: 'Blue',
}
);

// Save the two log entries. You can write entries one at a time, but it is
// best to write multiple entires together in a batch.
log.write([entry, secondEntry])
.then(() => {
console.log(`Wrote to ${logName}`);
})
.catch(err => {
console.error('ERROR:', err);
});
log
.write([entry, secondEntry])
.then(() => {
console.log(`Wrote to ${logName}`);
})
.catch(err => {
console.error('ERROR:', err);
});
// [END logging_write_log_entry]
}

Expand Down Expand Up @@ -84,13 +88,14 @@ function writeLogEntryAdvanced(logName, options) {

// See
// https://googlecloudplatform.github.io/google-cloud-node/#/docs/logging/latest/logging/log?method=write
log.write(entry)
.then(() => {
console.log(`Wrote to ${logName}`);
})
.catch(err => {
console.error('ERROR:', err);
});
log
.write(entry)
.then(() => {
console.log(`Wrote to ${logName}`);
})
.catch(err => {
console.error('ERROR:', err);
});
// [END logging_write_log_entry_advanced]
}

Expand All @@ -112,19 +117,20 @@ function listLogEntries(logName) {
// List the most recent entries for a given log
// See
// https://googlecloudplatform.github.io/google-cloud-node/#/docs/logging/latest/logging?method=getEntries
log.getEntries()
.then(results => {
const entries = results[0];

console.log('Logs:');
entries.forEach(entry => {
const metadata = entry.metadata;
console.log(`${metadata.timestamp}:`, metadata[metadata.payload]);
});
})
.catch(err => {
console.error('ERROR:', err);
log
.getEntries()
.then(results => {
const entries = results[0];

console.log('Logs:');
entries.forEach(entry => {
const metadata = entry.metadata;
console.log(`${metadata.timestamp}:`, metadata[metadata.payload]);
});
})
.catch(err => {
console.error('ERROR:', err);
});
// [END logging_list_log_entries]
}

Expand Down Expand Up @@ -155,19 +161,20 @@ function listLogEntriesAdvanced(filter, pageSize, orderBy) {

// See
// https://googlecloudplatform.github.io/google-cloud-node/#/docs/logging/latest/logging?method=getEntries
logging.getEntries(options)
.then(results => {
const entries = results[0];

console.log('Logs:');
entries.forEach(entry => {
const metadata = entry.metadata;
console.log(`${metadata.timestamp}:`, metadata[metadata.payload]);
});
})
.catch(err => {
console.error('ERROR:', err);
logging
.getEntries(options)
.then(results => {
const entries = results[0];

console.log('Logs:');
entries.forEach(entry => {
const metadata = entry.metadata;
console.log(`${metadata.timestamp}:`, metadata[metadata.payload]);
});
})
.catch(err => {
console.error('ERROR:', err);
});
// [START logging_list_log_entries_advanced]
}

Expand All @@ -190,95 +197,102 @@ function deleteLog(logName) {
// Note that a deletion can take several minutes to take effect.
// See
// https://googlecloudplatform.github.io/google-cloud-node/#/docs/logging/latest/logging/log?method=delete
log.delete()
.then(() => {
console.log(`Deleted log: ${logName}`);
})
.catch(err => {
console.error('ERROR:', err);
});
log
.delete()
.then(() => {
console.log(`Deleted log: ${logName}`);
})
.catch(err => {
console.error('ERROR:', err);
});
// [END logging_delete_log]
}

require(`yargs`)
.demand(1)
.command(
'list',
'Lists log entries, optionally filtering, limiting, and sorting results.',
{
filter: {
alias: 'f',
type: 'string',
requiresArg: true,
description: 'Only log entries matching the filter are written.',
},
limit: {
alias: 'l',
type: 'number',
requiresArg: true,
description: 'Maximum number of results to return.',
},
sort: {
alias: 's',
type: 'string',
requiresArg: true,
description: 'Sort results.',
},
},
opts => {
listLogEntriesAdvanced(opts.filter, opts.limit, opts.sort);
})
.command(
'list-simple <logName>', 'Lists log entries.', {},
opts => listLogEntries(opts.logName))
.command(
'write <logName> <resource> <entry>',
'Writes a log entry to the specified log.', {},
opts => {
try {
opts.resource = JSON.parse(opts.resource);
} catch (err) {
console.error('"resource" must be a valid JSON string!');
return;
}

try {
opts.entry = JSON.parse(opts.entry);
} catch (err) {
console.error('"entry" must be a valid JSON string!');
return;
}

writeLogEntryAdvanced(opts.logName, opts);
})
.command(
'write-simple <logName>',
'Writes a basic log entry to the specified log.', {},
opts => {
writeLogEntry(opts.logName);
})
.command(
'delete <logName>', 'Deletes the specified Log.', {},
opts => {
deleteLog(opts.logName);
})
.example('node $0 list', 'List all log entries.')
.example(
'node $0 list -f "severity=ERROR" -s "timestamp" -l 2',
'List up to 2 error entries, sorted by timestamp ascending.')
.example(
`node $0 list -f 'logName="my-log"' -l 2`,
'List up to 2 log entries from the "my-log" log.')
.example(
'node $0 write my-log \'{"type":"gae_app","labels":{"module_id":"default"}}\' \'"Hello World!"\'',
'Write a string log entry.')
.example(
'node $0 write my-log \'{"type":"global"}\' \'{"message":"Hello World!"}\'',
'Write a JSON log entry.')
.example('node $0 delete my-log', 'Delete "my-log".')
.wrap(120)
.recommendCommands()
.epilogue(`For more information, see https://cloud.google.com/logging/docs`)
.help()
.strict()
.argv;
.demand(1)
.command(
'list',
'Lists log entries, optionally filtering, limiting, and sorting results.',
{
filter: {
alias: 'f',
type: 'string',
requiresArg: true,
description: 'Only log entries matching the filter are written.',
},
limit: {
alias: 'l',
type: 'number',
requiresArg: true,
description: 'Maximum number of results to return.',
},
sort: {
alias: 's',
type: 'string',
requiresArg: true,
description: 'Sort results.',
},
},
opts => {
listLogEntriesAdvanced(opts.filter, opts.limit, opts.sort);
}
)
.command('list-simple <logName>', 'Lists log entries.', {}, opts =>
listLogEntries(opts.logName)
)
.command(
'write <logName> <resource> <entry>',
'Writes a log entry to the specified log.',
{},
opts => {
try {
opts.resource = JSON.parse(opts.resource);
} catch (err) {
console.error('"resource" must be a valid JSON string!');
return;
}

try {
opts.entry = JSON.parse(opts.entry);
} catch (err) {
console.error('"entry" must be a valid JSON string!');
return;
}

writeLogEntryAdvanced(opts.logName, opts);
}
)
.command(
'write-simple <logName>',
'Writes a basic log entry to the specified log.',
{},
opts => {
writeLogEntry(opts.logName);
}
)
.command('delete <logName>', 'Deletes the specified Log.', {}, opts => {
deleteLog(opts.logName);
})
.example('node $0 list', 'List all log entries.')
.example(
'node $0 list -f "severity=ERROR" -s "timestamp" -l 2',
'List up to 2 error entries, sorted by timestamp ascending.'
)
.example(
`node $0 list -f 'logName="my-log"' -l 2`,
'List up to 2 log entries from the "my-log" log.'
)
.example(
'node $0 write my-log \'{"type":"gae_app","labels":{"module_id":"default"}}\' \'"Hello World!"\'',
'Write a string log entry.'
)
.example(
'node $0 write my-log \'{"type":"global"}\' \'{"message":"Hello World!"}\'',
'Write a JSON log entry.'
)
.example('node $0 delete my-log', 'Delete "my-log".')
.wrap(120)
.recommendCommands()
.epilogue(`For more information, see https://cloud.google.com/logging/docs`)
.help()
.strict().argv;
17 changes: 9 additions & 8 deletions samples/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,18 @@ const log = logging.log(logName);
const text = 'Hello, world!';
// The metadata associated with the entry
const metadata = {
resource: {type: 'global'}
resource: {type: 'global'},
};
// Prepares a log entry
const entry = log.entry(metadata, text);

// Writes the log entry
log.write(entry)
.then(() => {
console.log(`Logged: ${text}`);
})
.catch(err => {
console.error('ERROR:', err);
});
log
.write(entry)
.then(() => {
console.log(`Logged: ${text}`);
})
.catch(err => {
console.error('ERROR:', err);
});
// [END logging_quickstart]
Loading