File: loggers.py

package info (click to toggle)
plaso 20201007-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 519,924 kB
  • sloc: python: 79,002; sh: 629; xml: 72; sql: 14; vhdl: 11; makefile: 10
file content (45 lines) | stat: -rw-r--r-- 1,311 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Tests for the logging related classes and functions."""

from __future__ import unicode_literals

import logging
import os
import unittest

from plaso.lib import loggers

from tests import test_lib as shared_test_lib


class CompressedFileHandlerTests(shared_test_lib.BaseTestCase):
  """Tests for the compressed file handler for logging."""

  def testOpenAndEmit(self):
    """Tests the open and emit functions."""
    with shared_test_lib.TempDirectory() as temp_directory:
      filename = os.path.join(temp_directory, 'test.log.gz')
      handler = loggers.CompressedFileHandler(filename)

      record = logging.LogRecord(None, None, "", 0, "", (), None, None)
      handler.emit(record)


class LoggersTests(shared_test_lib.BaseTestCase):
  """Tests for the loggers module."""

  def testConfigureLogging(self):
    """Tests the ConfigureLogging function."""
    with shared_test_lib.TempDirectory() as temp_directory:
      filename = os.path.join(temp_directory, 'test.log.gz')
      loggers.ConfigureLogging(debug_output=True, filename=filename)

      filename = os.path.join(temp_directory, 'test.log')
      loggers.ConfigureLogging(filename=filename, quiet_mode=True)

    loggers.ConfigureLogging()


if __name__ == '__main__':
  unittest.main()