Logs UI errors to a service provided in the configuration
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
1
down vote
favorite
As part of the project I am currently working on we want to log our UI component errors as well. I developed this package as a base.
It's a factory (basically, not sure if it's correctly a factory).
There is one function exposed configure that takes the parameters that each service (of the project) needs to supply and returns a logger; an object with four functions - debug, info, warn and error.
I am not sure if this is the right way to do it in javascript. Or in general. Is this how a factory should look? I have seen some that expose a function rather than an object that has a function on it but in my mind these two seem equivalent.
import uuid from 'uuid/v4';
import post from './post';
function requiredParam(param)
const requiredParamError = new Error(`Required parameter, "$param" is missing.`);
// preserve original stack trace
if (typeof Error.captureStackTrace === 'function')
Error.captureStackTrace(
requiredParamError,
requiredParam
);
throw requiredParamError;
const Logger =
configure: (
url = requiredParam('url'),
service = requiredParam('service'),
version = requiredParam('version'),
apigeeClientId = requiredParam('apigeeClientId')
) =>
const prepareForwardLogFunction = function prepareForwardLogFunction(logLevel)
return async function forwardLog(details, exception)
const payload =
...details,
service,
version,
loggername: 'UiLogger',
serviceType: 'reactjs',
level: logLevel,
eventType: logLevel === 'error' ? 'Exception' : 'Trace',
correlationId: uuid(),
timestamp: new Date(),
exception: exception !== undefined ? exception : null,
request: global.window.location.href
;
try
await post(url, payload, apigeeClientId);
catch (error)
console.warn('UI Logger failed:', url, payload, error ); // eslint-disable-line no-console
;
;
return
debug: prepareForwardLogFunction('debug'),
info: prepareForwardLogFunction('info'),
warn: prepareForwardLogFunction('warn'),
error: prepareForwardLogFunction('error')
;
;
export default Logger;
javascript logging factory-method
add a comment |Â
up vote
1
down vote
favorite
As part of the project I am currently working on we want to log our UI component errors as well. I developed this package as a base.
It's a factory (basically, not sure if it's correctly a factory).
There is one function exposed configure that takes the parameters that each service (of the project) needs to supply and returns a logger; an object with four functions - debug, info, warn and error.
I am not sure if this is the right way to do it in javascript. Or in general. Is this how a factory should look? I have seen some that expose a function rather than an object that has a function on it but in my mind these two seem equivalent.
import uuid from 'uuid/v4';
import post from './post';
function requiredParam(param)
const requiredParamError = new Error(`Required parameter, "$param" is missing.`);
// preserve original stack trace
if (typeof Error.captureStackTrace === 'function')
Error.captureStackTrace(
requiredParamError,
requiredParam
);
throw requiredParamError;
const Logger =
configure: (
url = requiredParam('url'),
service = requiredParam('service'),
version = requiredParam('version'),
apigeeClientId = requiredParam('apigeeClientId')
) =>
const prepareForwardLogFunction = function prepareForwardLogFunction(logLevel)
return async function forwardLog(details, exception)
const payload =
...details,
service,
version,
loggername: 'UiLogger',
serviceType: 'reactjs',
level: logLevel,
eventType: logLevel === 'error' ? 'Exception' : 'Trace',
correlationId: uuid(),
timestamp: new Date(),
exception: exception !== undefined ? exception : null,
request: global.window.location.href
;
try
await post(url, payload, apigeeClientId);
catch (error)
console.warn('UI Logger failed:', url, payload, error ); // eslint-disable-line no-console
;
;
return
debug: prepareForwardLogFunction('debug'),
info: prepareForwardLogFunction('info'),
warn: prepareForwardLogFunction('warn'),
error: prepareForwardLogFunction('error')
;
;
export default Logger;
javascript logging factory-method
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
As part of the project I am currently working on we want to log our UI component errors as well. I developed this package as a base.
It's a factory (basically, not sure if it's correctly a factory).
There is one function exposed configure that takes the parameters that each service (of the project) needs to supply and returns a logger; an object with four functions - debug, info, warn and error.
I am not sure if this is the right way to do it in javascript. Or in general. Is this how a factory should look? I have seen some that expose a function rather than an object that has a function on it but in my mind these two seem equivalent.
import uuid from 'uuid/v4';
import post from './post';
function requiredParam(param)
const requiredParamError = new Error(`Required parameter, "$param" is missing.`);
// preserve original stack trace
if (typeof Error.captureStackTrace === 'function')
Error.captureStackTrace(
requiredParamError,
requiredParam
);
throw requiredParamError;
const Logger =
configure: (
url = requiredParam('url'),
service = requiredParam('service'),
version = requiredParam('version'),
apigeeClientId = requiredParam('apigeeClientId')
) =>
const prepareForwardLogFunction = function prepareForwardLogFunction(logLevel)
return async function forwardLog(details, exception)
const payload =
...details,
service,
version,
loggername: 'UiLogger',
serviceType: 'reactjs',
level: logLevel,
eventType: logLevel === 'error' ? 'Exception' : 'Trace',
correlationId: uuid(),
timestamp: new Date(),
exception: exception !== undefined ? exception : null,
request: global.window.location.href
;
try
await post(url, payload, apigeeClientId);
catch (error)
console.warn('UI Logger failed:', url, payload, error ); // eslint-disable-line no-console
;
;
return
debug: prepareForwardLogFunction('debug'),
info: prepareForwardLogFunction('info'),
warn: prepareForwardLogFunction('warn'),
error: prepareForwardLogFunction('error')
;
;
export default Logger;
javascript logging factory-method
As part of the project I am currently working on we want to log our UI component errors as well. I developed this package as a base.
It's a factory (basically, not sure if it's correctly a factory).
There is one function exposed configure that takes the parameters that each service (of the project) needs to supply and returns a logger; an object with four functions - debug, info, warn and error.
I am not sure if this is the right way to do it in javascript. Or in general. Is this how a factory should look? I have seen some that expose a function rather than an object that has a function on it but in my mind these two seem equivalent.
import uuid from 'uuid/v4';
import post from './post';
function requiredParam(param)
const requiredParamError = new Error(`Required parameter, "$param" is missing.`);
// preserve original stack trace
if (typeof Error.captureStackTrace === 'function')
Error.captureStackTrace(
requiredParamError,
requiredParam
);
throw requiredParamError;
const Logger =
configure: (
url = requiredParam('url'),
service = requiredParam('service'),
version = requiredParam('version'),
apigeeClientId = requiredParam('apigeeClientId')
) =>
const prepareForwardLogFunction = function prepareForwardLogFunction(logLevel)
return async function forwardLog(details, exception)
const payload =
...details,
service,
version,
loggername: 'UiLogger',
serviceType: 'reactjs',
level: logLevel,
eventType: logLevel === 'error' ? 'Exception' : 'Trace',
correlationId: uuid(),
timestamp: new Date(),
exception: exception !== undefined ? exception : null,
request: global.window.location.href
;
try
await post(url, payload, apigeeClientId);
catch (error)
console.warn('UI Logger failed:', url, payload, error ); // eslint-disable-line no-console
;
;
return
debug: prepareForwardLogFunction('debug'),
info: prepareForwardLogFunction('info'),
warn: prepareForwardLogFunction('warn'),
error: prepareForwardLogFunction('error')
;
;
export default Logger;
javascript logging factory-method
edited Apr 29 at 3:31
200_success
123k14142399
123k14142399
asked Apr 28 at 21:12
Andreas Andreou
1521
1521
add a comment |Â
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f193166%2flogs-ui-errors-to-a-service-provided-in-the-configuration%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password