/* * Copyright (c) 2015 Nordic Semiconductor ASA * * SPDX-License-Identifier: LicenseRef-Nordic-4-Clause */ import React from 'react'; import formatDate from 'date-fns/format'; import { type LogEntry } from 'winston'; import { openUrl } from '../utils/open'; import './log-entry.scss'; const regex = /(.*?)(https?:\/\/[^\s]+)/g; /** * Convert strings to array of strings and JSX tags for hrefs * * E.g. 'For reference see: https://github.com/example/doc.md or reboot Windows.' * will be converted to: * [ * 'For reference see: ', * https://github.com/example/doc.md, * ' or reboot Windows.', * ] * * @param {string} str input string * @returns {Array} strings and JSX tags */ function hrefReplacer(str: string) { const message = []; const remainder = str.replace(regex, (_match, before, href, index) => { message.push(before); message.push( openUrl(href)} onKeyPress={() => {}} > {href} , ); return ''; }); message.push(remainder); return message; } export default ({ entry }: { entry: LogEntry }) => { const className = `core19-log-entry core19-log-level-${entry.level}`; const time = formatDate(new Date(entry.timestamp), 'HH:mm:ss.SSS'); return (