Comments (4)
@alexfedoseev Cool. I'll see if I'll find a way (and time) to make it happen.
from rescript-logger.
Looking good. Couple of suggestions.
- It makes sense to memoize platform value.
- You can do this to get rid of raw:
[@bs.val] external window: 'a = "window";
window->Js.typeof == "undefined"
from rescript-logger.
Hey, I wouldn't mind having UniversalLogger.re
that leverages current loggers but I'm not sure about details of environment detection and it'd be far low in my priorities list in the near future to make it happen. I would happily accept PR though!
from rescript-logger.
Ok, not yet a PR, but I made one kind of working PoC inside my app. It looks like this:
// Let's define a variant because it's pretty
type platform =
| Browser
| Node;
// Utilizes 'ugly' raw javascript tester function
// that simply checks if window is available
let getPlatform = () => {
let windowExists: unit => bool = [%raw
{|
function() {
if (typeof window === 'undefined') { return false; }
else return true;
}
|}
];
if (windowExists()) {
Browser;
} else {
Node;
};
};
// An universal wrapper module
module Log = {
let error = (loc: string, msg: string) =>
switch (getPlatform()) {
| Browser => BrowserLogger.error(loc, msg)
| Node => NodeLogger.error(loc, msg)
};
let info = (loc: string, msg: string) =>
switch (getPlatform()) {
| Browser => BrowserLogger.info(loc, msg)
| Node => NodeLogger.info(loc, msg)
};
let warn = (loc: string, msg: string) =>
switch (getPlatform()) {
| Browser => BrowserLogger.warn(loc, msg)
| Node => NodeLogger.warn(loc, msg)
};
};
from rescript-logger.
Related Issues (14)
- Extension nodes inside annotated reducer
- Upgrade to BuckleScript v6
- ppx behavior when BS_LOG env var doesn't exist
- Use of console.group prevents grouping of similar logs
- BrowserLogger does not map to Console API functions (error(), warn(), debug(), ...)
- Bug: @log does not work on cases prefixed with module name HOT 1
- Feature Request: A way of turning off generation of absolute path in js files HOT 4
- Handle Ppat_any
- Support for comas between arguments (so log calls with arguments can span one line, instead of several) HOT 6
- Handle Ppat_or
- Question: ppx arm64 on linux? (needed for docker on M1/M2 Mac)
- Windows build fails on CI
- ppx file is not created with .exe extension HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rescript-logger.