Created
August 25, 2018 22:06
-
-
Save hamed-farag/e4470b1b8e52cb5da929a833f0d21ab1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
export default WrapperComponent => { | |
const _logType = { | |
warn: "warn", | |
error: "error", | |
info: "info" | |
}; | |
let _logging = { | |
info: function(logTypeName, filePath, description) { | |
// Console.info, Calling API to log it, winston-client, loglevel library or your custom code | |
}, | |
warn: function(logTypeName, filePath, description) { | |
// Console.warn, Calling API to log it, winston-client, loglevel library or your custom code | |
}, | |
error: function(logTypeName, filePath, description) { | |
// Console.error, Calling API to log it, winston-client, loglevel library or your custom code | |
} | |
}; | |
let logging = function(logType = "info", logTypeName, filePath, description) { | |
switch (logType.toLowerCase()) { | |
case _logType.info: | |
_logging.info(logTypeName, filePath, description); | |
break; | |
case _logType.warn: | |
_logging.warn(logTypeName, filePath, description); | |
break; | |
case _logType.error: | |
_logging.error(logTypeName, filePath, description); | |
break; | |
default: | |
break; | |
} | |
}; | |
return function(props) { | |
return ( | |
<WrapperComponent | |
{...props} | |
logging={{ log: logging, type: { ..._logType } }} | |
/> | |
); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to use it?
import React from "react";
import withLogging from "../HOC/loggingHOC";
class Home extends React.PureComponent {
render() {
const { logging: {log, type} } = this.props;
log(type.warn, 'TypeWarn', 'app/components/Usercard.jsx', 'This Warning to be Handled bla bla bla')
return <span>Hello World!</span>;
}
}
export default withLogging(Home);