After recent updates the log format in the console on react-native and maybe node apps, has become like:
This results after doing a simple console.log() call.
In previous versions the timestamp format was different, and a lot shorter. Is there a way to customize that date format?
I know what day is today, time only would save lots of space on my monitor.
I got no luck looking into the docs/source of react-native-cli.
Environment: npm 6.14.8, react 16.13.1, react-native 0.63.4
Searching a bit i found 3 ways to check logs:
Using android studio, the log format on the logcat can be changed using the settings icon, and you can remove the date
Using react-native log-android which formats differently the log using the logkitty package. example scrn of the log prefix outcome:
The default format on the metro bundler exists inside node_modules/metro/src/lib/formatLogTimestamp.js
It is currently (as of version 0.59):
module.exports = date =>
chalk.dim(
`[${date.toDateString()} ${date.toLocaleTimeString("en-US", {
hour12: false
})}.${String(date.getMilliseconds()).padEnd(3, "0")}] `
);
Change that to:
module.exports = date =>
chalk.dim(
`[${date.toLocaleTimeString("en-US", {
hour12: false
})}.${String(date.getMilliseconds()).padEnd(3, "0")}] `
);
After the change you need to restart metro,
and voila! you have only the time without the date.
(Obviously you need to make the change every time you remove/install the metro package)
Related
Is there a way to add a timestamp to when my bot logs something to the console?
For example, when it leaves a server, it says:
I have been removed from the guild: "Server"
And I want it to look something like [Day, Time]:
[May 10, 2022, 15:35] I have been removed from the guild: "Server"
You Can use log-timestamp npm package to do so!
steps:
type npm i log-timestamp in console.
paste it in your main index.js file!
require('log-timestamp')
all set! now you will get timestamp in every logging in console!
You can get Date and normalize it with simple module moment.js.
Install it on terminal with npm i moment.
const moment = require("moment")
moment.locale("en")
client.on("guildDelete", async guild => {
console.log(`[${moment(Date.now()).format("LLL")}] I have been removed from the guild: ${guild.name}`)
})
Use a custom log function (e.g. client.log()) instead of console.log(). This allows you to modify logs without changing global prototype (bad practice!)
Example of my TS discord bot's custom logger
It is thrown around as log on every function. Note this code is a little advanced, so it may confuse newer readers.
I am trying to get the current hour of the time which i try in this approach.
var currentTimeHour = dates.ZonedDateTime.now().getHour()
It did return value but it is zero while my time is 3pm. And i notice when the time turn to 4pm, the value return become one.
I did tried getMinute and getDay and it seems fine. Did i did anything wrong and is there anyway to get the hour of the current time?
Thanks.
dates.ZonedDateTime.now().getHour() is correct one to use.
Or you may want to use just dates.ZonedDateTime.now().time.hour
var myNow = dates.ZonedDateTime.now()
console.log('myNow', myNow)
var myHour = dates.ZonedDateTime.now().getHour()
console.log('myNow.getHour()', myHour)
Let's try the above code in JS file, and can see clearly the structure of now() in debug console. As the following screenshot.
First confirm the timezone is correct. IDE may change to a different timezone. This is the screenshot if I change IDE to Indiana timezone.
To confirm/change IDE timezone, use simulator -> User -> GPS/Clock override feature.
I'm using the admin-on-rest npm package starter project and trying to plug in a simple SSO Facebook login button using the FacebookAuth npm package. Every time I try to click the "Login" button, I get the following error:
FB.login() called before FB.init()
I'm using an .env file with the following variable: REACT_APP_FACEBOOK_APP_ID and setting it to the right value. I even did console.log() within my app and can see it output.
I checked and I'm only loading the FB SDK once, not multiple times (this was a common issue reported on other threads).
Ok, it turned out to be something pretty dumb, but something to point out nonetheless!
In my .env file, I had accidentally placed a semicolon (;) at the end of the declaration, like this:
REACT_APP_FACEBOOK_APP_ID = XXXXXXXXXXXX;
Apparently .env files do NOT like semi-colons. This was just very difficult to figure out from the error above.
So if any of you want to pull your hair out because of this issue, and you're using similar tech, check to make sure you're syntactically kosher EVERYWHERE variables are being declared.
the funny thing was i forgot to replace your-app-id with my app id:
<script>
FB.init({
appId: 'your-app-id',
autoLogAppEvents: true,
xfbml: true,
version: 'v8.0'
});
</script>
I am using the https://github.com/mikaelbr/node-notifier package to show notifications in shell.
This is my code:
var notifier = require('node-notifier');
var path = require('path');
notifier.notify({
title: 'My awesome title',
message: 'Hello from node, Mr. User!',
icon: path.join(__dirname, 'coulson.jpg'), // absolute path (not balloons)
sound: true, // Only Notification Center or Windows Toasters
wait: true // wait with callback until user action is taken on notification
}, function (err, response) {
// response is response from notification
});
notifier.on('click', function (notifierObject, options) {
// Happens if `wait: true` and user clicks notification
});
notifier.on('timeout', function (notifierObject, options) {
// Happens if `wait: true` and notification closes
});
The notification comes like this:
As you can see a terminal icon is coming before the name.
Can you help me how to remove that icon?
It is known issue with node-notifier.
From issue #71:
mikaelbr:
No, I'm afraid that's how the notification work, as it's the terminal that initiates the message. The only way to avoid this is to use your custom terminal-notifier where the Terminal icon is swapped for your own. It's not a big task, and you can easily set customPath for notification center reporter.
kurisubrooks:
This happens because of the way notifications in OS X work. The notification will show the referring app icon, and because we're using terminal-notifier to push notifications, we have the icon of terminal-notifier.
To work around this, you'll need to compile terminal-notifier with your own app.icns. Download the source, change out the AppIcon bundle with your own in Xcode, recompile terminal-notifier and pop it into node-notifier. (/node-notifier/vendor/terminal-notifier.app)
Now that you have your own terminal-notifier inside node-notifier, remove all the icon references from your OS X Notification Center code, and run the notification as if it has no icon. If the old app icon is showing in your notifications, you need to clear your icon cache. (Google how to do this)
Another valuable comment from mikaelb:
That's correct. But keep in mind, node-notifier uses a fork of terminal-notifier (github.com/mikaelbr/terminal-notifier) to add option to wait for notification to finish, so this should be used to add your own icon. A easy way to do it is to copy/paste from the vendor-folder and use customPath to point to your own vendor.
I tried #Aleksandr M's steps but it didn't seem to work for me. Maybe I didn't understand the steps well enough. Here's how it worked for me.
I cloned https://github.com/mikaelbr/terminal-notifier . Then opened the project with xcode and deleted the Terminal.icns file and replaced it with my custom icon Myicon.icns.
Then edited terminal-notifier/Terminal Notifier/Terminal Notifier-Info.plist by setting the key icon file to Myicon.
After doing this, simply building the project did NOT work. I had to change the values of the build version and build identifier (any new value would do) see this.
Afterwards I just built the project with xcode and then copied the built .app file (you can find it by clicking the Products directory of the project from xcode Products > right click the file > show in finder) to my electron project
e.g your final path may look like this. electron-project/vendor/terminal-notifier.app.
Then I set customPath as #Aleksandr M suggested.
Here's what mine looked like
var notifier = new NotificationCenter({
customPath: 'vendor/terminal-notifier.app/Contents/MacOS/terminal-notifier'
});
And THEN it worked! 🙂
This solved my problem and you only need to have your icns file ready:
run this command in terminal after downloading :customise-terminal-notifier
** path/customise-terminal-notifier-master/customise-terminal-notifier -i path/Terminal.icns -b com.bundle.identifier
im very new to nodejs but was wondering if the following was easily possible to achieve.
I use Gulp along with browser-sync plugin. I was wondering if there was a way to log every time the browser gets re-injected with the domain and time over a port range. The reason for this being I want to be able to plot productivity over projects without having to manually record this and this seems to be the most logical solution.
Is there anything out there like this or could this easily be added into a Gulp file?
Many thanks, Luke
There are some options and you can use the emitter to react to events like stream:changed, browser:reload, client:connected, connection,...
example:
var bs = require("browser-sync").create();
bs.init({}); //http://www.browsersync.io/docs/options/
....
bs.emitter.on("file:reload", function(){
console.log("File reload - Details:"+arguments)
});