Skip to content

Commit bb25ee5

Browse files
acidicXAlexZeitler
authored andcommitted
feat: add timestamps option to log output
1 parent 0eef3a1 commit bb25ee5

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export type DockerComposeConfigVolumesResult = {
6565

6666
export interface IDockerComposeLogOptions extends IDockerComposeOptions {
6767
follow?: boolean
68+
timestamps?: boolean
6869
}
6970

7071
export interface IDockerComposeBuildOptions extends IDockerComposeOptions {
@@ -675,10 +676,13 @@ export const logs = function (
675676
services: string | string[],
676677
options: IDockerComposeLogOptions = {}
677678
): Promise<IDockerComposeResult> {
678-
let args = Array.isArray(services) ? services : [services]
679+
const args = Array.isArray(services) ? services : [services]
679680

680681
if (options.follow) {
681-
args = ['--follow', ...args]
682+
args.unshift('--follow')
683+
}
684+
if (options.timestamps) {
685+
args.unshift('--timestamps')
682686
}
683687

684688
return execCompose('logs', args, options)

test/compose.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,18 @@ describe('logs command', (): void => {
890890
expect(std.out.includes('compose_test_proxy')).toBeTruthy()
891891
await compose.downAll({ cwd: path.join(__dirname), log: logOutput })
892892
})
893+
894+
it('does include timestamps', async (): Promise<void> => {
895+
await compose.upAll({ cwd: path.join(__dirname), log: logOutput })
896+
const std = await compose.logs('proxy', {
897+
cwd: path.join(__dirname),
898+
log: logOutput,
899+
timestamps: true
900+
})
901+
902+
expect(std.out.includes('compose_test_proxy')).toBeTruthy()
903+
await compose.downAll({ cwd: path.join(__dirname), log: logOutput })
904+
})
893905
})
894906

895907
describe('port command', (): void => {

0 commit comments

Comments
 (0)