Logging to custom folder with $.log.file

#1

PhantomBot Version: 3.0.0 (Revision: fcc08b51)
OS Version: Linux - CentOS 6
Java Version: 1.8.0_181-b13

Let us know what help you need:

From a custom script I’m trying to log data a new/custom file with $.log.file('foldername', textvariable), the folder is not generated and no log file, no errors in console or in the core logs. The script itself seems to execute fine it doesn’t fail or stop working after the missing log attempt.

The bot does create a daily log file in the moderation folder (for timeouts), so I assume it has permission to create folders/files. using that same moderation log file from my script does not work either (no new lines are added).

The only logging method that currently works is by using $.log.warn, however this file gets messy with multiple scripts logging in it.

1 Like

#2

This worked for me in a test. Double check the permissions on the logs directory, the logging module checks to see if the directory exists and attempts to create it. If the other directories are created though, that is interesting. There currently isn’t an error check around that code, we could add one and you could run a test script as well if the permissions look good. Let us know. Example code running:

$.log.file('newdirectory', 'Some text to go into a file.');
[morpheus] /opt/iobot/logs
illusion% ls -lrt
total 60
drwxrwsr-x 2 illusion illusion 4096 Apr  6  2018 patternDetector
drwxrwsr-x 2 illusion illusion 4096 Apr  6  2018 moderation
drwxrwsr-x 2 illusion illusion 4096 Oct 15 16:29 warning
drwxrwsr-x 2 illusion illusion 4096 Dec 20 00:31 private-messages
drwxrwsr-x 2 illusion illusion 4096 Jan  6 14:03 core-warnings
drwxrwsr-x 2 illusion illusion 4096 Mar 10 13:29 customCommands
drwxrwsr-x 2 illusion illusion 4096 Mar 10 13:29 core-debug
drwxrwsr-x 2 illusion illusion 4096 Mar 10 13:29 core
drwxrwsr-x 2 illusion illusion 4096 Mar 13 18:59 core-error
drwxrwsr-x 2 illusion illusion 4096 Mar 13 18:59 event
drwxrwsr-x 2 illusion illusion 4096 Mar 13 18:59 chat
drwxrwsr-x 2 illusion illusion 4096 Mar 13 19:00 pointSystem
drwxrwsr-x 2 illusion illusion 4096 Mar 13 19:00 stacktraces
drwxrwsr-x 2 illusion illusion 4096 Mar 13 19:22 error
drwxrwsr-x 2 illusion illusion 4096 Mar 13 20:03 newdirectory
[morpheus] /opt/iobot/logs
illusion% cd newdirectory/
[morpheus] /opt/iobot/logs/newdirectory
illusion% ls -lat
total 12
-rw-rw-r--  1 illusion illusion   61 Mar 13 20:03 13-03-2019.txt
drwxrwsr-x  2 illusion illusion 4096 Mar 13 20:03 .
drwxrwsr-x 17 illusion illusion 4096 Mar 13 20:03 ..
[morpheus] /opt/iobot/logs/newdirectory
illusion% cat 13-03-2019.txt
[03-13-2019 @ 20:03:01.545 MDT] Some text to go into a file.
0 Likes

#3

Thanks for your response and example output. We’ll compare our file & folder permissions on our system and get back to you if we do need the error check.

0 Likes

#4

Alright, yeah we can’t seem to figure it out. So if there is a way to catch an error while logging/creating directories that would be great.
We created a folder inside logs, and set different permissions on that folder, but it wouldnt create a log file, so maybe the logs folder itself is not allowing it? I’m not sure what the right permissions should be set at.

0 Likes

#5

This will throw an exception to the Console.

logging.js (14.3 KB)

Make a backup copy of scripts/core/logging.js and replace with the one above. Should help to identify the issue.

0 Likes