Skip to content

Commit d2b447e

Browse files
furkansenharputlumustafaiman
authored andcommitted
Make OFF a log level
1 parent db8f841 commit d2b447e

File tree

16 files changed

+53
-91
lines changed

16 files changed

+53
-91
lines changed

code_samples/logging.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var LogLevel = require('hazelcast-client').LogLevel;
2121

2222
if (process.argv.length != 3) {
2323
console.log('Run as node logging.js [logger]');
24-
console.log('[logger]: winston/default/off');
24+
console.log('[logger]: winston/default');
2525
} else {
2626
var cfg = new Config.ClientConfig();
2727

src/HazelcastClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ export default class HazelcastClient {
9191
this.instanceName = 'hz.client_' + this.id;
9292
}
9393

94-
this.loggingService = new LoggingService(this.config.properties['hazelcast.logging'],
94+
this.loggingService = new LoggingService(this.config.customLogger,
9595
this.config.properties['hazelcast.logging.level'] as number);
9696
this.invocationService = new InvocationService(this);
9797
this.listenerService = new ListenerService(this);
98-
this.serializationService = new SerializationServiceV1(this.config.serializationConfig);
98+
this.serializationService = new SerializationServiceV1(this, this.config.serializationConfig);
9999
this.proxyManager = new ProxyManager(this);
100100
this.nearCacheManager = new NearCacheManager(this);
101101
this.partitionService = new PartitionService(this);

src/aggregation/AggregatorFactory.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ export class AggregatorFactory implements IdentifiedDataSerializableFactory {
5959
private logger: ILogger;
6060
private idToConstructor: { [id: number]: Aggregator<any> } = {};
6161

62-
constructor() {
62+
constructor(logger: ILogger) {
63+
this.logger = logger;
6364
this.idToConstructor[AggregatorFactory.COUNT] = CountAggregator;
6465
this.idToConstructor[AggregatorFactory.DOUBLE_AVG] = DoubleAverageAggregator;
6566
this.idToConstructor[AggregatorFactory.DOUBLE_SUM] = DoubleSumAggregator;

src/config/Config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {ReliableTopicConfig} from './ReliableTopicConfig';
2929
import {SerializationConfig} from './SerializationConfig';
3030
import {Statistics} from '../statistics/Statistics';
3131
import {LogLevel} from '..';
32+
import {ILogger} from '../logging/ILogger';
3233

3334
/**
3435
* Top level configuration object of Hazelcast client. Other configurations items are properties of this object.
@@ -46,7 +47,6 @@ export class ClientConfig {
4647
'hazelcast.invalidation.reconciliation.interval.seconds': 60,
4748
'hazelcast.invalidation.max.tolerated.miss.count': 10,
4849
'hazelcast.invalidation.min.reconciliation.interval.seconds': 30,
49-
'hazelcast.logging': 'default',
5050
'hazelcast.logging.level': LogLevel.INFO,
5151
};
5252

@@ -56,6 +56,7 @@ export class ClientConfig {
5656
instanceName: string;
5757
groupConfig: GroupConfig = new GroupConfig();
5858
networkConfig: ClientNetworkConfig = new ClientNetworkConfig();
59+
customLogger: ILogger;
5960
customCredentials: any = null;
6061
listeners: ListenerConfig = new ListenerConfig();
6162
listenerConfigs: ImportConfig[] = [];

src/config/Properties.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import {ILogger} from '../logging/ILogger';
1818

1919
export interface Properties {
20-
[prop: string]: string | number | boolean | ILogger;
20+
[prop: string]: Property;
2121
}
2222

2323
export type Property = string | number | boolean | ILogger;

src/logging/ILogger.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,50 +23,50 @@ export interface ILogger {
2323

2424
/**
2525
* Logs a message with an associated objectName and furtherInfo at the given level.
26-
* @param {LogLevel} the log level
27-
* @param {string} the object in which the message is logged
28-
* @param {string} the message to log
29-
* @param further info about the log
26+
* @param level the log level
27+
* @param objectName name of the object in which the message is logged
28+
* @param message the message to log
29+
* @param furtherInfo further info about the log
3030
*/
3131
log(level: LogLevel, objectName: string, message: string, furtherInfo: any): void;
3232

3333
/**
3434
* Logs a message with an associated objectName and furtherInfo at the error level.
35-
* @param {string} the object in which the message is logged
36-
* @param {string} the message to log
37-
* @param further info about the log
35+
* @param objectName name of the object in which the message is logged
36+
* @param message the message to log
37+
* @param furtherInfo further info about the log
3838
*/
3939
error(objectName: string, message: string, furtherInfo?: any): void;
4040

4141
/**
4242
* Logs a message with an associated objectName and furtherInfo at the warn level.
43-
* @param {string} the object in which the message is logged
44-
* @param {string} the message to log
45-
* @param further info about the log
43+
* @param objectName name of the object in which the message is logged
44+
* @param message the message to log
45+
* @param furtherInfo further info about the log
4646
*/
4747
warn(objectName: string, message: string, furtherInfo?: any): void;
4848

4949
/**
5050
* Logs a message with an associated objectName and furtherInfo at the info level.
51-
* @param {string} the object in which the message is logged
52-
* @param {string} the message to log
53-
* @param further info about the log
51+
* @param objectName name of the object in which the message is logged
52+
* @param message the message to log
53+
* @param furtherInfo further info about the log
5454
*/
5555
info(objectName: string, message: string, furtherInfo?: any): void;
5656

5757
/**
5858
* Logs a message with an associated objectName and furtherInfo at the debug level.
59-
* @param {string} the object in which the message is logged
60-
* @param {string} the message to log
61-
* @param further info about the log
59+
* @param objectName name of the object in which the message is logged
60+
* @param message the message to log
61+
* @param furtherInfo further info about the log
6262
*/
6363
debug(objectName: string, message: string, furtherInfo?: any): void;
6464

6565
/**
6666
* Logs a message with an associated objectName and furtherInfo at the trace level.
67-
* @param {string} the object in which the message is logged
68-
* @param {string} the message to log
69-
* @param further info about the log
67+
* @param objectName name of the object in which the message is logged
68+
* @param message the message to log
69+
* @param furtherInfo further info about the log
7070
*/
7171
trace(objectName: string, message: string, furtherInfo?: any): void;
7272
}

src/logging/LoggingService.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {NoLogger} from './NoLogger';
1817
import {Property} from '../config/Properties';
1918
import {DefaultLogger} from './DefaultLogger';
2019
import {ILogger} from './ILogger';
2120

2221
export enum LogLevel {
22+
OFF = -1,
2323
ERROR = 0,
2424
WARN = 1,
2525
INFO = 2,
@@ -31,20 +31,20 @@ export class LoggingService {
3131

3232
private readonly logger: ILogger;
3333

34-
constructor(loggingProperty: Property, logLevel: number) {
35-
if (loggingProperty === 'off') {
36-
this.logger = new NoLogger();
37-
} else if (loggingProperty === 'default') {
34+
constructor(customLogger: ILogger, logLevel: number) {
35+
if (customLogger == null) {
3836
this.logger = new DefaultLogger(logLevel);
39-
} else if (this.isLogger(loggingProperty)) {
40-
this.logger = loggingProperty;
37+
} else if (this.isLogger(customLogger)) {
38+
this.logger = customLogger;
4139
} else {
42-
throw new RangeError('Logging type unknown: ' + loggingProperty);
40+
throw new RangeError('Logger should implement ILogger functions!');
4341
}
4442
}
4543

4644
isLogger(loggingProperty: Property): loggingProperty is ILogger {
47-
return (loggingProperty as ILogger).log !== undefined;
45+
loggingProperty = (loggingProperty as ILogger);
46+
return loggingProperty.log !== undefined && loggingProperty.error !== undefined && loggingProperty.warn !== undefined &&
47+
loggingProperty.info !== undefined && loggingProperty.debug !== undefined && loggingProperty.trace !== undefined;
4848
}
4949

5050
getLogger(): ILogger {

src/logging/NoLogger.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/nearcache/MetadataFetcher.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import HazelcastClient from '../HazelcastClient';
2222
import {Invocation} from '../invocation/InvocationService';
2323
import {PartitionService} from '../PartitionService';
2424
import {RepairingHandler} from './RepairingHandler';
25-
import ClientMessage = require('../ClientMessage');
2625
import {ILogger} from '../logging/ILogger';
26+
import ClientMessage = require('../ClientMessage');
2727

2828
export class MetadataFetcher {
2929

@@ -32,6 +32,7 @@ export class MetadataFetcher {
3232
private logger: ILogger;
3333

3434
constructor(client: HazelcastClient) {
35+
this.logger = client.getLoggingService().getLogger();
3536
this.client = client;
3637
this.partitionService = this.client.getPartitionService();
3738
}

src/proxy/BaseProxy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import ClientMessage = require('../ClientMessage');
2626
*/
2727
export class BaseProxy {
2828

29-
public client: HazelcastClient;
29+
protected client: HazelcastClient;
3030
protected name: string;
3131
protected serviceName: string;
3232

0 commit comments

Comments
 (0)