Skip to content

Commit

Permalink
fix: respect Winston Formatters
Browse files Browse the repository at this point in the history
  • Loading branch information
liboz committed Nov 11, 2020
1 parent f1f65c2 commit 7c6069f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {LEVEL} from 'triple-beam';
import {LEVEL, MESSAGE} from 'triple-beam';
import TransportStream = require('winston-transport');

import {LOGGING_TRACE_KEY as COMMON_TRACE_KEY, LoggingCommon} from './common';
Expand Down Expand Up @@ -174,12 +174,18 @@ export class LoggingWinston extends TransportStream {
log(info: any, callback: Callback) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const {message, level, splat, stack, ...metadata} = info;
const formattedMessage = info[MESSAGE] ?? message;

// If the whole message is an error we have to manually copy the stack into
// metadata. Errors dont have enumerable properties so they don't
// destructure.
if (stack) metadata.stack = stack;
this.common.log(info[LEVEL] || level, message, metadata || {}, callback);
this.common.log(
info[LEVEL] || level,
formattedMessage,
metadata || {},
callback
);
}
}

Expand Down

0 comments on commit 7c6069f

Please sign in to comment.