Page 1 of 1

Logging

Posted: Tue Jul 28, 2015 4:45 am
by nullable
What better use for logging in the plugin?
Loggers or logging or something else?

Posted: Wed Jul 29, 2015 5:40 am
by satoon101
Ideally, you would want to use loggers. Though, we obviously haven't added any of that to the wiki, yet. Here is GunGame's usage of LogManager:
https://github.com/GunGame-Dev-Team/GunGame-SP/blob/master/addons/source-python/plugins/gungame/core/logger.py

The reason why ConVars are used for level and areas is so that server operators (and plugin testers) can easily change where the messages are logged to and which messages to log. For more information on the two types of variables, look to the ../cfg/source-python/core_settings.ini's LOG_SETTINGS section:

Syntax: Select all

[LOG_SETTINGS]
# Set to the logging level to use for Source.Python.

# To show all messages, set to level 5.
# To show debugging messages, set to at least level 4.
# To show informational messages, set to at least level 3.
# To show warning messages, set to at least level 2.
# To show exception messages, set to at least level 1.
# To show only critical and base messages, set to 0.
level = 2

# Set to the areas to log (console, main log, sp log, script log):
# Console = 1
# Main log = 2
# SP log = 4
# Script log = 8
# Add each of the areas up and set the value to that number.
# Example:
# To have the messages print to the console and be added to SP's log:
# Console + SP log = 1 + 4 = 5
areas = 1

Posted: Wed Jul 29, 2015 9:00 pm
by nullable
I did a similar but not the same output format as needed:

Syntax: Select all

gg_logger = LogManager(
'gg', _level, _areas, 'gungame',
'%(asctime)s - %(name)s\t-\t%(levelname)s\n%(message)s',
'%m-%d-%Y %H:%M:%S')

I mean all logs without prefix datetime.