You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Previous solution where only the logger function is configured had a
potential drawback - all log messages needed to be constructed even
when user is only interested in a certain log level. E.g. debug
messages that stringify returned values had to be created even if user
is only interested in 'info' level.
This commit addresses the problem by making the log level configurable.
Driver configuration now looks like:
```
const config = {
logging: {
level: 'debug',
logger: (level, message) => console.log(level + ' ' + message)
}
};
const driver = neo4j.driver(
'bolt://localhost',
neo4j.auth.basic('neo4j', 'password'),
config
);
```
to enable logging of all currently supported log levels.
Levels have priorities like:
```
error: 0
warn: 1
info: 2
debug: 3
```
Enabling a certain level also enables logging of all levels with lower
priorities. When 'info' is enabled, logger will output 'error', 'warn',
'info' but not 'debug'. Level configuration is optional, 'info' is the
default value.
Copy file name to clipboardExpand all lines: src/v1/index.js
+27-12Lines changed: 27 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -69,11 +69,17 @@ const auth = {
69
69
constUSER_AGENT="neo4j-javascript/"+VERSION;
70
70
71
71
/**
72
-
* Object containing predefined logger implementations. These are expected to be used as values of the driver config's <code>logger</code> property.
73
-
* @property {function(level: string, message: string)} console the logger function that outputs timestamp, log level and message to <code>console.log()</code>
72
+
* Object containing predefined logging configurations. These are expected to be used as values of the driver config's <code>logging</code> property.
73
+
* @property {function(level: ?string): object} console the function to create a logging config that prints all messages to <code>console.log</code> with
74
+
* timestamp, level and message. It takes an optional <code>level</code> parameter which represents the maximum log level to be logged. Default value is 'info'.
* // Specify the logging configuration for the driver. Object should have two properties <code>level</code> and <code>logger</code>.
191
+
* //
192
+
* // Property <code>level</code> represents the logging level which should be one of: 'error', 'warn', 'info' or 'debug'. This property is optional and
193
+
* // its default value is 'info'. Levels have priorities: 'error': 0, 'warn': 1, 'info': 2, 'debug': 3. Enabling a certain level also enables all
194
+
* // levels with lower priority. For example: 'error', 'warn' and 'info' will be logged when 'info' level is configured.
195
+
* //
196
+
* // Property <code>logger</code> represents the logging function which will be invoked for every log call with an acceptable level. The function should
197
+
* // take two string arguments <code>level</code> and <code>message</code>. The function should not execute any blocking or long-running operations
198
+
* // because it is often executed on a hot path.
199
+
* //
200
+
* // No logging is done by default. See <code>neo4j.logging</code> object that contains predefined logging implementations.
0 commit comments