Skip to content

Commit

Permalink
[Stock-RM] Add Log Filename (RocketMap#91)
Browse files Browse the repository at this point in the history
[Stock-RM] Add Log Filename  (RocketMap#91)
  • Loading branch information
rlodev67 committed Mar 26, 2018
1 parent 8eb9b99 commit babcfc2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

# RocketMap

![Python 2.7](https://img.shields.io/badge/python-2.7-blue.svg) ![License](https://img.shields.io/github/license/RocketMap/RocketMap.svg) [![Build Status](https://travis-ci.org/RocketMap/RocketMap.svg?branch=develop)](https://travis-ci.org/RocketMap/RocketMap)
Expand Down
1 change: 1 addition & 0 deletions config/config.ini.example
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
#verbosity # Show debug messages from RocketMap and PGoApi. Values are 1,2,3 (default=0)
#no-file-logs # Disables logging to files except for access.log. (default=False)
#log-path: # Defines the path logs are saved at. (default=logs/)
#log-filename: # Defines the log filename to be saved. The default generates yyyymmdd_HHMM_statusname.log. (default=%Y%m%d_%H%M_<SN>)
#no-version-check # Disable API version check. (default=False)
#version-check-interval: # Interval to check API version in seconds (Default: in range [60, 300]).
#mock: # Mock mode - point to a fpgo endpoint instead of using the real PogoApi,
Expand Down
9 changes: 8 additions & 1 deletion docs/first-run/commandline.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
[-novc] [-vci VERSION_CHECK_INTERVAL]
[-odt ON_DEMAND_TIMEOUT] [--disable-blacklist] [--disable-blacklist]
[-tp TRUSTED_PROXIES] [--api-version API_VERSION]
[--no-file-logs] [--log-path LOG_PATH] [--dump] [-exg] [-exg]
[--no-file-logs] [--log-path LOG_PATH]
[--log-filename LOG_FILENAME] [--dump] [-exg]

[-v | --verbosity VERBOSE] [-Rh RARITY_HOURS]
[-Rf RARITY_UPDATE_FREQUENCY]
Expand Down Expand Up @@ -388,6 +389,12 @@ environment variables which override config file values which override defaults.
logs. [env var: POGOMAP_NO_FILE_LOGS]
--log-path LOG_PATH Defines directory to save log files to.
[env var: POGOMAP_LOG_PATH]
--log-filename LOG_FILENAME
Defines the log filename to be saved. Allows date
formatting, and replaces <SN> with the instance's
status name. Read the python time module docs for
details. Default: %Y%m%d_%H%M_<SN>.log. [env var:
POGOMAP_LOG_FILENAME]
--dump Dump censored debug info about the environment and
auto-upload to hastebin.com. [env var: POGOMAP_DUMP]
-v Show debug messages from RocketMap and pgoapi. Can be
Expand Down
14 changes: 14 additions & 0 deletions pogom/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from requests.adapters import HTTPAdapter
from cHaversine import haversine
from pprint import pformat
from time import strftime
from timeit import default_timer

from pogom import dyn_img
Expand Down Expand Up @@ -532,6 +533,13 @@ def get_args():
parser.add_argument('--log-path',
help=('Defines directory to save log files to.'),
default='logs/')
parser.add_argument('--log-filename',
help=('Defines the log filename to be saved.'
' Allows date formatting, and replaces <SN>'
" with the instance's status name. Read the"
' python time module docs for details.'
' Default: %%Y%%m%%d_%%H%%M_<SN>.log.'),
default='%Y%m%d_%H%M_<SN>.log'),
parser.add_argument('--dump',
help=('Dump censored debug info about the ' +
'environment and auto-upload to ' +
Expand Down Expand Up @@ -623,6 +631,11 @@ def get_args():

args = parser.parse_args()

# Allow status name and date formatting in log filename.
args.log_filename = strftime(args.log_filename)
args.log_filename = args.log_filename.replace('<sn>', '<SN>')
args.log_filename = args.log_filename.replace('<SN>', args.status_name)

if args.only_server:
if args.location is None:
parser.print_usage()
Expand Down Expand Up @@ -1367,6 +1380,7 @@ def _censor_args_namespace(args, censored_tag):
'db',
'proxy_file',
'log_path',
'log_filename',
'encrypt_lib',
'ssl_certificate',
'ssl_privatekey',
Expand Down
4 changes: 1 addition & 3 deletions runserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,9 +525,7 @@ def set_log_and_verbosity(log):
if not os.path.exists(args.log_path):
os.mkdir(args.log_path)
if not args.no_file_logs:
date = strftime('%Y%m%d_%H%M')
filename = os.path.join(
args.log_path, '{}_{}.log'.format(date, args.status_name))
filename = os.path.join(args.log_path, args.log_filename)
filelog = logging.FileHandler(filename)
filelog.setFormatter(logging.Formatter(
'%(asctime)s [%(threadName)18s][%(module)14s][%(levelname)8s] ' +
Expand Down

0 comments on commit babcfc2

Please sign in to comment.