GithubHelp home page GithubHelp logo

Disable SSHLogger about sshaolin HOT 7 CLOSED

bucknerns avatar bucknerns commented on July 1, 2024
Disable SSHLogger

from sshaolin.

Comments (7)

d1skort avatar d1skort commented on July 1, 2024 1

@seemethere awesome mate, thank you!

from sshaolin.

seemethere avatar seemethere commented on July 1, 2024

What's the use case? If you don't want to use the SSHLogger you can just set your log level above info?

from sshaolin.

d1skort avatar d1skort commented on July 1, 2024

I already have massive logs (which include response from ssh) and just don't need this CALL logs.

from sshaolin.

seemethere avatar seemethere commented on July 1, 2024

Actually talked it over with the @bucknerns and he suggested using something similar to:

import logging
logging.getLogger('sshaolin').setLevel(logging.CRITICAL)

Which works equally as well without any code changes on this side (and class signature changes).

If you do it once in your project you never have to do it again.

from sshaolin.

d1skort avatar d1skort commented on July 1, 2024

oh, my bad, sorry guys.

from sshaolin.

bucknerns avatar bucknerns commented on July 1, 2024

I am of the opinion that logging should be handled at the framework level with overrides being possible from anywhere. If we hard code logging into this class is it only possible to change it during the init of the class. My recommendation is to disable the propagate from modules you dont want. In the example below we can see a lot of debug from paramiko.transport logger and sshaolin.client.SSHClient logger. So we are going to just stop paramiko and sshaolin from propagating to our root logger which is writing to the screen(in your case a file).
This is don't by getting the logger and setting propagate to false.
sshaolin

disable sshaolin/paramiko

paramiko_logger = logging.getLogger("paramiko")
sshaolin_logger = logging.getLogger("sshaolin")
paramiko_logger.propagate = False
sshaolin_logger.propagate = False

you could also just set the log level of the logger as well like I discussed with eli.

logging.getLogger('sshaolin').setLevel(logging.CRITICAL)

Current problem situation

# handled by framework or at top of script
import logging
fmt = logging.Formatter(
    fmt="%(asctime)s: %(levelname)s: %(name)s: %(message)s")
root_logger = logging.getLogger()
handler = logging.StreamHandler()
handler.setFormatter(fmt=fmt)
root_logger.addHandler(handler)
root_logger.setLevel(logging.DEBUG)
my_logger = logging.getLogger("my_logger")
# user code
from sshaolin import client
my_logger.debug("123")
c = client.SSHClient("localhost", look_for_keys=True)
ls_results = c.execute_command("ls")
my_logger.debug("456")
my_logger.debug(ls_results.stdout)

Results

2016-09-26 11:36:40,253: DEBUG: my_logger: 123
2016-09-26 11:36:40,253: INFO: sshaolin.client.SSHClient: 
==========================================
CALL
------------------------------------------
execute_command args..........: ('ls',)
execute_command kwargs........: {}
------------------------------------------

