lw.comm-server icon indicating copy to clipboard operation
lw.comm-server copied to clipboard

Fix logfile path

Open jorgerobles opened this issue 7 years ago • 28 comments

As https://github.com/LaserWeb/LaserWeb4/issues/369 @gerwinbrunner

@cprezzi I've tested patch on electron_bundler At https://github.com/LaserWeb/lw.comm-server/blob/electron_bundler/server.js#L2843

logFile = fs.createWriteStream(path.join(electronApp.getPath('userData'),"logfile.log"));

I've no commited this, as don't know if thas to be other considerations about branches master & electron

jorgerobles avatar Jul 06 '17 11:07 jorgerobles

Yes, that's the problem! If we fix that only in the electron_bundler branch, it will probably be overwritten by a merge with master, but we can't do electron specific stuff in master.

I think this is a bug in electron for iOS, as a filename without path should use relative path which is the installation directory.

cprezzi avatar Jul 06 '17 12:07 cprezzi

Is there something like electron compile switches we could use?

cprezzi avatar Jul 06 '17 12:07 cprezzi

I've not found anything on electron-builder

What I would do:

  1. Move all the electron related code to other file (app.js ?)
  2. Encapsulate server code on an class (object/prototype/singleton, or even nested function) and inject dependencies on construct (like a setLogger function that swallows a modified logFile function)
  3. Create a new bootstrap.js file, make it main at package.json.
  4. Bootstrap.js reads an .env file git-ignored in the repo, if not exists instances the server.js class and runs. If exists, load the alternative file on env (like app.js), that runs the server.js instance and the electron part.

jorgerobles avatar Jul 06 '17 13:07 jorgerobles

Maybe if(electronApp)?

tbfleming avatar Jul 06 '17 13:07 tbfleming

@jorgerobles Isn't that a bit overcomplicated? There must be a simpler solution.

cprezzi avatar Jul 06 '17 14:07 cprezzi

Ok, found something to get if app is running inside electron: if (process.versions.electron) {...

cprezzi avatar Jul 06 '17 14:07 cprezzi

Well is complicated but abstracts enough to update server freely. Proces.. is of course valid

jorgerobles avatar Jul 06 '17 14:07 jorgerobles

You can also use is-electron to detect if current process is running in Electron.

cheton avatar Jul 06 '17 14:07 cheton

Thank's @cheton! That's even better.

cprezzi avatar Jul 06 '17 15:07 cprezzi

@jorgerobles logFile = fs.createWriteStream(path.join(electronApp.getPath('userData'),"logfile.log")); doesn't seem to work on Win10 electron app. I get now error message, but also no logfile.

cprezzi avatar Jul 06 '17 16:07 cprezzi

Probably is working but saving somwhere else :)

El 6 jul. 2017 6:29 p. m., "Claudio Prezzi" [email protected] escribió:

@jorgerobles https://github.com/jorgerobles logFile = fs.createWriteStream(path.join(electronApp.getPath(' userData'),"logfile.log")); doesn't seem to work on Win10 electron app. I get now error message, but also no logfile.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/LaserWeb/lw.comm-server/issues/42#issuecomment-313448529, or mute the thread https://github.com/notifications/unsubscribe-auth/ABoIYP-3gt0um35LD0tLdw91MzGd8k96ks5sLQtogaJpZM4OPgoR .

jorgerobles avatar Jul 06 '17 16:07 jorgerobles

Nope, doesn't seem to. I searched the whole drive. Looks like we need a way to find out if running on Mac 👎 (hate that stuff!)

cprezzi avatar Jul 06 '17 17:07 cprezzi

If(Mac) warn("update to an OS with sane APIs")

tbfleming avatar Jul 06 '17 17:07 tbfleming

Ok, found that getPath('userData') is delivering the correct path with \ as directory separator on Windows. Still searching why fs.createWriteStream is not working...

cprezzi avatar Jul 06 '17 18:07 cprezzi

I had to make if OS dependant with os.platform.

Who could compile the Mac Version and test if the logfile is written now? (needs .env file with LOG_LEVEL=3 in installation folder).

cprezzi avatar Jul 07 '17 10:07 cprezzi

I'll do

El 7 jul. 2017 12:19, "Claudio Prezzi" [email protected] escribió:

I had to make if OS dependant with os.platform.

Who could compile the Mac Version and test if the logfile is written now? (needs .env file with LOG_LEVEL=3 in installation folder).

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/LaserWeb/lw.comm-server/issues/42#issuecomment-313644491, or mute the thread https://github.com/notifications/unsubscribe-auth/ABoIYL3GcF_ualTSQitMuGgWWEilfPIDks5sLgYigaJpZM4OPgoR .

jorgerobles avatar Jul 07 '17 10:07 jorgerobles

image

But does not write log :|

jorgerobles avatar Jul 07 '17 10:07 jorgerobles

@cprezzi cannot get it work on Sierra. Does not find .env

jorgerobles avatar Jul 07 '17 11:07 jorgerobles

I don't know anything about Mac. On Windows, the .env file just has to sit in the same directory as the exe.

cprezzi avatar Jul 07 '17 15:07 cprezzi

Yes. I've tried several ways. Seems version bound. On Mavericks ran ok yesterday.

jorgerobles avatar Jul 07 '17 15:07 jorgerobles

Eventually making a .provile file could help: https://apple.stackexchange.com/questions/106778/how-do-i-set-environment-variables-on-os-x

cprezzi avatar Jul 07 '17 16:07 cprezzi

Yes, I did the export LOG_LEVEL=3 too 😢

jorgerobles avatar Jul 07 '17 16:07 jorgerobles

Did I mention - I hate Apple?!

cprezzi avatar Jul 07 '17 16:07 cprezzi

Hmm. Osx could contribute, but I see more culprit on electron or dotenv. I don't miss win viruses.

El 7 jul. 2017 6:10 p. m., "Claudio Prezzi" [email protected] escribió:

Did I say - I hate Apple?!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/LaserWeb/lw.comm-server/issues/42#issuecomment-313725251, or mute the thread https://github.com/notifications/unsubscribe-auth/ABoIYIJ0ZeqA4ehBLXsHKkHfu2laWlIVks5sLlhmgaJpZM4OPgoR .

jorgerobles avatar Jul 07 '17 16:07 jorgerobles

Osx is a God gift. :)

cojarbi avatar Jul 07 '17 18:07 cojarbi

I once gave a MBP 3 months of my development life. I liked the hardware so was willing to give the OS a fair shot. Things kept getting worse over time as I learned more and more of it. It's both a bad UI (very horrid keyboard support, way too much clicky needed) and a bad POSIX system (ancient BSD version missing critical syscalls needed to avoid deadlock in fork/exec).

tbfleming avatar Jul 07 '17 19:07 tbfleming

This is how I got the Logfile.txt working on OSX:

Open a Terminal session (from the Utilities folder under Applications) cd /Applications/Laserweb.app/Contents export LOG_LEVEL=3 ./Laserweb

And as it runs it creates Logfile.txt in that same directory.

Cheers Douglas.

DouglasPearless avatar Aug 22 '17 02:08 DouglasPearless

@DouglasPearless Thank you for the information. That makes sense. Setting the environment variable with export only survives in the same terminal session.

cprezzi avatar Aug 22 '17 18:08 cprezzi