Skip to content

Commit 4de623e

Browse files
committed
Fix audit logger logging to console even when disabled
1 parent 7e47e39 commit 4de623e

File tree

2 files changed

+15
-28
lines changed

2 files changed

+15
-28
lines changed

x-pack/plugins/security/server/audit/audit_service.test.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,6 @@ describe('#setup', () => {
7474
expect(logging.configure).toHaveBeenCalledWith(expect.any(Observable));
7575
});
7676

77-
it('does not configure logging when using legacy logger', async () => {
78-
new AuditService(logger).setup({
79-
license,
80-
config: {
81-
enabled: true,
82-
},
83-
logging,
84-
http,
85-
getCurrentUser,
86-
getSpaceId,
87-
});
88-
expect(logging.configure).not.toHaveBeenCalled();
89-
});
90-
9177
it('registers post auth hook', () => {
9278
new AuditService(logger).setup({
9379
license,
@@ -181,7 +167,7 @@ describe('#createLoggingConfig', () => {
181167
"appenders": Array [
182168
"auditTrailAppender",
183169
],
184-
"context": "audit",
170+
"context": "audit.ecs",
185171
"level": "info",
186172
},
187173
],

x-pack/plugins/security/server/audit/audit_service.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ export class AuditService {
6767
*/
6868
private allowAuditLogging = false;
6969

70-
constructor(private readonly logger: Logger) {}
70+
private ecsLogger: Logger;
71+
72+
constructor(private readonly logger: Logger) {
73+
this.ecsLogger = logger.get('ecs');
74+
}
7175

7276
setup({
7377
license,
@@ -83,16 +87,13 @@ export class AuditService {
8387
});
8488
}
8589

86-
// Do not change logging for legacy logger
87-
if (config.appender) {
88-
// Configure logging during setup and when license changes
89-
logging.configure(
90-
license.features$.pipe(
91-
distinctUntilKeyChanged('allowAuditLogging'),
92-
createLoggingConfig(config)
93-
)
94-
);
95-
}
90+
// Configure logging during setup and when license changes
91+
logging.configure(
92+
license.features$.pipe(
93+
distinctUntilKeyChanged('allowAuditLogging'),
94+
createLoggingConfig(config)
95+
)
96+
);
9697

9798
/**
9899
* Creates an {@link AuditLogger} scoped to the current request.
@@ -146,7 +147,7 @@ export class AuditService {
146147
},
147148
};
148149
if (filterEvent(meta, config.ignore_filters)) {
149-
this.logger.info(event.message!, meta);
150+
this.ecsLogger.info(event.message!, meta);
150151
}
151152
};
152153
return { log };
@@ -203,7 +204,7 @@ export const createLoggingConfig = (config: ConfigType['audit']) =>
203204
},
204205
loggers: [
205206
{
206-
context: 'audit',
207+
context: 'audit.ecs',
207208
level: config.enabled && config.appender && features.allowAuditLogging ? 'info' : 'off',
208209
appenders: ['auditTrailAppender'],
209210
},

0 commit comments

Comments
 (0)