2016-09-26 11:36:40,253: DEBUG: paramiko.transport: starting thread (client mode): 0xc29516d0L
2016-09-26 11:36:40,254: DEBUG: paramiko.transport: Local version/idstring: SSH-2.0-paramiko_2.0.2
2016-09-26 11:36:40,257: DEBUG: paramiko.transport: Remote version/idstring: SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.1
2016-09-26 11:36:40,257: INFO: paramiko.transport: Connected (version 2.0, client OpenSSH_7.2p2)
2016-09-26 11:36:40,257: DEBUG: paramiko.transport: kex algos:[u'[email protected]', u'ecdh-sha2-nistp256', u'ecdh-sha2-nistp384', u'ecdh-sha2-nistp521', u'diffie-hellman-group-exchange-sha256', u'diffie-hellman-group14-sha1'] server key:[u'ssh-rsa', u'rsa-sha2-512', u'rsa-sha2-256', u'ecdsa-sha2-nistp256', u'ssh-ed25519'] client encrypt:[u'[email protected]', u'aes128-ctr', u'aes192-ctr', u'aes256-ctr', u'[email protected]', u'[email protected]'] server encrypt:[u'[email protected]', u'aes128-ctr', u'aes192-ctr', u'aes256-ctr', u'[email protected]', u'[email protected]'] client mac:[u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]', u'hmac-sha2-256', u'hmac-sha2-512', u'hmac-sha1'] server mac:[u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]', u'hmac-sha2-256', u'hmac-sha2-512', u'hmac-sha1'] client compress:[u'none', u'[email protected]'] server compress:[u'none', u'[email protected]'] client lang:[u''] server lang:[u''] kex follows?False
2016-09-26 11:36:40,257: DEBUG: paramiko.transport: Kex agreed: diffie-hellman-group14-sha1
2016-09-26 11:36:40,257: DEBUG: paramiko.transport: Cipher agreed: aes128-ctr
2016-09-26 11:36:40,257: DEBUG: paramiko.transport: MAC agreed: hmac-sha2-256
2016-09-26 11:36:40,257: DEBUG: paramiko.transport: Compression agreed: [email protected]
2016-09-26 11:36:40,311: DEBUG: paramiko.transport: kex engine KexGroup14 specified hash_algo <built-in function openssl_sha1>
2016-09-26 11:36:40,311: DEBUG: paramiko.transport: Switch to new keys ...
2016-09-26 11:36:40,325: DEBUG: paramiko.transport: Adding ssh-rsa host key for localhost: fe21c8703589ae3ecefbd6d7fd607200
2016-09-26 11:36:40,326: DEBUG: paramiko.transport: Trying discovered key b023135fb284a083d0d960b2e098708a in /home/nath4854/.ssh/id_rsa
2016-09-26 11:36:40,350: DEBUG: paramiko.transport: userauth is OK
2016-09-26 11:36:40,356: INFO: paramiko.transport: Authentication (publickey) successful!
2016-09-26 11:36:40,356: DEBUG: paramiko.transport: Switching on outbound compression ...
2016-09-26 11:36:40,356: DEBUG: paramiko.transport: Switching on inbound compression ...
2016-09-26 11:36:40,358: DEBUG: paramiko.transport: [chan 0] Max packet in: 32768 bytes
2016-09-26 11:36:40,439: DEBUG: paramiko.transport: Received global request "[email protected]"
2016-09-26 11:36:40,439: DEBUG: paramiko.transport: Rejecting "[email protected]" global request from server.
2016-09-26 11:36:40,478: DEBUG: paramiko.transport: [chan 0] Max packet out: 32768 bytes
2016-09-26 11:36:40,478: DEBUG: paramiko.transport: Secsh channel 0 opened.
2016-09-26 11:36:40,491: DEBUG: paramiko.transport: [chan 0] Sesch channel 0 request ok
2016-09-26 11:36:40,493: DEBUG: paramiko.transport: [chan 0] EOF received (0)
2016-09-26 11:36:40,493: DEBUG: paramiko.transport: [chan 0] EOF sent (0)
2016-09-26 11:36:40,594: DEBUG: paramiko.transport: EOF in transport thread
2016-09-26 11:36:40,608: INFO: sshaolin.client.SSHClient: 
==========================================
RESPONSE
------------------------------------------
response stdout......: 3ds
bcwc_pcie
bin
code
code_reference
docs
Downloads
in
index.html
lib
magic.mgc
oracle
Screenshot from 2016-06-06 11-54-18.png
Screenshot from 2016-07-13 11-18-10.png
Screenshot from 2016-07-22 08-52-57.png
Screenshot from 2016-07-29 16-32-05.png
Screenshot from 2016-08-09 12-52-54.png
Screenshot from 2016-08-29 15-36-29.png
test1.py
testing_namespace
test.py
testssh
texmf
tools

response stderr......: 
response exit_status.: 0
response elapsed.....: 0.355528116226
------------------------------------------

2016-09-26 11:36:40,609: DEBUG: my_logger: 456
2016-09-26 11:36:40,609: DEBUG: my_logger: 3ds
bcwc_pcie
bin
code
code_reference
docs
Downloads
in
index.html
lib
magic.mgc
oracle
Screenshot from 2016-06-06 11-54-18.png
Screenshot from 2016-07-13 11-18-10.png
Screenshot from 2016-07-22 08-52-57.png
Screenshot from 2016-07-29 16-32-05.png
Screenshot from 2016-08-09 12-52-54.png
Screenshot from 2016-08-29 15-36-29.png
test1.py
testing_namespace
test.py
testssh
texmf
tools

Good example

# handled by framework or at top of script
import logging
fmt = logging.Formatter(
    fmt="%(asctime)s: %(levelname)s: %(name)s: %(message)s")
root_logger = logging.getLogger()
handler = logging.StreamHandler()
handler.setFormatter(fmt=fmt)
root_logger.addHandler(handler)
root_logger.setLevel(logging.DEBUG)
my_logger = logging.getLogger("my_logger")

# disable sshaolin/paramiko
paramiko_logger = logging.getLogger("paramiko")
sshaolin_logger = logging.getLogger("sshaolin")
paramiko_logger.propagate = False
sshaolin_logger.propagate = False
# user code
from sshaolin import client
my_logger.debug("123")
c = client.SSHClient("localhost", look_for_keys=True)
ls_results = c.execute_command("ls")
my_logger.debug("456")
my_logger.debug(ls_results.stdout)

Results

2016-09-26 11:49:06,947: DEBUG: my_logger: 123
No handlers could be found for logger "sshaolin.client.SSHClient"
2016-09-26 11:49:07,286: DEBUG: my_logger: 456
2016-09-26 11:49:07,286: DEBUG: my_logger: 3ds
bcwc_pcie
bin
code
code_reference
docs
Downloads
in
index.html
lib
magic.mgc
oracle
Screenshot from 2016-06-06 11-54-18.png
Screenshot from 2016-07-13 11-18-10.png
Screenshot from 2016-07-22 08-52-57.png
Screenshot from 2016-07-29 16-32-05.png
Screenshot from 2016-08-09 12-52-54.png
Screenshot from 2016-08-29 15-36-29.png
test1.py
testing_namespace
test.py
testssh
texmf
tools

from sshaolin.

bucknerns avatar bucknerns commented on July 1, 2024

Don't worry about it, it happens.

from sshaolin.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.