Package: logdna
Python package for logging toLogDNAInstallationSetupUsageUsage with fileConfigAPILogDNAHandler(key: string, [options: dict])keyoptionslog(line, [options])lineoptionsDevelopmentScriptsLicenseInstallation$pipinstalllogdnaSetupimportloggingfromlogdnaimportLogDNAHandlerimportos# Set your key as an env variable# then import here, its best not to# hard code your key!key=os.environ['INGESTION_KEY']log=logging.getLogger('logdna')log.setLevel(logging.INFO)options={'hostname':'pytest','ip':'10.0.1.1','mac':'C0:FF:EE:C0:FF:EE'}# Defaults to False; when True meta objects are searchableoptions['index_meta']=Trueoptions['custom_fields']='meta'test=LogDNAHandler(key,options)log.addHandler(test)log.warning("Warning message",extra={'app':'bloop'})log.info("Info message")RequiredLogDNA Ingestion KeyOptionalHostname - (string)MAC Address - (string)IP Address - (string)Index Meta - (bool) - formatted asoptions['index_meta']UsageAfter initial setup, logging is as easy as:# Simplest use caselog.info('My Sample Log Line')# Add a custom levellog.info('My Sample Log Line',extra={'level':'MyCustomLevel'})# Include an App name with this specific loglog.info('My Sample Log Line',extra={'level':'Warn','app':'myAppName'})# Pass associated objects along as metadatameta={'foo':'bar','nested':{'nest1':'nested text'}}opts={'level':'warn','meta':meta}log.info('My Sample Log Line',extra=opts)Usage with fileConfigTo useLogDNAHandlerwithfileConfig(e.g., in a Djangosettings.pyfile):importosimportloggingfromlogdnaimportLogDNAHandler#  required to register `logging.handlers.LogDNAHandler`LOGGING={# Other logging settings...'handlers':{'logdna':{'level':logging.DEBUG,'class':'logging.handlers.LogDNAHandler','key':os.environ.get('LOGDNA_INGESTION_KEY'),'options':{'app':'<app name>','env':os.environ.get('ENVIRONMENT'),'index_meta':<True|False>,},},},'loggers':{'':{'handlers':['logdna'],'level':logging.DEBUG},},}(This example assumes you have set environment variables forENVIRONMENTandLOGDNA_INGESTION_KEY.)APILogDNAHandler(key:string, [options:dict])keyRequiredType:stringValues:<your ingestion key>TheLogDNA API Keyassociated with your account.optionsappOptionalType:stringDefault:''Values:<your custom app>The default app named that is included in every every log line sent through this instance.envOptionalType:stringDefault:''Values:<your custom env>The default env passed along with every log sent through this instance.hostnameOptionalType:stringDefault:''Values:<your custom hostname>The default hostname passed along with every log sent through this instance.include_standard_metaOptionalType:boolDefault:FalsePythonLogRecordobjects includes language-specific information that may be useful metadata in logs.
Settinginclude_standard_metatoTrueautomatically populates meta objects withname,pathname, andlinenofrom theLogRecord.WARNINGThis option is deprecated and will be removed in the upcoming major release.index_metaOptionalType:boolDefault:FalseWe allow meta objects to be passed with each line. By default these meta objects are stringified and not searchable, and are only displayed for informational purposes.If this option is set to True then meta objects are parsed and searchable up to three levels deep. Any fields deeper than three levels are stringified and cannot be searched.WARNINGIf this option is True, your metadata objects MUST have consistent types across all log messages or the metadata object might not be parsed properly.levelOptionalType:stringDefault:InfoValues:Debug,Trace,Info,Warn,Error,Fatal,<your custom level>The default level passed along with every log sent through this instance.verboseOptionalType:stringorboolDefault:TrueValues:Falseor any levelSets the verbosity of log statements for failures.request_timeoutOptionalType:intDefault:30000The amount of time (in ms) the request should wait for LogDNA to respond before timing out.tagsOptionalType:list<string>Default:[]List of tags used to dynamically group hosts.  More information on tags is available atHow Do I Use Host Tags?urlOptionalType:stringDefault:'https://logs.logdna.com/logs/ingest'A custom ingestion endpoint to stream log lines into.custom_fieldsOptionalType:list<string>Default:['args', 'name', 'pathname', 'lineno']List of fields out ofrecordobject to include in themetaobject. By default,args,name,pathname, andlinenowill be included.log_error_responseOptionalType:boolDefault:FalseEnables logging of the API response when an HTTP error is encounteredlog(line, [options])lineRequiredType:stringDefault:''The log line to be sent to LogDNA.optionslevelOptionalType:stringDefault:InfoValues:Debug,Trace,Info,Warn,Error,Fatal,<your custom level>The level passed along with this log line.appOptionalType:stringDefault:''Values:<your custom app>The app passed along with this log line.envOptionalType:stringDefault:''Values:<your custom env>The environment passed with this log line.metaOptionalType:dictDefault:NoneA standard dictonary containing additional metadata about the log line that is passed. Please ensure values are JSON serializable.NOTE: Values that are not JSON serializable will be removed and the respective keys will be added to the__errorsstring.index_metaOptionalType:boolDefault:FalseWe allow meta objects to be passed with each line. By default these meta objects will be stringified and will not be
searchable, but will be displayed for informational purposes.If this option is turned to true then meta objects will be parsed and will be searchable up to three levels deep. Any fields deeper than three levels will be stringified and cannot be searched.WARNINGWhen this option is true, your metadata objects across all types of log messages MUST have consistent types or the metadata object may not be parsed properly!timestampOptionalType:floatDefault:time.time()The time in seconds since the epoch to use for the log timestamp. It must be within one day or current time - if it is not, it is ignored and time.time() is used in its place.DevelopmentThis project makes use of thepoetrypackage manager for local development.$poetryinstallScriptslintRun linting rules w/o attempting to fix them$poetryruntasklintlint:fixRun lint rules against all local python files and attempt to fix where possible.$poetryruntasklint:fixtest:Runs all unit tests and generates coverage reportspoetryruntasktestContributors ✨Thanks goes to these wonderful people (emoji key):Muaz Siddiqui💻📖⚠️Samir Musali💻📖⚠️vilyapilya💻🚧⚠️Mike Hu📖Eric Satterwhite💻📖⚠️🔧Łukasz Bołdys (Lukasz Boldys)💻🐛Ryan📖Mike Huang💻🐛Dan Maas💻DChai📖Jakob de Maeyer💻Andrey Babak💻Mike S💻📖Brennan Ashton💻Christian Hotz-Behofsits💻🐛Kurtiss Hare🐛Alexey Kinev🐛matthiasfru🐛This project follows theall-contributorsspecification. Contributions of any kind welcome!LicenseMIT ©LogDNACopyright © 2017LogDNA, released under an MIT license. See theLICENSEfile andhttps://opensource.org/licenses/MITHappy Logging!