Skip to content

Commit

Permalink
SPRXCLT-12: use addDefaultFields logger API
Browse files Browse the repository at this point in the history
  • Loading branch information
Florent Monjalet committed Aug 3, 2023
1 parent 2485271 commit c96f133
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions lib/sproxyd.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,13 @@ class SproxydClient {
const isBatchDelete = key === '.batch_delete';
const newKey = key || keygen(this.cos, params);
const req = this._createRequestHeader(method, headers, newKey, params, log);
const logInfo = {
log.addDefaultFields({
component: 'sproxydclient',
method: '_handleRequest',
host,
key: newKey,
contentLength: size,
};
});

if (stream) {
let streamingStarted = false;
Expand All @@ -309,14 +309,14 @@ class SproxydClient {
err.retryable = true;
}
if (!voluntaryAbort) {
logInfo.error = err;
log.error('putting chunk to sproxyd', logInfo);
log.error('putting chunk to sproxyd', {error: err});
}
return callback(err);
}
// We return the key
logInfo.statusCode = response.statusCode;
log.debug('stored to sproxyd', logInfo);
log.debug('stored to sproxyd', {
statusCode: response.statusCode,
});
return callback(null, newKey);
});

Expand All @@ -325,11 +325,11 @@ class SproxydClient {
stream.pipe(request);
finished(stream, err => {
if (err) {
log.trace('readable stream aborted', logInfo);
log.trace('readable stream aborted');
request.abort();
voluntaryAbort = true;
} else {
log.trace('readable stream finished normally', logInfo);
log.trace('readable stream finished normally');
}
});
};
Expand All @@ -340,23 +340,23 @@ class SproxydClient {
request.on('socket', (socket) => {
// We can start streaming when reusing a socket
if (request.reusedSocket) {
log.trace('reusing existing socket', logInfo);
log.trace('reusing existing socket');
startPayloadStreaming();
} else {
// Otherwise, wait for a successful connection
socket.on('connect', () => {
log.trace('using a new socket', logInfo);
log.trace('using a new socket');
startPayloadStreaming();
});
}
});

request.on('finish', () => {
log.debug('finished sending PUT chunks to sproxyd', logInfo);
log.debug('finished sending PUT chunks to sproxyd');
});

stream.on('error', err => {
log.error('error from readable stream', logInfo);
log.error('error from readable stream');
});
} else {
headers['content-length'] = isBatchDelete ? size : 0;
Expand All @@ -367,19 +367,11 @@ class SproxydClient {
if (err) {
// non-streaming are always retryable;
err.retryable = true;
log.error('error sending sproxyd request', {
host,
error: err,
key: newKey,
method: '_handleRequest',
});
log.error('error sending sproxyd request', {error: err});
return callback(err);
}
log.debug('success sending sproxyd request', {
host,
statusCode: response.statusCode,
key: newKey,
method: '_handleRequest',
});
return callback(null, response);
});
Expand Down

0 comments on commit c96f133

Please sign in to comment.