Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

splunk_app_action_d83f64322080893e8c75e278a669d009 #15

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions TA_NetDocuments/package/bin/logger_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# This file is generated and maintained by splunk-app-action (https://github.com/VatsalJagani/splunk-app-action)
# To modify anything create Pull Request on the splunk-app-action GitHub repository.


# Standard library imports
import logging
import logging.handlers
import os

# Splunk imports
from splunk.clilib.bundle_paths import make_splunkhome_path

log_file_prefix = 'ta_netdocuments'


def setup_logging(log_name, log_level=logging.INFO):
""" Setup logger.

:param log_name: name for logger
:param log_level: log level, a string
:return: a logger object
"""
log_name = '{}_{}'.format(log_file_prefix, log_name)
# Make path till log file (current dir (app/<app-name>/bin))
# log_dir = os.path.dirname(os.path.abspath(__file__))
# log_file = os.path.join(log_dir, "%s.log" % log_name)

# Make path till log file (splunk/var/log/splunk dir)
log_file = make_splunkhome_path(
["var", "log", "splunk", "%s.log" % log_name])
log_dir = os.path.dirname(log_file)

# Create directory at the required path to store log file, if not found
if not os.path.exists(log_dir):
os.makedirs(log_dir)

logger = logging.getLogger(log_name)
logger.propagate = False

# Set log level
logger.setLevel(log_level)

handler_exists = any(
[True for h in logger.handlers if h.baseFilename == log_file])

if not handler_exists:
file_handler = logging.handlers.RotatingFileHandler(
log_file, mode="a", maxBytes=10485760, backupCount=10)
# Format logs
fmt_str = "%(asctime)s %(levelname)s %(thread)d - %(message)s"
formatter = logging.Formatter(fmt_str, datefmt="%Y-%m-%d %H:%M:%S %z")
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)

if log_level is not None:
file_handler.setLevel(log_level)

return logger
10 changes: 10 additions & 0 deletions TA_NetDocuments/package/default/props.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
############
## Logger ##
############
[source::.../var/log/splunk/ta_netdocuments_*.log*]
SHOULD_LINEMERGE = false
LINE_BREAKER = ([\r\n]+)\d{4}-\d{2}-\d{2}\s
sourcetype = ta_netdocuments:logs
TRUNCATE = 100000
TIME_PREFIX = ^
TIME_FORMAT = %Y-%m-%d %H:%M:%S %z
Loading