Skip to content
Open
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 CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## {{ UNRELEASED_VERSION }} - [{{ UNRELEASED_DATE }}]({{ UNRELEASED_LINK }})

* Added `--tail` option to `lando logs` command to allow users to specify the number of lines to show from the end of the logs for each service
* Added `--since` and `--until` options to `lando logs` command to allow users to specify a range of logs to show

## v3.24.0-beta.12 - [January 24, 2025](https://github.com/lando/core/releases/tag/v3.24.0-beta.12)

* Merged in improvements from `@lando/[email protected]`
Expand Down
9 changes: 8 additions & 1 deletion lib/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ const composeFlags = {
recreate: '--force-recreate',
removeOrphans: '--remove-orphans',
rm: '--rm',
since: '--since',
tail: '--tail',
timestamps: '--timestamps',
until: '--until',
volumes: '-v',
};

Expand All @@ -44,7 +47,11 @@ const mergeOpts = (run, opts = {}) => _.merge({}, defaultOptions[run], opts);
* Parse docker-compose options
*/
const parseOptions = (opts = {}) => {
const flags = _.map(composeFlags, (value, key) => _.get(opts, key, false) ? value : '');
const flags = _.map(composeFlags, (value, key) => {
const optValue = _.get(opts, key, false);
if (optValue === false) return '';
return optValue === true ? value : `${value}=${optValue}`;
});
const environment = _.flatMap(opts.environment, (value, key) => ['--env', `${key}=${value}`]);
const user = (_.has(opts, 'user')) ? ['--user', opts.user] : [];
const workdir = (_.has(opts, 'workdir')) ? ['--workdir', opts.workdir] : [];
Expand Down
1 change: 1 addition & 0 deletions lib/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ module.exports = class Engine {
* @param {Array} data.compose An Array of paths to Docker compose files
* @param {String} data.project A String of the project name (Usually this is the same as the app name)
* @param {Object} [data.opts] Options on how to build the `compose` objects containers.
* @param {String} [data.opts.tail='all'] Number of lines to tail.
* @param {Boolean} [data.opts.follow=false] Whether to follow the log. Works like `tail -f`.
* @param {Boolean} [data.opts.timestamps=true] Show timestamps in log.
* @return {Promise} A Promise.
Expand Down
17 changes: 16 additions & 1 deletion tasks/logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = lando => ({
usage: '$0 logs [--follow] [--service <service>...] [--timestamps]',
examples: [
'$0 logs',
'$0 logs --tail 10',
'$0 logs --follow --service appserver',
],
options: {
Expand All @@ -22,17 +23,31 @@ module.exports = lando => ({
alias: ['s'],
array: true,
},
since: {
describe: 'Show logs since timestamp (e.g. 2025-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)',
type: 'string',
},
tail: {
describe: 'Number of lines to show from the end of the logs for each service',
alias: ['n'],
default: 'all',
type: 'string',
},
timestamps: {
describe: 'Shows log timestamps',
alias: ['t'],
default: false,
boolean: true,
},
until: {
describe: 'Show logs before timestamp (e.g. 2025-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)',
type: 'string',
},
},
run: options => {
// Try to get our app
const app = lando.getApp(options._app.root);
const opts = _.pick(options, ['follow', 'timestamps', 'service']);
const opts = _.pick(options, ['follow', 'tail', 'timestamps', 'service', 'since', 'until']);
opts.services = opts.service;
if (app) return app.init().then(() => lando.engine.logs(_.merge(app, {opts})));
},
Expand Down
Loading