Skip to content
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
12 changes: 12 additions & 0 deletions src/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ export interface LogOptions {
*/
sinceSeconds?: number;

/**
* Only return logs after a specific date (RFC3339). Defaults to all logs.
* Only one of sinceSeconds or sinceTime may be specified.
*/
sinceTime?: string;

/**
* If set, the number of lines from the end of the logs to show. If not specified, logs are shown from the creation
* of the container or sinceSeconds or sinceTime
Expand Down Expand Up @@ -64,6 +70,12 @@ export function AddOptionsToSearchParams(
if (options?.sinceSeconds) {
searchParams.set('sinceSeconds', options?.sinceSeconds?.toString() || 'false');
}
if (options?.sinceTime) {
if (options?.sinceSeconds) {
throw new Error('at most one of sinceTime or sinceSeconds may be specified');
}
searchParams.set('sinceTime', options?.sinceTime);
}
if (options?.tailLines) {
searchParams.set('tailLines', options?.tailLines?.toString() || 'false');
}
Expand Down
21 changes: 19 additions & 2 deletions src/log_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { URLSearchParams } from 'url';
describe('Log', () => {
describe('AddOptionsToSearchParams', () => {
it('should add options to search params', () => {
const searchParams = new URLSearchParams();
const options: LogOptions = {
let searchParams = new URLSearchParams();
let options: LogOptions = {
follow: true,
limitBytes: 100,
pretty: true,
Expand All @@ -23,6 +23,12 @@ describe('Log', () => {
expect(searchParams.get('sinceSeconds')).to.equal('1');
expect(searchParams.get('tailLines')).to.equal('1');
expect(searchParams.get('timestamps')).to.equal('true');

const sinceTime = new Date().toISOString();
searchParams = new URLSearchParams();
options = { sinceTime };
AddOptionsToSearchParams(options, searchParams);
expect(searchParams.get('sinceTime')).to.equal(sinceTime);
});
it('should use defaults for', () => {
const searchParams = new URLSearchParams();
Expand All @@ -33,5 +39,16 @@ describe('Log', () => {
expect(searchParams.get('previous')).to.equal('false');
expect(searchParams.get('timestamps')).to.equal('false');
});
it('sinceTime and sinceSeconds cannot be used together', () => {
const searchParams = new URLSearchParams();
const sinceTime = new Date().toISOString();
const options: LogOptions = {
sinceSeconds: 1,
sinceTime,
};
expect(() => {
AddOptionsToSearchParams(options, searchParams);
}).to.throw('at most one of sinceTime or sinceSeconds may be specified');
});
});
});
Loading